-
Notifications
You must be signed in to change notification settings - Fork 0
/
_config.ts
62 lines (52 loc) · 1.99 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
import anchor from "https://ga.jspm.io/npm:[email protected]/dist/markdownItAnchor.mjs";
import footnote from "https://ga.jspm.io/npm:[email protected]/index.js";
import toc from "https://ga.jspm.io/npm:[email protected]/dist/markdownItTocDoneRight.js";
import { Element } from "https://deno.land/x/deno_dom/src/dom/element.ts";
import lume from "lume/mod.ts";
import attributes from "lume/plugins/attributes.ts";
import prism from "lume/plugins/prism.ts";
import inline from "lume/plugins/inline.ts";
import postcss from "lume/plugins/postcss.ts";
import nano from "npm:cssnano";
import resolveUrls from "lume/plugins/resolve_urls.ts";
/** language support for prism */
import "npm:[email protected]/components/prism-bash.js";
import "npm:[email protected]/components/prism-python.js";
const tocWithOptions = [toc, { level: 2 }];
const markdown = {
plugins: [anchor, footnote, tocWithOptions],
keepDefaultPlugins: true,
};
const site = lume({}, { markdown });
// Ignore all README.md files
site.ignore((path) => {
return path.match(/^.*README\.md$/) !== null;
});
site.use(attributes())
.use(inline())
.use(prism())
.use(resolveUrls());
site.use(postcss({
extensions: [".css"],
}));
site.hooks.addPostcssPlugin(nano);
// don't process, just copy to _site/
// site.copy("assets/images");
// add attributes to all links marked with 'ext'
site.process([".html"], (page) => {
// add appropriate attributes to external links
page.document?.querySelectorAll("a[ext]").forEach((link) => {
const linkEl = link as unknown as Element;
if (!linkEl.hasAttribute("target")) {
linkEl.setAttribute("target", "_blank");
}
linkEl.setAttribute("rel", "noopener noreferrer");
linkEl.removeAttribute("ext");
});
// todo: work out to actually patch the markdown plugin, instead.
page.document?.querySelectorAll(".footnote-backref").forEach((link) => {
const linkEl = link as unknown as Element;
linkEl.innerHTML = "[back to text]";
});
});
export default site;