Skip to content

Commit c9dfa44

Browse files
committed
Support paths with and without trailing slash in local dev
1 parent 3a6a641 commit c9dfa44

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

astro.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ const runLinkCheck = process.env.RUN_LINK_CHECK || false;
4444
// https://astro.build/config
4545
export default defineConfig({
4646
site: "https://developers.cloudflare.com",
47-
trailingSlash: "always",
4847
markdown: {
4948
smartypants: false,
5049
rehypePlugins: [

src/components/overrides/Sidebar.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Default from "@astrojs/starlight/components/Sidebar.astro";
55
import { Icon as AstroIcon } from "astro-icon/components";
66
import { lookupProductTitle } from "~/util/sidebar";
77
8-
const [product, module] = Astro.url.pathname.split("/").slice(1, -1);
8+
const [product, module] = Astro.url.pathname.split("/").filter(Boolean);
99
---
1010

1111
<a

src/util/sidebar.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const sidebars = new Map<string, Group>();
1616

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

2121
const product = segments.at(0);
2222

@@ -96,9 +96,14 @@ function setSidebarCurrentEntry(
9696
pathname: string,
9797
): boolean {
9898
for (const entry of sidebar) {
99-
if (entry.type === "link" && entry.href === pathname) {
100-
entry.isCurrent = true;
101-
return true;
99+
if (entry.type === "link") {
100+
const href = entry.href;
101+
102+
// Compare with and without trailing slash
103+
if (href === pathname || href.slice(0, -1) === href) {
104+
entry.isCurrent = true;
105+
return true;
106+
}
102107
}
103108

104109
if (

0 commit comments

Comments
 (0)