forked from denoland/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reference.page.jsx
53 lines (44 loc) · 1.29 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
45
46
47
48
49
50
51
52
53
import { walkSync } from "@std/fs/walk";
export const layout = "raw.tsx";
const resetRegexp =
/<link id="ddocResetStylesheet" rel="stylesheet" href=".*?reset\.css">\s+/;
const titleRegexp = /<title>(.+?)<\/title>\s*/s;
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(
resetRegexp,
"",
);
let title = "";
try {
const match = titleRegexp.exec(content);
title = match[1].slice(0, -"documentation".length) + "- Deno Docs";
} catch (e) {
if (!file.path.endsWith("prototype.html")) {
console.error(file.path);
throw e;
}
}
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, "/");
yield {
url: "/api" + path,
title,
content,
};
}
} catch (ex) {
console.warn("⚠️ Reference docs were not generated." + ex);
}
}