Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/overrides/Sidebar.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Default from "@astrojs/starlight/components/Sidebar.astro";
import { Icon as AstroIcon } from "astro-icon/components";
import { lookupProductTitle } from "~/util/sidebar";

const [product, module] = Astro.url.pathname.split("/").slice(1, -1);
const [product, module] = Astro.url.pathname.split("/").filter(Boolean);
---

<a
Expand Down
13 changes: 9 additions & 4 deletions src/util/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const sidebars = new Map<string, Group>();

export async function getSidebar(context: AstroGlobal<Props>) {
const pathname = context.url.pathname;
const segments = pathname.split("/").slice(1, -1);
const segments = pathname.split("/").filter(Boolean);

const product = segments.at(0);

Expand Down Expand Up @@ -96,9 +96,14 @@ function setSidebarCurrentEntry(
pathname: string,
): boolean {
for (const entry of sidebar) {
if (entry.type === "link" && entry.href === pathname) {
entry.isCurrent = true;
return true;
if (entry.type === "link") {
const href = entry.href;

// Compare with and without trailing slash
if (href === pathname || href.slice(0, -1) === href) {
entry.isCurrent = true;
return true;
}
}

if (
Expand Down
Loading