-
Notifications
You must be signed in to change notification settings - Fork 0
/
_config.ts
74 lines (66 loc) · 2.32 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
import lume from "lume/mod.ts";
import nunjucks from "lume/plugins/nunjucks.ts";
import code_highlight from "lume/plugins/code_highlight.ts";
import sass from "lume/plugins/sass.ts";
import sitemap from "lume/plugins/sitemap.ts";
import slugify_urls from "lume/plugins/slugify_urls.ts";
import nav from "lume/plugins/nav.ts";
import metas from "lume/plugins/metas.ts";
import picture from "lume/plugins/picture.ts";
import transform_images from "lume/plugins/transform_images.ts";
import resolveUrls from "lume/plugins/resolve_urls.ts";
import type { Options } from "lume/plugins/markdown.ts";
const webappUrl = Deno.env.get("WEBAPP_URL");
const markdown: Options = {
rules: {
"image": (tokens, idx, _options, _env, slf) => {
const token = tokens[idx];
const attributes = token.attrs || [];
if (
attributes.some((attribute: [string, string]) => {
return attribute[0] === "transform-images";
})
) {
return `<img alt="${token.content}" ${slf.renderAttrs(token)} />`;
}
return `<img alt="${token.content}" ${slf.renderAttrs(token)} transform-images="avif jpeg" />`;
},
"link_open": (tokens, idx, options, _env, slf) => {
const attrs: [string, string][] = tokens[idx].attrs;
//Check is link is internal. Link is set as internal if href value starts with either "/" or "#"
const isInternalLink = attrs.some((attr) =>
attr[0] === "href" && (attr[1].startsWith("/") || attr[1].startsWith("#"))
);
if (!isInternalLink) {
tokens[idx].attrSet("target", "_blank");
tokens[idx].attrSet("rel", "noopener noreferrer");
}
return slf.renderToken(tokens, idx, options);
},
},
};
const site = lume({
location: webappUrl ? new URL(webappUrl) : undefined,
src: "./src",
dest: "_site",
includes: "_includes",
components: {
variable: "comp",
},
}, { markdown });
site.use(nunjucks());
site.use(code_highlight());
site.use(sass());
site.use(sitemap());
site.use(slugify_urls());
site.use(nav());
site.use(metas());
site.use(resolveUrls());
site.use(picture());
site.use(transform_images());
site.filter("log", (value) => console.log(value));
site.remoteFile(
"styles/generated-code-highlight.scss",
"https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/styles/a11y-light.min.css",
);
export default site;