Skip to content

Commit cd71771

Browse files
committed
fix(theme-docs): export sortDedupeDocLinks for getStaticPaths bundle
Astro compiles getStaticPaths separately; local helpers in the same frontmatter were not in scope at build time (sortDedupeDocLinks is not defined). Made-with: Cursor
1 parent 94cba91 commit cd71771

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

packages/theme-docs/src/lib/wikiGraph.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,21 @@ export interface WikiGraphJson {
4646
broken?: WikiGraphBroken[];
4747
}
4848

49+
/** Dedupe graph nodes by id, sort by title (for Linked pages lists). */
50+
export function sortDedupeDocLinks(
51+
nodes: WikiGraphNode[],
52+
): { title: string; href: string }[] {
53+
const seen = new Set<string>();
54+
const out: WikiGraphNode[] = [];
55+
for (const n of nodes) {
56+
if (seen.has(n.id)) continue;
57+
seen.add(n.id);
58+
out.push(n);
59+
}
60+
out.sort((a, b) => a.title.localeCompare(b.title));
61+
return out.map((n) => ({ title: n.title, href: n.href }));
62+
}
63+
4964
function stripFencedCode(raw: string): string {
5065
return raw.replace(/```[\s\S]*?```/g, " ");
5166
}

packages/theme-docs/src/pages/section/[...slug].astro

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,7 @@ import AssetViewerJs from "../../components/asset/AssetViewerJs.astro";
1919
import AssetIpynb from "../../components/asset/AssetIpynb.astro";
2020
import AssetRst from "../../components/asset/AssetRst.astro";
2121
import AssetEpub from "../../components/asset/AssetEpub.astro";
22-
import { buildWikiGraph, type WikiGraphNode } from "../../lib/wikiGraph.js";
23-
24-
function sortDedupeDocLinks(nodes: WikiGraphNode[]): { title: string; href: string }[] {
25-
const seen = new Set<string>();
26-
const out: WikiGraphNode[] = [];
27-
for (const n of nodes) {
28-
if (seen.has(n.id)) continue;
29-
seen.add(n.id);
30-
out.push(n);
31-
}
32-
out.sort((a, b) => a.title.localeCompare(b.title));
33-
return out.map((n) => ({ title: n.title, href: n.href }));
34-
}
22+
import { buildWikiGraph, sortDedupeDocLinks, type WikiGraphNode } from "../../lib/wikiGraph.js";
3523
3624
export async function getStaticPaths() {
3725
const projectRoot = process.env.BARODOC_PROJECT_ROOT || process.cwd();

0 commit comments

Comments
 (0)