-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_config.ts
167 lines (139 loc) · 3.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
import lume from "lume/mod.ts";
import code_highlight from "lume/plugins/code_highlight.ts";
import jsx_preact from "lume/plugins/jsx_preact.ts";
import sitemap from "lume/plugins/sitemap.ts";
import toc from "https://deno.land/x/[email protected]/toc.ts";
import sass from "lume/plugins/sass.ts";
import lang_typescript from "npm:highlight.js/lib/languages/typescript";
import lang_plaintext from "npm:highlight.js/lib/languages/plaintext";
import lang_shell from "npm:highlight.js/lib/languages/shell";
import versions from "./_versions.ts";
const site = lume({
location: new URL("https://mtkru.to"),
src: `./src`,
}, {
markdown: { options: { typographer: true } },
});
site.ignore("components");
site.use(
toc({
slugify: (text) =>
text.replaceAll(/\p{P}/ug, "").toLowerCase().replaceAll(/\s+/g, "-"),
}),
);
site.data("deno", "@mtkruto/mtkruto");
site.data("esm", `https://esm.sh/jsr/@mtkruto/mtkruto@${versions[0]}`);
site.use(sass());
site.use(code_highlight({
languages: {
typescript: lang_typescript,
shell: lang_shell,
txt: lang_plaintext,
},
}));
site.use(jsx_preact());
site.use(sitemap());
site.data("layout", "layout.tsx");
site.copy("_headers");
site.copy("static", ".");
site.process([".html"], (pages) => {
for (const page of pages) {
const document = page.document;
if (!document) {
continue;
}
for (const code of document.querySelectorAll(".language-shell")) {
code.innerHTML = code.innerHTML.trim()
.split("\n").map((v) =>
`<span style="opacity: 0.5; user-select: none">$ </span>${v}`
).join("\n");
}
}
});
site.process([".html"], (pages) => {
for (const page of pages) {
const document = page.document;
if (!document) {
continue;
}
for (const codeGroup of document.querySelectorAll("code-group")) {
const div = document.createElement("div");
let first = true;
{
const controls = document.createElement("div");
controls.classList.add("code-group-header");
let first = true;
let n = 0;
for (const node of codeGroup.querySelectorAll("code-group-item")) {
controls.innerHTML +=
`<button data-n=${n++} class="code-group-button${
first ? " code-group-button-active" : ""
}">${node.getAttribute("title")}</button>`;
first = false;
}
div.append(controls);
}
let n = 0;
for (const pre of codeGroup.querySelectorAll("pre")) {
if (!first) {
pre.setAttribute("hidden", "");
} else {
first = false;
}
pre.setAttribute("data-n", n++ + "");
pre.classList.add("code-group-item");
div.append(pre);
}
div.classList.add("code-group");
codeGroup.replaceWith(div);
}
}
});
site.preprocess(
[".md"],
(pages) => pages.forEach((page) => page.data.templateEngine = ["vto", "md"]),
);
site.helper(
"getTitle",
(title) => (site.pages.find((v) => v.src.path == title)?.data.title ?? title),
{ type: "filter" },
);
site.helper(
"m",
(name) => (`[${name}](/methods/${name.toLowerCase()})`),
{ type: "filter" },
);
site.helper(
"t",
(name) => (`[${name}](/types/${name.toLowerCase()})`),
{ type: "filter" },
);
site.helper("install", (pkg: string) => {
const jsr = pkg.startsWith("jsr:");
jsr && (pkg = pkg.slice(4));
return `
<code-group>
<code-group-item title="pnpm">
\`\`\`shell
pnpm ${jsr ? "dlx jsr i " + pkg : "add " + pkg}
\`\`\`
</code-group-item>
<code-group-item title="Yarn">
\`\`\`shell
yarn ${jsr ? "dlx jsr i " + pkg : "add " + pkg}
\`\`\`
</code-group-item>
<code-group-item title="npm">
\`\`\`shell
${jsr ? "npx jsr i " + pkg : "npm install " + pkg}
\`\`\`
</code-group-item>
<code-group-item title="Bun">
\`\`\`shell
${jsr ? "bunx jsr add " + pkg : "bun add " + pkg}
\`\`\`
</code-group-item>
</code-group>
`;
}, { type: "filter" });
export default site;