Skip to content

Commit 9d5b9d0

Browse files
committed
docs
1 parent 07573dd commit 9d5b9d0

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

docs/src/components/ScriptVersions.astro

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
2-
import fs from "node:fs/promises";
32
import { Badge } from "@astrojs/starlight/components";
43
54
type Props = {
@@ -22,24 +21,34 @@ const {
2221
prefix = "v",
2322
} = Astro.props as Props;
2423
25-
async function readVersion(relPath: string): Promise<string> {
24+
const scripts = import.meta.glob("../../../*.bash", {
25+
query: "?raw",
26+
import: "default",
27+
eager: true,
28+
}) as Record<string, string>;
29+
30+
function readVersion(filename: string): string {
2631
try {
27-
// Build a file URL relative to this component's location
28-
const url = new URL(relPath, import.meta.url);
29-
const content = await fs.readFile(url, "utf8");
32+
const importPath = `../../../${filename}`;
33+
const content = scripts[importPath];
34+
if (!content) {
35+
console.error(`Script file ${filename} not found at ${importPath}`);
36+
return "unknown";
37+
}
3038
// More robust match: allow spaces and single/double quotes
3139
const match = content.match(
3240
/(?:^|\n)\s*script_version\s*=\s*(["'])([^"']+)\1/,
3341
);
3442
return match?.[2] ?? "unknown";
35-
} catch {
43+
} catch (e) {
44+
console.error(`Error parsing script file ${filename}:`, e);
3645
return "unknown";
3746
}
3847
}
3948
4049
// Scripts live at the repository root; this component is at docs/src/components/
4150
// So we traverse up three directories to reach the repo root.
42-
const version = await readVersion(`../../../${file}`);
51+
const version = readVersion(file);
4352
const isKnown = version !== "unknown";
4453
const normalizedVersion = typeof version === "string" ? version.trim() : "";
4554
const displayVersion = isKnown

0 commit comments

Comments
 (0)