forked from probe-rs/webpage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_config.ts
116 lines (103 loc) · 3.55 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
import lume from "lume/mod.ts";
import jsx from "lume/plugins/jsx.ts";
import vento from "lume/plugins/vento.ts";
import attributes from "lume/plugins/attributes.ts";
import base_path from "lume/plugins/base_path.ts";
import code_highlight from "lume/plugins/code_highlight.ts";
import date from "lume/plugins/date.ts";
import esbuild from "lume/plugins/esbuild.ts";
import eta from "lume/plugins/eta.ts";
import feed from "lume/plugins/feed.ts";
import filter_pages from "lume/plugins/filter_pages.ts";
import inline from "lume/plugins/inline.ts";
import mdx from "lume/plugins/mdx.ts";
import picture from "lume/plugins/picture.ts";
import imagick from "lume/plugins/imagick.ts";
import sass from "lume/plugins/sass.ts";
import source_maps from "lume/plugins/source_maps.ts";
import svgo from "lume/plugins/svgo.ts";
import toc from "https://deno.land/x/[email protected]/toc/mod.ts";
import readingTime from "https://raw.githubusercontent.com/lumeland/experimental-plugins/main/reading_time/mod.ts";
import { Page } from "lume/core.ts";
const markdown = {
plugins: [toc],
keepDefaultPlugins: true,
};
const site = lume(
{
location: new URL("https://probe.rs"),
dest: "./target",
src: "./src",
server: {
// open: true,
},
},
{ markdown }
);
site.copy("static", ".");
site.copy([".gif"]);
site.use(jsx());
site.use(vento());
site.use(attributes());
site.use(base_path());
site.use(code_highlight());
site.use(date());
site.use(esbuild());
site.use(eta());
site.use(feed());
site.use(filter_pages());
site.use(inline());
site.use(mdx());
site.use(picture());
site.use(imagick());
site.use(sass());
site.use(source_maps());
site.use(svgo());
site.use(readingTime());
site
.scopedUpdates((path) => path.endsWith(".png") || path.endsWith(".jpg"))
.filter("slice", (arr, length) => arr.slice(0, length))
.process([".html"], (page) => {
const doc = page.document!;
const blocks = doc.querySelectorAll("probe-rs-code");
blocks.forEach((block, i) => {
const pres = (block as unknown as HTMLElement).querySelectorAll(
":scope > pre"
);
const menu = doc.createElement("ul");
menu.setAttribute("role", "tablist");
menu.setAttribute("aria-label", "Code Tabs");
menu.classList.add("probe-rs-code-menu");
pres.forEach((pre, j) => {
const title = pre.querySelector("code")!.getAttribute("title")!;
const li = doc.createElement("li");
li.setAttribute("role", "presentation");
const button = doc.createElement("button");
button.setAttribute("role", "tab");
button.setAttribute("aria-selected", j === 0 ? true : false);
button.setAttribute("aria-controls", `panel-${i + 1}-${j + 1}`);
button.setAttribute("id", `tab-${i + 1}-${j + 1}`);
button.setAttribute("tabindex", j === 0 ? 0 : -1);
button.innerText = title;
button.classList.add("probe-rs-code-tab");
if (j > 0) {
pre.setAttribute("hidden", "true");
} else {
button.classList.add("is-active");
}
pre.setAttribute("role", "tabpanel");
pre.setAttribute("aria-labelledby", `tab-${i + 1}-${j + 1}`);
pre.setAttribute("id", `panel-${i + 1}-${j + 1}`);
pre.setAttribute("tabindex", "0");
li.append(button);
menu.appendChild(li);
});
(block as unknown as HTMLElement).prepend(menu as unknown as Node);
});
})
.preprocess([".md"], (page: Page) => {
page.data.excerpt ??= (page.data.content as string).split(
/<!--\s*more\s*-->/i,
)[0];
});
export default site;