-
Notifications
You must be signed in to change notification settings - Fork 25
/
.eleventy.js
62 lines (52 loc) · 1.67 KB
/
.eleventy.js
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
const fs = require("fs");
const path = require("path");
const markdownIt = require("markdown-it");
const markdownItAnchor = require("markdown-it-anchor");
const markdownItLinkAttributes = require("markdown-it-link-attributes");
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const tableOfContents = require("eleventy-plugin-toc");
const katex = require("katex");
const yaml = require("js-yaml");
module.exports = function (eleventyConfig) {
// This will copy these folders to the output without modifying them at all
eleventyConfig.addPassthroughCopy("js");
eleventyConfig.addPassthroughCopy("img");
eleventyConfig.addPassthroughCopy("css");
eleventyConfig.addPassthroughCopy("_redirects");
// handle LaTeX
eleventyConfig.addFilter("latex", (content) => {
return content.replace(/\$\$(.+?)\$\$/g, (_, equation) => {
const cleanEquation = equation
.replace(/</g, "<")
.replace(/>/g, ">");
return katex.renderToString(cleanEquation, { throwOnError: true });
});
});
// add markdown header anchors and a table of contents
let markdown = markdownIt({
html: true,
breaks: true,
linkify: true,
})
.use(markdownItAnchor)
.use(markdownItLinkAttributes, [
{
pattern: /^(?!(\/|#)).*$/gm,
attrs: {
target: "_blank",
rel: "noopener",
},
},
]);
eleventyConfig.setLibrary("md", markdown);
// enable plugins
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.addPlugin(tableOfContents);
return {
markdownTemplateEngine: "njk",
jsDataFileSuffix: ".data",
dir: {
layouts: "_includes/layouts",
},
};
};