Files
vercel-labs--zerolang/docs/lib/search-index.ts
T
wehub-resource-sync e7738de6d2
CI / Deep Native Runtime Cases (1/6) (push) Has been skipped
CI / Native Preflight (push) Failing after 1s
CI / Native Runtime Cases (1/2) (push) Failing after 0s
CI / Native Runtime Cases (2/2) (push) Failing after 1s
CI / Native Metadata Reports (push) Failing after 0s
CI / Native Direct Backend Artifacts (push) Failing after 0s
CI / Native Sanitizer Smoke (push) Failing after 1s
CI / Command Contract Snapshots (push) Failing after 1s
CI / Deep Conformance Suite (push) Has been skipped
CI / Graph Build Perf (push) Failing after 1s
CI / Deep Native Preflight (push) Has been skipped
CI / Deep Native Runtime Cases (2/6) (push) Has been skipped
CI / Deep Native Runtime Cases (3/6) (push) Has been skipped
CI / Conformance Suite (push) Failing after 1s
CI / Workspace Checks (push) Failing after 0s
CI / Deep Native Runtime Cases (5/6) (push) Has been skipped
CI / Deep Native Runtime Cases (6/6) (push) Has been skipped
CI / Deep Native Runtime Cases (4/6) (push) Has been skipped
CI / Deep Graph Build Perf (push) Has been skipped
chore: import upstream snapshot with attribution
2026-07-13 12:29:30 +08:00

46 lines
1.1 KiB
TypeScript

import { readArticleBySlug } from "./articles";
import { docs } from "./docs";
import type { SearchIndexEntry } from "./types";
let cached: SearchIndexEntry[] | null = null;
function stripMarkdown(md: string): string {
return md
.replace(/```[\s\S]*?```/g, "")
.replace(/`[^`]+`/g, "")
.replace(/\[([^\]]+)\]\([^)]+\)/g, "$1")
.replace(/^#{1,6}\s+/gm, "")
.replace(/\*{1,3}([^*]+)\*{1,3}/g, "$1")
.replace(/<[^>]+>/g, "")
.replace(/\n{3,}/g, "\n\n")
.trim();
}
export async function getSearchIndex(): Promise<SearchIndexEntry[]> {
if (cached) return cached;
const entries: SearchIndexEntry[] = [];
for (const doc of docs) {
try {
const raw = await readArticleBySlug(doc.slug);
const content = raw ? stripMarkdown(raw) : "";
entries.push({
title: doc.title,
href: doc.path,
section: doc.section ?? "",
content,
});
} catch {
entries.push({
title: doc.title,
href: doc.path,
section: doc.section ?? "",
content: "",
});
}
}
cached = entries;
return entries;
}