From fcc173eb07ffe1f4bde19ecd946139a1d39f0eac Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 31 Aug 2025 07:17:02 +0100 Subject: [PATCH] Re-ordered IP convertor --- src/lib/components/SubHeader.svelte | 136 ++++++++++++++++-- src/lib/constants/nav.ts | 67 ++++++--- src/routes/ip-address-convertor/+page.svelte | 19 ++- .../families}/+layout.svelte | 6 +- .../families}/ipv4-to-ipv6/+page.svelte | 2 +- .../families}/ipv6-to-ipv4/+page.svelte | 2 +- .../representations/+page.svelte | 19 +++ src/routes/ip-family-convertor/+page.svelte | 17 --- 8 files changed, 204 insertions(+), 64 deletions(-) rename src/routes/{ip-family-convertor => ip-address-convertor/families}/+layout.svelte (98%) rename src/routes/{ip-family-convertor => ip-address-convertor/families}/ipv4-to-ipv6/+page.svelte (91%) rename src/routes/{ip-family-convertor => ip-address-convertor/families}/ipv6-to-ipv4/+page.svelte (90%) create mode 100644 src/routes/ip-address-convertor/representations/+page.svelte delete mode 100644 src/routes/ip-family-convertor/+page.svelte diff --git a/src/lib/components/SubHeader.svelte b/src/lib/components/SubHeader.svelte index 7553887..0e90bf9 100644 --- a/src/lib/components/SubHeader.svelte +++ b/src/lib/components/SubHeader.svelte @@ -1,26 +1,134 @@ -{#if links} +{#if navStructure} {/if} + + diff --git a/src/lib/constants/nav.ts b/src/lib/constants/nav.ts index ee0a705..d4ce975 100644 --- a/src/lib/constants/nav.ts +++ b/src/lib/constants/nav.ts @@ -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 = { +export const SUB_NAV: Record = { '/cidr-convertor': [ { href: '/cidr-convertor/cidr-to-subnet-mask', @@ -45,18 +43,34 @@ export const SUB_NAV: Record = { 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 diff --git a/src/routes/ip-address-convertor/+page.svelte b/src/routes/ip-address-convertor/+page.svelte index 4c3e03c..4070e44 100644 --- a/src/routes/ip-address-convertor/+page.svelte +++ b/src/routes/ip-address-convertor/+page.svelte @@ -1,19 +1,18 @@ {pages.ipConverter.title} - - - - - - + +
Redirecting to IP Address Format Converter...
diff --git a/src/routes/ip-family-convertor/+layout.svelte b/src/routes/ip-address-convertor/families/+layout.svelte similarity index 98% rename from src/routes/ip-family-convertor/+layout.svelte rename to src/routes/ip-address-convertor/families/+layout.svelte index 88a9434..85a0f47 100644 --- a/src/routes/ip-family-convertor/+layout.svelte +++ b/src/routes/ip-address-convertor/families/+layout.svelte @@ -1,7 +1,7 @@ diff --git a/src/routes/ip-family-convertor/ipv4-to-ipv6/+page.svelte b/src/routes/ip-address-convertor/families/ipv4-to-ipv6/+page.svelte similarity index 91% rename from src/routes/ip-family-convertor/ipv4-to-ipv6/+page.svelte rename to src/routes/ip-address-convertor/families/ipv4-to-ipv6/+page.svelte index 762748c..c7d29f2 100644 --- a/src/routes/ip-family-convertor/ipv4-to-ipv6/+page.svelte +++ b/src/routes/ip-address-convertor/families/ipv4-to-ipv6/+page.svelte @@ -9,7 +9,7 @@ - + - + + import IPConverter from '$lib/components/IPConverter.svelte'; + import { site, pages } from '$lib/constants/site'; + import '../../../styles/pages.scss'; + + + + + {pages.ipConverter.title} + + + + + + + + + + diff --git a/src/routes/ip-family-convertor/+page.svelte b/src/routes/ip-family-convertor/+page.svelte deleted file mode 100644 index a039dd0..0000000 --- a/src/routes/ip-family-convertor/+page.svelte +++ /dev/null @@ -1,17 +0,0 @@ - - - - IPv4/IPv6 Converter - IP Family Conversion Tools - - - - -
Redirecting to IPv4 to IPv6 converter...
\ No newline at end of file