-
Notifications
You must be signed in to change notification settings - Fork 208
/
reference.page.jsx
76 lines (65 loc) · 1.74 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { walkSync } from "@std/fs/walk";
import { unescape } from "@std/html/entities";
import entityList from "@std/html/named-entity-list.json" with { type: "json" };
export const layout = "raw.tsx";
export const sidebar = [
{
items: [
{
label: "Deno APIs",
id: "/api/deno/",
},
{
label: "Web APIs",
id: "/api/web/",
},
{
label: "Node APIs",
id: "/api/node/",
},
],
},
];
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);
const titleFirst = match[1].slice(0, -"documentation".length);
title = unescape(titleFirst, { entityList }) + "- 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);
}
}