forked from denoland/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reference.page.jsx
44 lines (36 loc) · 1.18 KB
/
reference.page.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { walkSync } from "@std/fs/walk";
export const layout = "raw.tsx";
export default function* () {
try {
if (Deno.env.has("SKIP_REFERENCE")) {
throw new Error();
}
const files = walkSync("reference_gen/gen", {
exts: [".html"],
});
for (const file of files) {
const content = Deno.readTextFileSync(file.path).replace(
/<link id="ddocResetStylesheet" rel="stylesheet" href=".*?reset\.css">\s+/,
"",
);
const trailingLength = file.path.endsWith("index.html")
? -"index.html".length
: -".html".length;
let path = file.path.slice("reference_gen/gen".length, trailingLength);
// replace slashes for windows
path = path.replace(/\\/g, "/");
const name = file.name.slice(0, -".html".length);
const [_, group, subgroup] = path.split("/");
const groupDisplay = group.charAt(0).toUpperCase() + group.slice(1);
yield {
url: "/api" + path,
title: `${groupDisplay} Reference for ${
name === "index" ? (subgroup || "") : name
}`,
content,
};
}
} catch (ex) {
console.warn("⚠️ Reference docs were not generated." + ex);
}
}