mirror of
https://github.com/herdrdev/herdr.git
synced 2026-09-22 00:01:06 +00:00
fix: preserve preview docs navigation
This commit is contained in:
+19
-17
@@ -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()
|
||||
|
||||
@@ -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'],
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
---
|
||||
|
||||
<SidebarPersister>
|
||||
<SidebarSublist sublist={channelSidebar} />
|
||||
</SidebarPersister>
|
||||
|
||||
<div class="md:sl-hidden">
|
||||
<MobileMenuFooter />
|
||||
</div>
|
||||
@@ -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/';
|
||||
---
|
||||
|
||||
<div class="title-row sl-flex">
|
||||
@@ -8,7 +10,7 @@ const { siteTitle, siteTitleHref } = Astro.locals.starlightRoute;
|
||||
<span translate="no">{siteTitle}</span>
|
||||
</a>
|
||||
<nav class="title-nav" aria-label="Primary">
|
||||
<a href="/docs/">Docs</a>
|
||||
<a href={docsHref}>Docs</a>
|
||||
<a href="/releases/">Releases</a>
|
||||
<a href="/blog/">Blog</a>
|
||||
</nav>
|
||||
|
||||
Reference in New Issue
Block a user