/
.eleventy.js
78 lines (66 loc) · 2.82 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Setup Packages
const pluginRss = require("@11ty/eleventy-plugin-rss");
const CleanCSS = require("clean-css");
const markdownIt = require("markdown-it");
const markdownItContainer = require("markdown-it-container");
const markdownItFootnote = require("markdown-it-footnote");
module.exports = function(eleventyConfig) {
//Passthrough Copy Files
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPassthroughCopy('./src/img/');
eleventyConfig.addPassthroughCopy('./src/.htaccess');
eleventyConfig.addPassthroughCopy('./src/humans.txt');
eleventyConfig.addPassthroughCopy('./src/robots.txt');
eleventyConfig.addPassthroughCopy('./src/keybase.txt');
// Add CleanCSS and Minify
eleventyConfig.addFilter("cssmin", function(code) {
return new CleanCSS({}).minify(code).styles;
});
// Define Markdown-it lib; allow code indentation by not parsing indention as code elements
let markdownLibrary = markdownIt({ // docs: https://www.npmjs.com/package/markdown-it
html: true,
typographer: true,
}).disable('code')
// Markdown-it footnote plugin
.use(markdownItFootnote)
// Markdown-it container plugin
.use( require('markdown-it-container'), '', { // Can add wrapping containers with IDs and Classes, and nest them - docs: https://github.com/markdown-it/markdown-it-container - and some help via: https://ryan.thaut.me/blog/2020/04/25/flirting-with-eleventy-11ty/
validate: () => true,
render: (tokens, idx) => {
if (tokens[idx].nesting === 1) {
const classList = tokens[idx].info.trim()
return `<div ${classList && `class="${classList}"`}>`;
} else {
return `</div>`;
}
}
});
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.setLibrary("md", markdownLibrary);
// Move footnotes via: Moving the Footnotes on Eleventy - Scott Watermasysk - https://scottw.com/articles/moving_the_footnotes_on_eleventy/ → https://web.archive.org/web/20230603165523/https://scottw.com/articles/moving_the_footnotes_on_eleventy/
eleventyConfig.addTransform("move-footnotes", (content, outputPath) => {
if (outputPath && outputPath.endsWith(".html")) {
const footnoteRegex = /(<hr class="footnotes-sep">\n<section class="footnotes">[\s\S]+<\/section>)/m;
const newFootnoteLocationRegex = /<!--FOOTNOTES-->/;
let newLocation = content.match(newFootnoteLocationRegex);
let footnote = content.match(footnoteRegex);
if (newLocation && footnote) {
return content
.replace(footnoteRegex, "")
.replace(newFootnoteLocationRegex, footnote[0]);
}
}
return content;
});
// Template Config
return {
markdownTemplateEngine: 'njk',
dataTemplateEngine: 'njk',
htmlTemplateEngine: 'njk',
// Set Input and Output
dir: {
input: 'src',
output: '_site'
}
};
};