2023-07-23 16:04:28 -04:00
|
|
|
import lume from "lume/mod.ts";
|
|
|
|
import jsx from "lume/plugins/jsx.ts";
|
|
|
|
import nav from "lume/plugins/nav.ts";
|
|
|
|
import sass from "lume/plugins/sass.ts";
|
2023-08-05 20:13:10 -04:00
|
|
|
import feed from "lume/plugins/feed.ts";
|
2023-11-29 14:55:46 -05:00
|
|
|
import code_highlight from "lume/plugins/code_highlight.ts";
|
2024-09-06 11:05:02 -04:00
|
|
|
import toc from "lume-markdown-plugins/toc.ts";
|
|
|
|
import footnotes from "lume-markdown-plugins/footnotes.ts";
|
2023-11-29 14:55:46 -05:00
|
|
|
|
|
|
|
import lang_typescript from "npm:highlight.js/lib/languages/typescript";
|
|
|
|
import lang_javascript from "npm:highlight.js/lib/languages/javascript";
|
|
|
|
import lang_bash from "npm:highlight.js/lib/languages/bash";
|
2023-07-23 16:04:28 -04:00
|
|
|
|
2024-09-14 08:03:30 -04:00
|
|
|
import { deflateSync } from "node:zlib";
|
|
|
|
|
|
|
|
const textEncoder = new TextEncoder();
|
|
|
|
|
2023-07-23 16:04:28 -04:00
|
|
|
const site = lume({
|
2024-09-10 07:01:50 -04:00
|
|
|
src: "./src",
|
2023-08-05 20:13:10 -04:00
|
|
|
location: new URL("https://www.fosterhangdaan.com/"),
|
2023-07-23 16:04:28 -04:00
|
|
|
});
|
|
|
|
|
2023-10-02 19:41:35 -04:00
|
|
|
site.ignore("README.md", "README.org", "LICENSE.txt", "LICENSE.md");
|
2023-07-23 16:21:17 -04:00
|
|
|
|
2024-09-10 07:30:23 -04:00
|
|
|
site.copy("static", ".");
|
2023-07-27 22:51:48 -04:00
|
|
|
|
2024-09-10 08:18:00 -04:00
|
|
|
site.copy([
|
|
|
|
".avif",
|
|
|
|
".jpeg",
|
|
|
|
".jpg",
|
|
|
|
".png",
|
|
|
|
".webp",
|
|
|
|
]);
|
2023-11-28 16:19:58 -05:00
|
|
|
|
2023-07-23 16:04:28 -04:00
|
|
|
site.use(jsx());
|
|
|
|
site.use(nav());
|
|
|
|
site.use(sass());
|
2023-08-05 20:13:10 -04:00
|
|
|
site.use(feed({
|
|
|
|
query: "type=post",
|
|
|
|
output: [
|
|
|
|
"/blog/feed.rss",
|
|
|
|
"/blog/feed.json",
|
|
|
|
],
|
|
|
|
info: {
|
|
|
|
title: "Foster Hangdaan's Blog",
|
|
|
|
description: "My thoughts and ideas.",
|
2023-12-09 10:45:00 -05:00
|
|
|
published: new Date(),
|
2023-08-06 16:45:45 -04:00
|
|
|
lang: "en",
|
2023-08-05 20:13:10 -04:00
|
|
|
},
|
|
|
|
items: {
|
|
|
|
title: "=title",
|
|
|
|
description: "=description",
|
2023-12-09 10:45:00 -05:00
|
|
|
published: "=date",
|
|
|
|
updated: "=updated",
|
2024-03-05 18:38:42 -05:00
|
|
|
},
|
2023-08-05 20:13:10 -04:00
|
|
|
}));
|
2023-11-29 14:55:46 -05:00
|
|
|
site.use(code_highlight({
|
|
|
|
languages: {
|
|
|
|
typescript: lang_typescript,
|
|
|
|
javascript: lang_javascript,
|
|
|
|
bash: lang_bash,
|
2024-03-05 18:38:42 -05:00
|
|
|
},
|
2024-09-14 08:01:55 -04:00
|
|
|
options: {
|
|
|
|
noHighlightRe: /^no-highlight$/i,
|
|
|
|
languageDetectRe: /\blanguage-([\w-]+)\b/i,
|
|
|
|
classPrefix: "hljs-",
|
|
|
|
cssSelector: "pre code",
|
|
|
|
},
|
2023-11-29 14:55:46 -05:00
|
|
|
}));
|
2023-12-03 10:57:42 -05:00
|
|
|
site.use(toc({
|
|
|
|
slugify: {
|
|
|
|
separator: "-",
|
|
|
|
lowercase: true,
|
|
|
|
},
|
|
|
|
}));
|
2023-12-03 13:11:01 -05:00
|
|
|
site.use(footnotes());
|
2023-07-23 16:04:28 -04:00
|
|
|
|
2023-12-09 10:45:00 -05:00
|
|
|
site.process([".html"], (pages) => {
|
|
|
|
pages.forEach((page) => {
|
2024-09-06 11:05:02 -04:00
|
|
|
if (page.document) {
|
2024-09-14 08:29:15 -04:00
|
|
|
// NOTE: This is a hack to append a class to JS doctrings so that we
|
|
|
|
// can style them. If only the Hightlight.js plugin could be configured
|
|
|
|
// to do this instead.
|
2024-09-06 11:05:02 -04:00
|
|
|
for (
|
|
|
|
const codeCommentElement of page.document.getElementsByClassName(
|
|
|
|
"hljs-comment",
|
|
|
|
)
|
|
|
|
) {
|
2024-03-05 18:38:42 -05:00
|
|
|
const docStringRegex = /^\/\*\*.*\*\/$/gsm;
|
2024-09-06 11:05:02 -04:00
|
|
|
const matchResult = codeCommentElement.textContent?.match(
|
|
|
|
docStringRegex,
|
|
|
|
);
|
2024-03-05 18:38:42 -05:00
|
|
|
if (matchResult) {
|
|
|
|
codeCommentElement.classList.add("docstring");
|
|
|
|
}
|
2024-09-06 11:05:02 -04:00
|
|
|
}
|
2024-09-14 08:03:30 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert Plantuml code to images using Kroki.
|
|
|
|
*/
|
|
|
|
const diagrams = page.document.getElementsByClassName(
|
|
|
|
"language-plantuml",
|
|
|
|
);
|
|
|
|
if (diagrams.length > 0) {
|
|
|
|
for (const diagram of diagrams) {
|
|
|
|
if (diagram.textContent && diagram.parentElement) {
|
|
|
|
const encoded = textEncoder.encode(diagram.textContent);
|
|
|
|
const compressed = deflateSync(encoded);
|
|
|
|
const result = compressed.toString("base64url");
|
|
|
|
const img = page.document.createElement("img");
|
|
|
|
const url = new URL(
|
|
|
|
`https://kroki.fosterhangdaan.com/plantuml/svg/${result}`,
|
|
|
|
);
|
|
|
|
img.setAttribute("src", url.toString());
|
|
|
|
diagram.parentElement.replaceWith(img);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-09-06 11:05:02 -04:00
|
|
|
}
|
2023-12-05 10:36:20 -05:00
|
|
|
});
|
2023-12-05 10:22:49 -05:00
|
|
|
});
|
|
|
|
|
2023-07-23 16:04:28 -04:00
|
|
|
export default site;
|