-
Notifications
You must be signed in to change notification settings - Fork 11
/
.eleventy.js
65 lines (53 loc) · 1.39 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
const htmlmin = require("html-minifier")
const markdownIt = require("markdown-it")
const anchors = require('markdown-it-anchor')
const date = Date.now()
function getFromManifest(name) {
try {
const assets = require("./_site/mix-manifest.json")
if (name[0] !== '/') {
name = '/' + name
}
return assets[name] || name + '?id=' + date
} catch (error) {
return name + '?id=' + date
}
}
module.exports = function (eleventyConfig) {
eleventyConfig.addPassthroughCopy({ "docs/_public": '/' })
/**
* Add the asset shortcode to fetch an asset name from mix-manifest.json
*
* @example {% asset 'css/style.css' %}
*/
eleventyConfig.addShortcode("asset", function (name) {
return getFromManifest(name)
});
eleventyConfig.addTransform("htmlmin", function(content, outputPath) {
if (outputPath && outputPath.endsWith(".html")) {
return htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
minifyJS: true,
collapseWhitespace: true
});
}
return content;
});
eleventyConfig.addFilter('stringify', (value) => {
return JSON.stringify(value)
})
let markdownLibrary = markdownIt({
html: true
})
.use(anchors, {
tabIndex: false
});
eleventyConfig.setLibrary("md", markdownLibrary);
return {
dir: { input: 'docs', data: '_data' },
passthroughFileCopy: true,
templateFormats: ['njk', 'md', 'html'],
htmlTemplateEngine: 'njk'
}
};