mirror of
https://github.com/lissy93/networking-toolbox.git
synced 2026-12-03 18:11:23 +03:00
Re-ordered IP convertor
This commit is contained in:
1 parent
222e84012f
commit
fcc173eb07
8 files changed
+204
-64
No files matched your search
@@ -1,26 +1,134 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/stores';
|
||||
import { SUB_NAV, findSectionKey, isActive } from '$lib/constants/nav';
|
||||
import { SUB_NAV, findSectionKey, isActive, type NavItem, type NavGroup } from '$lib/constants/nav';
|
||||
|
||||
$: currentPath = $page.url.pathname;
|
||||
$: sectionKey = findSectionKey(currentPath); // e.g. '/reference' or '/cidr-convertor'
|
||||
$: links = sectionKey ? SUB_NAV[sectionKey] : null;
|
||||
$: navStructure = sectionKey ? SUB_NAV[sectionKey] : null;
|
||||
|
||||
// Check if the structure contains groups or just items
|
||||
$: hasGroups = navStructure && navStructure.length > 0 && 'title' in navStructure[0];
|
||||
</script>
|
||||
|
||||
{#if links}
|
||||
{#if navStructure}
|
||||
<nav class="sub-nav" aria-label="Section">
|
||||
<div class="container">
|
||||
<div class="sub-nav-links">
|
||||
{#each links as link}
|
||||
<a
|
||||
href={link.href}
|
||||
class="sub-nav-link {isActive(currentPath, link.href) ? 'active' : ''}"
|
||||
aria-current={isActive(currentPath, link.href) ? 'page' : undefined}
|
||||
>
|
||||
{link.label}
|
||||
</a>
|
||||
{/each}
|
||||
</div>
|
||||
{#if hasGroups}
|
||||
<!-- Grouped navigation -->
|
||||
<div class="sub-nav-groups">
|
||||
{#each navStructure as group}
|
||||
{#if 'title' in group}
|
||||
<div class="nav-group">
|
||||
<div class="group-title">{group.title}</div>
|
||||
<div class="group-links">
|
||||
{#each group.items as link}
|
||||
<a
|
||||
href={link.href}
|
||||
class="sub-nav-link {isActive(currentPath, link.href) ? 'active' : ''}"
|
||||
aria-current={isActive(currentPath, link.href) ? 'page' : undefined}
|
||||
>
|
||||
{link.label}
|
||||
</a>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
{:else}
|
||||
<!-- Flat navigation -->
|
||||
<div class="sub-nav-links">
|
||||
{#each navStructure as link}
|
||||
{#if 'href' in link}
|
||||
<a
|
||||
href={link.href}
|
||||
class="sub-nav-link {isActive(currentPath, link.href) ? 'active' : ''}"
|
||||
aria-current={isActive(currentPath, link.href) ? 'page' : undefined}
|
||||
>
|
||||
{link.label}
|
||||
</a>
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</nav>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
/* Base sub-nav styles */
|
||||
.sub-nav {
|
||||
background-color: var(--bg-tertiary);
|
||||
border-bottom: 1px solid var(--border-primary);
|
||||
padding: var(--spacing-sm) 0;
|
||||
}
|
||||
|
||||
/* Flat navigation styles (existing) */
|
||||
.sub-nav-links {
|
||||
display: flex;
|
||||
gap: var(--spacing-md);
|
||||
}
|
||||
|
||||
.sub-nav-link {
|
||||
padding: var(--spacing-xs) var(--spacing-md);
|
||||
border-radius: var(--radius-sm);
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--text-secondary);
|
||||
text-decoration: none;
|
||||
transition: all var(--transition-fast);
|
||||
}
|
||||
|
||||
.sub-nav-link:hover {
|
||||
color: var(--color-primary);
|
||||
background-color: var(--surface-hover);
|
||||
}
|
||||
|
||||
.sub-nav-link.active {
|
||||
color: var(--color-primary);
|
||||
background-color: var(--surface-hover);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* Grouped navigation styles (new) */
|
||||
.sub-nav-groups {
|
||||
display: flex;
|
||||
gap: var(--spacing-xl);
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.nav-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.group-title {
|
||||
font-size: var(--font-size-xs);
|
||||
font-weight: 600;
|
||||
color: var(--text-secondary);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
padding: var(--spacing-xs) var(--spacing-md);
|
||||
}
|
||||
|
||||
.group-links {
|
||||
display: flex;
|
||||
gap: var(--spacing-md);
|
||||
}
|
||||
|
||||
/* Responsive styles */
|
||||
@media (max-width: 768px) {
|
||||
.sub-nav-links {
|
||||
gap: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.sub-nav-groups {
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-md);
|
||||
}
|
||||
|
||||
.group-links {
|
||||
gap: var(--spacing-sm);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
+49
-18
@@ -5,6 +5,11 @@ export type NavItem = {
|
||||
icon?: string;
|
||||
};
|
||||
|
||||
export type NavGroup = {
|
||||
title: string;
|
||||
items: NavItem[];
|
||||
};
|
||||
|
||||
// Individual standalone pages
|
||||
export const STANDALONE_PAGES: NavItem[] = [
|
||||
{
|
||||
@@ -12,12 +17,6 @@ export const STANDALONE_PAGES: NavItem[] = [
|
||||
label: 'Subnet Calculator',
|
||||
description: 'Calculate subnet information, network addresses, broadcast addresses, and host ranges with visual network analysis',
|
||||
icon: 'subnet-calculator'
|
||||
},
|
||||
{
|
||||
href: '/ip-address-convertor',
|
||||
label: 'IP Address Converter',
|
||||
description: 'Convert IP addresses between decimal, binary, hexadecimal, and octal number systems',
|
||||
icon: 'ip-convertor'
|
||||
}
|
||||
];
|
||||
|
||||
@@ -25,12 +24,11 @@ export const TOP_NAV: NavItem[] = [
|
||||
{ href: '/subnet-calculator', label: 'Subnet Calc' },
|
||||
{ href: '/cidr-convertor', label: 'CIDR Convert' },
|
||||
{ href: '/ip-address-convertor', label: 'IP Convert' },
|
||||
{ href: '/ip-family-convertor', label: 'IPv4/IPv6' },
|
||||
{ href: '/ip-reference', label: 'Reference' }
|
||||
];
|
||||
|
||||
// Sections that have sub-pages (drives the conditional SubHeader)
|
||||
export const SUB_NAV: Record<string, NavItem[]> = {
|
||||
export const SUB_NAV: Record<string, NavItem[] | NavGroup[]> = {
|
||||
'/cidr-convertor': [
|
||||
{
|
||||
href: '/cidr-convertor/cidr-to-subnet-mask',
|
||||
@@ -45,18 +43,34 @@ export const SUB_NAV: Record<string, NavItem[]> = {
|
||||
icon: 'cidr-convertor'
|
||||
}
|
||||
],
|
||||
'/ip-family-convertor': [
|
||||
'/ip-address-convertor': [
|
||||
{
|
||||
href: '/ip-family-convertor/ipv4-to-ipv6',
|
||||
label: 'IPv4 → IPv6',
|
||||
description: 'Convert IPv4 addresses to IPv6 format using IPv4-mapped IPv6 addressing',
|
||||
icon: 'ipv4-ipv6'
|
||||
title: 'Number Formats',
|
||||
items: [
|
||||
{
|
||||
href: '/ip-address-convertor/representations',
|
||||
label: 'Format Representations',
|
||||
description: 'Convert IP addresses between decimal, binary, hexadecimal, and octal number systems',
|
||||
icon: 'ip-convertor'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
href: '/ip-family-convertor/ipv6-to-ipv4',
|
||||
label: 'IPv6 → IPv4',
|
||||
description: 'Extract IPv4 addresses from IPv4-mapped IPv6 addresses',
|
||||
icon: 'ipv6-ipv4'
|
||||
title: 'IP Families',
|
||||
items: [
|
||||
{
|
||||
href: '/ip-address-convertor/families/ipv4-to-ipv6',
|
||||
label: 'IPv4 → IPv6',
|
||||
description: 'Convert IPv4 addresses to IPv6 format using IPv4-mapped IPv6 addressing',
|
||||
icon: 'ipv4-ipv6'
|
||||
},
|
||||
{
|
||||
href: '/ip-address-convertor/families/ipv6-to-ipv4',
|
||||
label: 'IPv6 → IPv4',
|
||||
description: 'Extract IPv4 addresses from IPv4-mapped IPv6 addresses',
|
||||
icon: 'ipv6-ipv4'
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
'/ip-reference': [
|
||||
@@ -87,10 +101,27 @@ export function isActive(pathname: string, href: string): boolean {
|
||||
return pathname === href || pathname.startsWith(href + '/');
|
||||
}
|
||||
|
||||
// Helper function to extract all nav items from mixed structure
|
||||
function extractAllNavItems(navStructure: (NavItem | NavGroup)[]): NavItem[] {
|
||||
const items: NavItem[] = [];
|
||||
|
||||
for (const item of navStructure) {
|
||||
if ('href' in item) {
|
||||
// It's a NavItem
|
||||
items.push(item);
|
||||
} else if ('title' in item && 'items' in item) {
|
||||
// It's a NavGroup
|
||||
items.push(...item.items);
|
||||
}
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
// All pages for homepage navigation - combines standalone pages with sub-pages
|
||||
export const ALL_PAGES: NavItem[] = [
|
||||
...STANDALONE_PAGES,
|
||||
...Object.values(SUB_NAV).flat()
|
||||
...Object.values(SUB_NAV).map(section => extractAllNavItems(section as (NavItem | NavGroup)[])).flat()
|
||||
];
|
||||
|
||||
// Helper: find the section key (e.g. '/reference') that matches a pathname
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
<script lang="ts">
|
||||
import IPConverter from '$lib/components/IPConverter.svelte';
|
||||
import { site, pages } from '$lib/constants/site';
|
||||
import '../../styles/pages.scss';
|
||||
|
||||
import { goto } from '$app/navigation';
|
||||
import { pages } from '$lib/constants/site';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
onMount(() => {
|
||||
goto('/ip-address-convertor/representations', { replaceState: true });
|
||||
});
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>{pages.ipConverter.title}</title>
|
||||
<meta name="description" content="{pages.ipConverter.description}" />
|
||||
<meta name="keywords" content="{site.keywords}" />
|
||||
<meta property="og:title" content="{pages.ipConverter.title}" />
|
||||
<meta property="og:description" content="{pages.ipConverter.description}" />
|
||||
<meta property="og:url" content="{site.url}/ip-address-convertor" />
|
||||
</svelte:head>
|
||||
|
||||
|
||||
<IPConverter />
|
||||
<!-- This page automatically redirects to the first sub-page -->
|
||||
<div>Redirecting to IP Address Format Converter...</div>
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import '../../styles/pages.scss';
|
||||
import '../../styles/converters.scss';
|
||||
import '../../styles/components.scss';
|
||||
import '../../../styles/pages.scss';
|
||||
import '../../../styles/converters.scss';
|
||||
import '../../../styles/components.scss';
|
||||
import { site, pages } from '$lib/constants/site';
|
||||
import Icon from '$lib/components/Icon.svelte';
|
||||
</script>
|
||||
+1
-1
@@ -9,7 +9,7 @@
|
||||
<meta name="keywords" content="IPv4, IPv6, conversion, IPv4-mapped IPv6, IP address converter, network tools" />
|
||||
<meta property="og:title" content="IPv4 to IPv6 Converter - {site.title}" />
|
||||
<meta property="og:description" content="Convert IPv4 addresses to IPv6 format using IPv4-mapped IPv6 addressing" />
|
||||
<meta property="og:url" content="{site.url}/ip-family-convertor/ipv4-to-ipv6" />
|
||||
<meta property="og:url" content="{site.url}/ip-address-convertor/families/ipv4-to-ipv6" />
|
||||
</svelte:head>
|
||||
|
||||
<IPFamilyConverter
|
||||
+1
-1
@@ -9,7 +9,7 @@
|
||||
<meta name="keywords" content="IPv6, IPv4, conversion, IPv4-mapped IPv6, IP address converter, network tools" />
|
||||
<meta property="og:title" content="IPv6 to IPv4 Converter - {site.title}" />
|
||||
<meta property="og:description" content="Extract IPv4 addresses from IPv4-mapped IPv6 addresses" />
|
||||
<meta property="og:url" content="{site.url}/ip-family-convertor/ipv6-to-ipv4" />
|
||||
<meta property="og:url" content="{site.url}/ip-address-convertor/families/ipv6-to-ipv4" />
|
||||
</svelte:head>
|
||||
|
||||
<IPFamilyConverter
|
||||
@@ -0,0 +1,19 @@
|
||||
<script lang="ts">
|
||||
import IPConverter from '$lib/components/IPConverter.svelte';
|
||||
import { site, pages } from '$lib/constants/site';
|
||||
import '../../../styles/pages.scss';
|
||||
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>{pages.ipConverter.title}</title>
|
||||
<meta name="description" content="{pages.ipConverter.description}" />
|
||||
<meta name="keywords" content="{site.keywords}" />
|
||||
<meta property="og:title" content="{pages.ipConverter.title}" />
|
||||
<meta property="og:description" content="{pages.ipConverter.description}" />
|
||||
<meta property="og:url" content="{site.url}/ip-address-convertor" />
|
||||
</svelte:head>
|
||||
|
||||
|
||||
<IPConverter />
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import { pages } from '$lib/constants/site';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
onMount(() => {
|
||||
goto('/ip-family-convertor/ipv4-to-ipv6', { replaceState: true });
|
||||
});
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>IPv4/IPv6 Converter - IP Family Conversion Tools</title>
|
||||
<meta name="description" content="Convert between IPv4 and IPv6 address formats. IPv4-mapped IPv6 conversion tools." />
|
||||
</svelte:head>
|
||||
|
||||
<!-- This page automatically redirects to the first sub-page -->
|
||||
<div>Redirecting to IPv4 to IPv6 converter...</div>
|
||||
Reference in new issue
Block a user