-
Notifications
You must be signed in to change notification settings - Fork 77
/
.eleventy.js
82 lines (76 loc) · 2.24 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
const CleanCSS = require('clean-css');
const eleventyNavigationPlugin = require("@11ty/eleventy-navigation");
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const pluginTOC = require('eleventy-plugin-nesting-toc');
const imageOptimizations = require('./_11ty/image-dimensions.js');
module.exports = function(config) {
config.addPassthroughCopy('src/img');
config.addPassthroughCopy('src/manifest.json');
config.addPlugin(pluginTOC, {tags: ['h2', 'h3', 'h4']});
config.addPlugin(syntaxHighlight);
config.addPlugin(imageOptimizations);
config.addPlugin(eleventyNavigationPlugin);
config.addFilter('cssmin', function(code) {
return new CleanCSS({}).minify(code).styles;
});
const { minify } = require("terser");
config.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);
}
});
let markdownIt = require("markdown-it");
const markdownItAnchor = require('markdown-it-anchor');
const markdownItAttrs = require('markdown-it-attrs');
const markdownItDefList = require("markdown-it-deflist");
const markdownItContainer = require("markdown-it-container");
let options = {
html: true,
linkify: true,
breaks: true
};
let markdownLib = markdownIt(options)
.use(markdownItAnchor)
.use(markdownItAttrs, {
leftDelimiter: '{:',
rightDelimiter: '}',
})
.use(markdownItContainer,'', {
validate: () => true,
render: (tokens, idx) => {
if (tokens[idx].nesting === 1) {
const classList = tokens[idx].info.trim()
return `<div ${classList && `class="${classList}"`}>`;
} else {
return `</div>`;
}
}
});
config.addNunjucksAsyncFilter('markdown', async function (
code,
callback
) {
try {
console.log(code);
const converted = markdownLib.render(code);
callback(null, converted);
} catch (err) {
console.error("Terser error: ", err);
// Fail gracefully.
callback(null, code);
}
});
config.setLibrary("md", markdownLib);
return {
dir: { input: './src', output: 'dist', includes: '_includes', data: '_data' },
passthroughFileCopy: true
};
};