full site update

This commit is contained in:
2025-07-24 18:46:24 +02:00
parent bfe2b90d8d
commit 37a6e0ab31
6912 changed files with 540482 additions and 361712 deletions

View File

@@ -0,0 +1,58 @@
import yaml from "js-yaml";
import * as toml from "smol-toml";
function isFrontmatterValid(frontmatter) {
try {
JSON.stringify(frontmatter);
} catch {
return false;
}
return typeof frontmatter === "object" && frontmatter !== null;
}
const frontmatterRE = /(?:^\uFEFF?|^\s*\n)(?:---|\+\+\+)([\s\S]*?\n)(?:---|\+\+\+)/;
const frontmatterTypeRE = /(?:^\uFEFF?|^\s*\n)(---|\+\+\+)/;
function extractFrontmatter(code) {
return frontmatterRE.exec(code)?.[1];
}
function getFrontmatterParser(code) {
return frontmatterTypeRE.exec(code)?.[1] === "+++" ? ["+++", toml.parse] : ["---", yaml.load];
}
function parseFrontmatter(code, options) {
const rawFrontmatter = extractFrontmatter(code);
if (rawFrontmatter == null) {
return { frontmatter: {}, rawFrontmatter: "", content: code };
}
const [delims, parser] = getFrontmatterParser(code);
const parsed = parser(rawFrontmatter);
const frontmatter = parsed && typeof parsed === "object" ? parsed : {};
let content;
switch (options?.frontmatter ?? "remove") {
case "preserve":
content = code;
break;
case "remove":
content = code.replace(`${delims}${rawFrontmatter}${delims}`, "");
break;
case "empty-with-spaces":
content = code.replace(
`${delims}${rawFrontmatter}${delims}`,
` ${rawFrontmatter.replace(/[^\r\n]/g, " ")} `
);
break;
case "empty-with-lines":
content = code.replace(
`${delims}${rawFrontmatter}${delims}`,
rawFrontmatter.replace(/[^\r\n]/g, "")
);
break;
}
return {
frontmatter,
rawFrontmatter,
content
};
}
export {
extractFrontmatter,
isFrontmatterValid,
parseFrontmatter
};