-
Notifications
You must be signed in to change notification settings - Fork 79
/
_config.ts
153 lines (137 loc) · 4.47 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
import lume from "lume/mod.ts";
import codeHighlight from "lume/plugins/code_highlight.ts";
import icons from "lume/plugins/icons.ts";
import googleFonts from "lume/plugins/google_fonts.ts";
import inline from "lume/plugins/inline.ts";
import resolveUrls from "lume/plugins/resolve_urls.ts";
import esbuild from "lume/plugins/esbuild.ts";
import transformImages from "lume/plugins/transform_images.ts";
import favicon from "lume/plugins/favicon.ts";
import minifyHTML from "lume/plugins/minify_html.ts";
import postcss from "lume/plugins/postcss.ts";
import nesting from "npm:postcss-nesting";
import sitemap from "lume/plugins/sitemap.ts";
import metas from "lume/plugins/metas.ts";
import checkUrls from "lume/plugins/check_urls.ts";
import ogImages from "lume/plugins/og_images.ts";
import { env } from "lume/core/utils/env.ts";
import toc from "https://deno.land/x/[email protected]/toc/mod.ts";
import analyze, {
mergeDefaults,
} from "https://deno.land/x/[email protected]/mod.ts";
import { alert } from "npm:@mdit/[email protected]";
import ventoLang from "https://deno.land/x/[email protected]/highlightjs-vento.js";
const markdown = {
plugins: [toc, alert],
options: {
linkify: true,
},
};
const site = lume(
{
location: new URL("https://lume.land"),
},
{ markdown },
);
site
.ignore("CONTRIBUTING.md")
.ignore("README.md")
.ignore("scripts")
.copy("static", ".")
.copy("_redirects")
.use(codeHighlight({
languages: {
vento: ventoLang,
},
}))
.use(postcss({
plugins: [nesting()],
}))
.use(googleFonts({
fonts:
"https://fonts.google.com/share?selection.family=Epilogue:ital,wght@0,100..900;1,100..900|Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900|JetBrains+Mono:ital,wght@0,100..800;1,100..800",
cssFile: "/styles/main.css",
}))
.use(favicon())
.use(inline())
.use(ogImages())
.use(metas())
.use(esbuild({
extensions: [".js"],
}))
.use(resolveUrls())
.use(transformImages())
.use(sitemap())
.use(icons())
.use(checkUrls({
external: false,
ignore: [
"/blog/",
],
}))
.scopedUpdates(
(path) => path.endsWith(".png") || path.endsWith(".jpg"),
)
.filter("slice", (arr, length) => arr.slice(0, length))
.process([".html"], (pages) => {
for (const page of pages) {
const doc = page.document!;
const blocks = doc.querySelectorAll("lume-code");
blocks.forEach((block, i) => {
const pres = block.querySelectorAll(
":scope > pre",
);
const menu = doc.createElement("ul");
menu.setAttribute("role", "tablist");
menu.setAttribute("aria-label", "Code Tabs");
menu.classList.add("lume-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("lume-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);
});
}
})
.use(minifyHTML({
options: {
minify_css: false, // https://github.com/wilsonzlin/minify-html/issues/173
},
}));
site.data("scheme", async (mod: string) => {
if (env("LUME_LIVE_RELOAD")) {
return [];
}
try {
const url = import.meta.resolve(`lume/${mod}`);
const { defaults } = await import(url);
const { Options } = await analyze(url, { maxDepth: 2, private: false });
mergeDefaults(Options, defaults);
return Options.children;
} catch (error) {
console.log(`Error generating the documentation for ${mod}`);
console.log(error);
return [];
}
});
export default site;