-
Notifications
You must be signed in to change notification settings - Fork 180
/
_config.ts
296 lines (269 loc) · 9 KB
/
_config.ts
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
import "@std/dotenv/load";
import lume from "lume/mod.ts";
import esbuild from "lume/plugins/esbuild.ts";
import jsx from "lume/plugins/jsx_preact.ts";
import prism from "lume/plugins/prism.ts";
import redirects from "lume/plugins/redirects.ts";
import search from "lume/plugins/search.ts";
import sitemap from "lume/plugins/sitemap.ts";
import postcss from "lume/plugins/postcss.ts";
import checkUrls from "lume/plugins/check_urls.ts";
import tw from "tailwindcss";
import tailwindConfig from "./tailwind.config.js";
import Prism from "npm:[email protected]";
import "npm:[email protected]/components/prism-typescript.js";
import "npm:[email protected]/components/prism-diff.js";
import "npm:[email protected]/components/prism-json.js";
import "npm:[email protected]/components/prism-bash.js";
import "npm:[email protected]/components/prism-json5.js";
Prism.languages.jsonc = Prism.languages.json5;
import title from "https://deno.land/x/[email protected]/title.ts";
import toc from "https://deno.land/x/[email protected]/toc.ts";
import { CSS as GFM_CSS } from "https://jsr.io/@deno/gfm/0.8.2/style.ts";
import anchor from "npm:markdown-it-anchor@9";
import { full as emoji } from "npm:markdown-it-emoji@3";
import admonitionPlugin from "./markdown-it/admonition.ts";
import codeblockCopyPlugin from "./markdown-it/codeblock-copy.ts";
import codeblockTitlePlugin from "./markdown-it/codeblock-title.ts";
import relativeLinksPlugin from "./markdown-it/relative-path.ts";
import replacerPlugin from "./markdown-it/replacer.ts";
import {
clear as oramaClear,
deploy as oramaDeploy,
generateDocumentsForExamples,
generateDocumentsForPage,
generateDocumentsForSymbols,
notify as oramaNotify,
OramaDocument,
} from "./orama.ts";
import apiDocumentContentTypeMiddleware from "./middleware/apiDocContentType.ts";
import redirectsMiddleware, {
toFileAndInMemory,
} from "./middleware/redirects.ts";
import createRoutingMiddleware from "./middleware/functionRoutes.ts";
import createGAMiddleware from "./middleware/googleAnalytics.ts";
const site = lume(
{
location: new URL("https://docs.deno.com"),
caseSensitiveUrls: true,
server: {
middlewares: [
redirectsMiddleware,
createRoutingMiddleware(),
createGAMiddleware({
addr: { transport: "tcp", hostname: "localhost", port: 3000 },
}),
apiDocumentContentTypeMiddleware,
],
},
},
{
markdown: {
plugins: [
replacerPlugin,
emoji,
admonitionPlugin,
codeblockCopyPlugin,
codeblockTitlePlugin,
[
anchor,
{
permalink: anchor.permalink.linkInsideHeader({
symbol:
`<span class="sr-only">Jump to heading</span><span aria-hidden="true" class="anchor-end">#</span>`,
placement: "after",
}),
getTokensText(tokens: { type: string; content: string }[]) {
return tokens
.filter((t) => ["text", "code_inline"].includes(t.type))
.map((t) => t.content.replaceAll(/ \([0-9/]+?\)/g, ""))
.join("")
.trim();
},
},
],
relativeLinksPlugin,
],
options: {
linkify: true,
langPrefix: "highlight notranslate language-",
},
},
},
);
site.copy("static", ".");
site.copy("subhosting/api/images");
site.copy("deploy/docs-images");
site.copy("deploy/kv/manual/images");
site.copy("deploy/tutorials/images");
site.copy("deploy/kv/tutorials/images");
site.copy("runtime/fundamentals/images");
site.copy("runtime/getting_started/images");
site.copy("runtime/reference/images");
site.copy("runtime/contributing/images");
site.copy("runtime/tutorials/images");
site.copy("deploy/manual/images");
site.copy("deno.json");
site.copy("go.json");
site.copy("oldurls.json");
site.copy("server.ts");
site.copy("middleware");
site.copy("examples");
site.copy(".env");
site.use(
redirects({
output: toFileAndInMemory,
}),
);
site.use(search());
site.use(jsx());
site.use(
postcss({
plugins: [tw(tailwindConfig)],
}),
);
site.use(
esbuild({
extensions: [".client.ts"],
options: {
minify: false,
splitting: true,
},
}),
);
// This is a work-around due to deno-dom's dependency of nwsapi not supporting
// :has selectors, nor having intention of supporting them, so using `body:not(:has(.ddoc))`
// is not possible. This works around by adding an `apply-prism` class on pages that
// don't use a ddoc class.
site.process([".html"], (pages) => {
for (const page of pages) {
const document = page.document!;
if (!document.querySelector(".ddoc")) {
document.body.classList.add("apply-prism");
}
}
});
site.use(
prism({
cssSelector: "body.apply-prism pre code",
}),
);
site.use(toc({ anchor: false }));
site.use(title());
site.use(sitemap());
site.addEventListener("afterBuild", () => {
Deno.writeTextFileSync(site.dest("gfm.css"), GFM_CSS);
});
site.copy("reference_gen/gen/deno/page.css", "/api/deno/page.css");
site.copy("reference_gen/gen/deno/styles.css", "/api/deno/styles.css");
site.copy("reference_gen/gen/deno/script.js", "/api/deno/script.js");
site.copy("reference_gen/gen/web/page.css", "/api/web/page.css");
site.copy("reference_gen/gen/web/styles.css", "/api/web/styles.css");
site.copy("reference_gen/gen/web/script.js", "/api/web/script.js");
site.copy("reference_gen/gen/node/page.css", "/api/node/page.css");
site.copy("reference_gen/gen/node/styles.css", "/api/node/styles.css");
site.copy("reference_gen/gen/node/script.js", "/api/node/script.js");
site.process([".html"], (pages) => {
for (const page of pages) {
const document = page.document;
if (document) {
const tabGroups = document.querySelectorAll("deno-tabs");
for (const tabGroup of tabGroups) {
const newGroup = document.createElement("div");
newGroup.classList.add("deno-tabs");
newGroup.dataset.id = tabGroup.getAttribute("group-id")!;
const buttons = document.createElement("ul");
buttons.classList.add("deno-tabs-buttons");
newGroup.appendChild(buttons);
const tabs = document.createElement("div");
tabs.classList.add("deno-tabs-content");
newGroup.appendChild(tabs);
for (const tab of tabGroup.children) {
if (tab.tagName === "DENO-TAB") {
const selected = tab.getAttribute("default") !== null;
const buttonContainer = document.createElement("li");
buttons.appendChild(buttonContainer);
const button = document.createElement("button");
button.textContent = tab.getAttribute("label")!;
button.dataset.tab = tab.getAttribute("value")!;
button.dataset.active = String(selected);
buttonContainer.appendChild(button);
const content = document.createElement("div");
content.innerHTML = tab.innerHTML;
content.dataset.tab = tab.getAttribute("value")!;
content.dataset.active = String(selected);
tabs.appendChild(content);
}
}
tabGroup.replaceWith(newGroup);
}
}
}
});
const ORAMA_API_KEY = Deno.env.get("ORAMA_CLOUD_API_KEY");
const ORAMA_INDEX_ID = Deno.env.get("ORAMA_CLOUD_INDEX_ID");
if (ORAMA_API_KEY && ORAMA_INDEX_ID) {
site.process([".html"], async (pages) => {
let pageEntries: OramaDocument[] = [];
await oramaClear(ORAMA_API_KEY, ORAMA_INDEX_ID);
for (const page of pages) {
if (
page.document &&
(page.data.url.startsWith("/runtime/") ||
page.data.url.startsWith("/deploy/") ||
page.data.url.startsWith("/subhosting/"))
) {
pageEntries = pageEntries.concat(generateDocumentsForPage(page));
}
}
await oramaNotify(ORAMA_API_KEY, ORAMA_INDEX_ID, pageEntries, "pages");
await oramaNotify(
ORAMA_API_KEY,
ORAMA_INDEX_ID,
await generateDocumentsForExamples(),
"examples",
);
try {
await oramaNotify(
ORAMA_API_KEY,
ORAMA_INDEX_ID,
await generateDocumentsForSymbols(),
"symbols",
);
} catch (e) {
console.warn(
"⚠️ Orama documents for reference docs were not generated.",
e,
);
}
await oramaDeploy(ORAMA_API_KEY, ORAMA_INDEX_ID);
});
} else {
console.warn("⚠️ Orama documents were not generated.");
}
site.ignore(
"old",
"README.md",
(path) => path.match(/\/reference_gen.*.ts/) !== null,
(path) => path.includes("/reference_gen/node_modules"),
(path) => path.includes("/reference_gen/node_descriptions"),
"examples",
// "deploy",
// "examples.page.tsx",
// "runtime",
// "subhosting",
);
site.scopedUpdates((path) => path == "/overrides.css");
site.use(checkUrls({
external: false, // Set to true to check external links
output: "_broken_links.json",
ignore: [
"https://www.googletagmanager.com",
],
}));
site.remoteFile(
"orama.css",
"https://unpkg.com/@orama/[email protected]/dist/orama-ui/orama-ui.css",
);
site.copy("orama.css");
export default site;