diff --git a/src/update.rs b/src/update.rs index 58095c08..0d73b5b1 100644 --- a/src/update.rs +++ b/src/update.rs @@ -3000,8 +3000,10 @@ mod tests { #[test] fn preview_manifest_reports_update_when_build_id_differs() { - let manifest: PreviewManifest = serde_json::from_str( - r####"{ + let (os, arch) = platform_target(); + let asset_key = format!("{os}-{arch}"); + let json = format!( + r####"{{ "channel": "preview", "base_version": "9.9.9", "build_id": "2026-06-02-abcdef123456", @@ -3009,29 +3011,29 @@ mod tests { "built_at": "2026-06-02T03:00:00Z", "protocol": 77, "notes": "### Fixed\n- One", - "assets": { - "linux-x86_64": { + "assets": {{ + "{asset_key}": {{ "url": "https://example.com/herdr-linux-x86_64", "sha256": "deadbeef" - } - }, - "builds": { - "2026-06-02-abcdef123456": { + }} + }}, + "builds": {{ + "2026-06-02-abcdef123456": {{ "base_version": "9.9.9", "commit": "abcdef1234567890", "built_at": "2026-06-02T03:00:00Z", "protocol": 77, - "assets": { - "linux_x86_64": { + "assets": {{ + "{asset_key}": {{ "url": "https://example.com/herdr-linux_x86_64", "sha256": "deadbeef" - } - } - } - } - }"####, - ) - .unwrap(); + }} + }} + }} + }} + }}"#### + ); + let manifest: PreviewManifest = serde_json::from_str(&json).unwrap(); let release = release_info_from_preview_manifest(&manifest) .unwrap() diff --git a/website/astro.config.mjs b/website/astro.config.mjs index 2da2dd44..00d97ccc 100644 --- a/website/astro.config.mjs +++ b/website/astro.config.mjs @@ -63,6 +63,7 @@ export default defineConfig({ ], components: { Header: './src/components/Header.astro', + Sidebar: './src/components/Sidebar.astro', SiteTitle: './src/components/SiteTitle.astro', }, customCss: ['./src/styles/starlight.css'], diff --git a/website/src/components/Sidebar.astro b/website/src/components/Sidebar.astro new file mode 100644 index 00000000..c875a390 --- /dev/null +++ b/website/src/components/Sidebar.astro @@ -0,0 +1,49 @@ +--- +import MobileMenuFooter from 'virtual:starlight/components/MobileMenuFooter'; +import SidebarPersister from '@astrojs/starlight/components/SidebarPersister.astro'; +import SidebarSublist from '@astrojs/starlight/components/SidebarSublist.astro'; + +const { sidebar } = Astro.locals.starlightRoute; +const pathname = Astro.url.pathname; +const isPreview = pathname === '/docs/preview/' || pathname.startsWith('/docs/preview/'); +const channelSidebar = isPreview ? rewriteSidebar(sidebar) : sidebar; + +function rewriteSidebar(entries) { + return entries.map((entry) => { + if (entry.type === 'link') { + const href = previewHref(entry.href); + return { + ...entry, + href, + isCurrent: samePath(href, pathname), + }; + } + const rewrittenEntries = rewriteSidebar(entry.entries); + return { + ...entry, + entries: rewrittenEntries, + }; + }); +} + +function previewHref(href) { + if (!href.startsWith('/docs/') || href.startsWith('/docs/preview/')) return href; + return href === '/docs/' ? '/docs/preview/' : href.replace(/^\/docs\//, '/docs/preview/'); +} + +function samePath(left, right) { + return stripTrailingSlash(left) === stripTrailingSlash(right); +} + +function stripTrailingSlash(path) { + return path.length > 1 ? path.replace(/\/$/, '') : path; +} +--- + + + + + +
+ +
diff --git a/website/src/components/SiteTitle.astro b/website/src/components/SiteTitle.astro index 1173f2b6..d35da5d6 100644 --- a/website/src/components/SiteTitle.astro +++ b/website/src/components/SiteTitle.astro @@ -1,5 +1,7 @@ --- const { siteTitle, siteTitleHref } = Astro.locals.starlightRoute; +const isPreview = Astro.url.pathname === '/docs/preview/' || Astro.url.pathname.startsWith('/docs/preview/'); +const docsHref = isPreview ? '/docs/preview/' : '/docs/'; ---
@@ -8,7 +10,7 @@ const { siteTitle, siteTitleHref } = Astro.locals.starlightRoute; {siteTitle}