Install Kroki plugin

This commit is contained in:
Foster Hangdaan 2024-11-08 17:02:47 -05:00
parent e0f959e6bf
commit 89efa55861
Signed by: foster
GPG key ID: E48D7F49A852F112
3 changed files with 5 additions and 27 deletions

View file

@ -6,15 +6,12 @@ import feed from "lume/plugins/feed.ts";
import code_highlight from "lume/plugins/code_highlight.ts";
import toc from "lume-markdown-plugins/toc.ts";
import footnotes from "lume-markdown-plugins/footnotes.ts";
import kroki from "https://code.fosterhangdaan.com/foster/lume-plugin-kroki/raw/tag/v1.0.0/mod.ts";
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";
import { deflateSync } from "node:zlib";
const textEncoder = new TextEncoder();
const site = lume({
src: "./src",
location: new URL("https://www.fosterhangdaan.com/"),
@ -78,6 +75,9 @@ site.use(toc({
},
}));
site.use(footnotes());
site.use(kroki({
server: "https://kroki.fosterhangdaan.com",
}));
site.process([".html"], (pages) => {
pages.forEach((page) => {
@ -98,28 +98,6 @@ site.process([".html"], (pages) => {
codeCommentElement.classList.add("docstring");
}
}
/**
* 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);
}
}
}
}
});
});

View file

@ -10,7 +10,7 @@
"tasks": {
"build": "deno run --allow-write='.' --allow-read='.' --allow-net='deno.land,cdn.deno.land,esm.sh,0.0.0.0:3000,jsr.io,lumeland.github.io' --allow-sys=networkInterfaces --allow-env='LUME_ENV,LUME_LIVE_RELOAD,LUME_LOGS,LUME_NOCACHE,LUME_DRAFTS,NODE_ENV,SASS_PATH' lume.ts",
"check": "deno fmt --check && deno lint && deno check .",
"serve": "deno run --allow-write='.' --allow-read='.' --allow-net='deno.land,cdn.deno.land,esm.sh,0.0.0.0:3000,jsr.io,lumeland.github.io' --allow-sys=networkInterfaces --allow-env='LUME_ENV,LUME_LIVE_RELOAD,LUME_LOGS,LUME_NOCACHE,LUME_DRAFTS,NODE_ENV,SASS_PATH' lume.ts -s",
"serve": "deno run --allow-write='.' --allow-read='.' --allow-net='deno.land,cdn.deno.land,esm.sh,0.0.0.0:3000,jsr.io,lumeland.github.io,code.fosterhangdaan.com' --allow-sys=networkInterfaces --allow-env='LUME_ENV,LUME_LIVE_RELOAD,LUME_LOGS,LUME_NOCACHE,LUME_DRAFTS,NODE_ENV,SASS_PATH' lume.ts -s",
"deploy": "rsync -avh --progress --delete ./_site/ podman:/srv/www/fosterhangdaan.com/"
},
"imports": {

BIN
deno.lock

Binary file not shown.