-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path_config.ts
230 lines (208 loc) · 6.42 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
// Lume
import { Page } from "lume/core/file.ts";
import lume from "lume/mod.ts";
import date from "lume/plugins/date.ts";
// import esbuild from "lume/plugins/esbuild.ts";
import metas from "lume/plugins/metas.ts";
import feed from "lume/plugins/feed.ts";
import reading_info from "lume/plugins/reading_info.ts";
import vento from "lume/plugins/vento.ts";
import remark from "lume/plugins/remark.ts";
import postcss from "lume/plugins/postcss.ts";
import sitemap from "lume/plugins/sitemap.ts";
import checkUrls from "lume/plugins/check_urls.ts";
// Experimental Plugins
import redirect from "./_plugins/redirect.ts"
// Third party Lume plugins
import ci from "https://deno.land/x/lume_plugin_ci@v1.0.0/mod.ts";
// NPM
import rehypePrettyCode from "rehype-pretty-code";
import remarkCallout from "remark-callout";
import prettier from "prettier"
import domain from "top-domain"
import { fromHtmlIsomorphic } from 'hast-util-from-html-isomorphic'
import remarkToc from 'remark-toc'
import rehypeSlug from 'rehype-slug'
import rehypeAutolinkHeadings from 'rehypeAutolinkHeadings'
// Deno
import { crypto } from "jsr:@std/crypto/crypto";
import { join } from "jsr:@std/path";
// Local
import cache_busting from "./_plugins/cache_busting.ts"
import rehypePostImageWrapper from "./_hooks/rehypePostImageWrapper.ts"
import { fnv_1a } from "./_utils/fnv_1a.ts"
const RSS_FILE_NAMES = ["/rss.xml", "/index.xml", "/rss.json", "/blog/rss.xml"];
// Used to toggle on/off certain plugins locally such as cache busting
const mode = Deno.env.get("MODE")
const site = lume({
location: new URL("https://utf9k.net"),
server: {
port: 1313
},
});
const rehypePrettyCodeOpts = {
theme: {
dark: 'rose-pine-moon',
light: 'rose-pine-dawn'
}
}
const rehypeAutolinkHeadingsOpts = {
properties: {
ariaHidden: 'true',
class: 'jumplink',
tabIndex: -1
},
// Fragment is important here so we don't get HTML document tags wrapping our header icon
// In this case, it's only visible in the RSS feed
// Also, the whitespace here is important for alignment!
content: fromHtmlIsomorphic('¶ ', { fragment: true })
}
site.use(date());
site.use(feed({
output: RSS_FILE_NAMES,
query: "category=blog",
info: {
title: "utf9k",
description: "You are online and logged on to my personal site",
lang: "en",
generator: true
},
items: {
title: "=title",
description: "=description",
published: "=date",
content: "=children",
lang: "=lang",
},
}));
site.use(reading_info());
site.use(remark({
remarkPlugins: [
remarkToc,
remarkCallout,
],
rehypePlugins: [
[rehypePrettyCode, rehypePrettyCodeOpts],
rehypeSlug,
rehypePostImageWrapper,
[rehypeAutolinkHeadings, rehypeAutolinkHeadingsOpts]
],
rehypeOptions: {
footnoteLabelProperties: {
className: ['sr-only', 'littlefoot--print']
}
}
}));
site.use(vento());
// site.use(esbuild()); # TODO: Some JS fails to be minified properly
site.use(metas())
site.use(redirect())
site.use(postcss())
site.use(checkUrls())
site.use(sitemap()) // Finds existing robots.txt and inserts sitemap
site.use(ci());
if (mode === "build") {
site.use(cache_busting())
}
// TODO: ESBuild + content hashing
site.copy("js");
site.copy("static", ".");
site.ignore(
"scripts",
".github",
"ci",
"node_modules",
".vale.ini",
"CITATION.cff",
"LICENSE",
"README.md",
"renovate.json",
".DS_Store"
);
// TODO: Try Promise.all(pages.map(fn))
// https://lume.land/docs/advanced/migrate-to-lume2/#change-your-(pre)processors
site.process(
[".html"],
async (pages) => {
for (const page of pages) {
if (page.content !== undefined) {
page.content = await prettier.format(page.content.toString(), { parser: "html", printWidth: 120 })
}
}
}
)
site.filter("taghash", tag => {
const tagColours = [
"lightpink",
"blueviolet",
"fuchsia",
"indigo",
"darkviolet",
"mediumvioletred",
"salmon",
"plum",
"tomato",
"orange",
"darkkhaki",
"royalblue",
"deepskyblue",
"lightseagreen",
"turquoise",
"chocolate",
"brown",
"goldenrod",
"burlywood",
]
const hash = fnv_1a(tag)
const i = Number(hash) % tagColours.length
return tagColours[i]
})
site.filter("getApexDomain", domain)
// Prior versions of the site never used trailing slashes. Functionally, this doesn't matter too much,
// but for RSS readers, the GUID tends to be the URL so having a trailing slash may accidentally
// result in a duplicate feed item appearing if said reader does not trim trailing slashes.
site.addEventListener("afterBuild", (event) => {
event.pages.forEach(async (page) => {
if (
RSS_FILE_NAMES.includes(page.data.url)
) {
const filePath = join("_site", page.data.url);
let content = await Deno.readTextFile(filePath);
if (RSS_FILE_NAMES.includes(page.data.url)) {
content = content.replaceAll(
/\/<\/guid>/g,
"</guid>"
);
}
await Deno.writeTextFile(filePath, content);
}
});
});
if (mode === "build") {
site.process("*", async (filteredPages, allPages) => {
let pageContent = ``
const sortedPages = allPages.sort((a, b) => a.data.url.localeCompare(b.data.url))
for (const page of sortedPages) {
if (page.data.url === "/") {
// Homepage contains some dynamic content so we remove it
// to ensure digest only changes when content changes
continue
}
const encoder = new TextEncoder()
const data = encoder.encode(page.content);
const hashBuffer = await crypto.subtle.digest("SHA-1", data);
const hashArray = Array.from(new Uint8Array(hashBuffer))
const hashHex = hashArray
.map(b => b.toString(16)
.padStart(2, "0"))
.join("")
pageContent += `${hashHex} ${page.data.url}\n`
}
const hashPage = Page.create({
url: `/digest.txt`,
content: pageContent
})
allPages.push(hashPage)
})
}
export default site;