From 51ed34739a43c0a1518faab08764d95d3d4ac7ad Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Wed, 7 Aug 2024 18:02:28 +0100 Subject: [PATCH] Underline the current section in the nav bar --- src/lib/nav/NavHeader.svelte | 6 ++++-- src/lib/nav/index.ts | 11 +++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/lib/nav/NavHeader.svelte b/src/lib/nav/NavHeader.svelte index 6f269c563d..bd4ea7c8d2 100644 --- a/src/lib/nav/NavHeader.svelte +++ b/src/lib/nav/NavHeader.svelte @@ -10,9 +10,11 @@ {#if navList}
    - {#each navList as navItem} + {#each navList as [path, title, currentlyHere]}
  1. - {navItem[1]} + + {title} +
  2. {/each}
diff --git a/src/lib/nav/index.ts b/src/lib/nav/index.ts index 25e6a224ad..15507eda0e 100644 --- a/src/lib/nav/index.ts +++ b/src/lib/nav/index.ts @@ -349,10 +349,11 @@ export function getNextPage( return result; } +// Returns [path, title, currently here] export function getNavList( rawPath: string, routeCheckType: "street" | "path" | "", -): [string, string][] | null { +): [string, string, boolean][] | null { let path = getSectionPath(rawPath); if (!path) { return null; @@ -360,9 +361,11 @@ export function getNavList( let sections = filterMainPageSections(routeCheckType); const toolName = path != "/" ? path.split("/")[1] : ""; - return sections.filter((section) => { - return section[0] != "/" && section[0].split("/")[1] == toolName; - }); + return sections + .filter((section) => { + return section[0] != "/" && section[0].split("/")[1] == toolName; + }) + .map(([p, title]) => [p, title, p == path]); } export function canonicalizePath(path: string): string {