-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
.eleventy.js
93 lines (87 loc) · 3.61 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const markdownIt = require("markdown-it");
const markdownItTocAndAnchor = require("markdown-it-toc-and-anchor").default; // the .default is essential: https://github.com/medfreeman/markdown-it-toc-and-anchor#readme
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const pluginRss = require("@11ty/eleventy-plugin-rss");
const CleanCSS = require("clean-css");
const { minify } = require("terser");
module.exports = function (eleventyConfig) {
try {
eleventyConfig.addWatchTarget("./src/sass/");
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPassthroughCopy("assets");
eleventyConfig.addPassthroughCopy("./src/**/*.jpg");
eleventyConfig.addPassthroughCopy("./src/**/*.png");
eleventyConfig.addPassthroughCopy("./src/**/*.gif");
eleventyConfig.addPassthroughCopy("./src/**/*.webp");
eleventyConfig.addPassthroughCopy("./src/**/*.mp4");
eleventyConfig.addPassthroughCopy("./src/**/*.pdf");
eleventyConfig.addPassthroughCopy("./src/**/*.mmd");
eleventyConfig.addPassthroughCopy("./src/**/*.xml");
eleventyConfig.addPassthroughCopy("./src/**/*.xslx");
eleventyConfig.addPassthroughCopy("./src/stories/**/bookend.json");
// add support for syntax highlighting
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.addFilter("cssmin", function (code) {
return new CleanCSS({}).minify(code).styles;
});
const highlighter = eleventyConfig.markdownHighlighter;
eleventyConfig.addMarkdownHighlighter((str, language) => {
if (language === "mermaid") {
return `<pre class="mermaid jace-was-here">${str}</pre>`;
}
return highlighter(str, language);
});
eleventyConfig.addNunjucksAsyncFilter("jsmin", async function (
code,
callback
) {
try {
const minified = await minify(code);
callback(null, minified.code);
} catch (err) {
console.error("Terser error: ", err);
// Fail gracefully.
callback(null, code);
}
});
eleventyConfig.addPairedShortcode('details', function (content, title) {
let detailstag = 'details';
let summarystyle = arguments['2'];
let attributes = arguments['3'];
if (attributes) {
detailstag += ' ' + attributes;
}
return `<${detailstag}><summary style="${summarystyle}"><span>${title}</span></summary>${content}</details>`;
});
eleventyConfig.addFilter("formatDate", function(value) {
var d = new Date(value).toLocaleString("en-CA");
d = d.replace(',','');
d = d.replace(/\./g,'');
return d;
});
let markdownLibrary = markdownIt({ // add IDs to headings with links inside. Perfect!
html: true,
breaks: true,
linkify: true
}).use(markdownItTocAndAnchor, {
tocClassName: null,
tocFirstLevel: 2,
anchorClassName: null,
wrapHeadingTextInAnchor: true
});
eleventyConfig.setLibrary("md", markdownLibrary);
} catch (e) {
//console.log('ERROR', e);
}
return {
addPassthroughCopy: true,
markdownTemplateEngine: "njk",
templateFormats: ["njk", "md"],
dir: {
input: "./src", // html and layouts for project
output: "./_site",
include: "./includes",
data: "./_data",
}
}
}