const fs = require("fs"); const hljs = require("highlight.js"); const twemoji = require("twemoji"); const { DateTime } = require("luxon"); const utils = require("markdown-it/lib/common/utils"); const excerptMinimumLength = 280; const excerptSeparator = ""; const twemojiOpts = { base: "https://cdnjs.cloudflare.com/ajax/libs/twemoji/15.1.0/", }; function extractExcerpt(doc) { if (doc.data.readOnline) return "[[ No Excerpt Available ]]"; if (doc.data.excerpt) return doc.data.excerpt; if (!doc.hasOwnProperty("templateContent")) { console.warn("Failed to extract excerpt: Document has no property `templateContent`."); return ""; } const content = doc.templateContent; if (content.includes(excerptSeparator)) return content.substring(0, content.indexOf(excerptSeparator)).trim(); else if (content.length <= excerptMinimumLength) return content.trim(); const excerptEnd = findExcerptEnd(content); return content.substring(0, excerptEnd).trim(); } function findExcerptEnd(content, skipLength = 0) { if (content === "") return 0; const paragraphEnd = content.indexOf("
", skipLength) + 4; return paragraphEnd + ((paragraphEnd < excerptMinimumLength)? findExcerptEnd(content.substring(paragraphEnd), paragraphEnd):0); } function demark(content) { return content.replace(/(.*?)<\/mark>/gis, (m,a) => "█".repeat(a.length)) } module.exports = (cfg) => { cfg.addPlugin(require("@11ty/eleventy-plugin-rss")); cfg.addFilter("excerpt", post => extractExcerpt(post)); cfg.addFilter("demark", content => demark(content)); cfg.addFilter("date", (date, fmt) => DateTime.fromJSDate(date).toFormat(fmt)); cfg.addPassthroughCopy({"static": "./"}); cfg.setDataDeepMerge(true); cfg.addFilter("fixAnchors", (c,u) => c.replace(/ { let starting = 1; let numLength; if (lang.includes(":")) { lang = lang.split(":"); starting = lang[1]; numLength = lang[2]; lang = lang[0]; } if (lang && hljs.getLanguage(lang)) { try { return '' +
hljs.highlight(str, { language: lang, ignoreIllegals: true }).value +
'
';
} catch (__) {} }
return '' + md.utils.escapeHtml(str) + '
';
}
}).use(require("markdown-it-anchor"), {
permalink: true, permalinkBefore: true, permalinkSymbol: "#"})
.use(require("markdown-it-emoji"), {shortcuts: {}})
.use(require("markdown-it-footnote"))
.use(require("markdown-it-mark"));
md.renderer.rules.emoji = (token, i) =>
`${twemoji.parse(token[i].content, twemojiOpts)}`;
md.renderer.rules.code_block = (tokens, i, options, env, slf) =>
`` +
utils.escapeHtml(tokens[i].content.replace(/ /g, "\xA0"))+'
\n';
md.renderer.rules.footnote_block_open = () => (
'