-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
47 lines (40 loc) · 1.25 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
const fs = require("fs")
const path = require("path")
const htmlmin = require('html-minifier')
const manifestPath = path.resolve(__dirname, "dist", "static", "manifest.json");
const manifest = JSON.parse(
fs.readFileSync(manifestPath, { encoding: "utf8" })
);
module.exports = function(eleventyConfig) {
eleventyConfig.addLayoutAlias("default", "layouts/default.njk");
eleventyConfig.addLayoutAlias("page", "layouts/page.njk");
eleventyConfig.addShortcode("static", function(name) {
if (!manifest[name]) {
throw new Error(`The asset ${name} does not exist in ${manifestPath}`);
}
return manifest[name];
});
eleventyConfig.setDynamicPermalinks(false);
eleventyConfig.setBrowserSyncConfig({ files: [manifestPath] });
eleventyConfig.addTransform("htmlmin", function(content, outputPath) {
if( outputPath.endsWith(".html") ) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true
})
return minified
}
return content
})
return {
dir: {
input: "src/site",
includes: "_includes",
output: "dist",
},
htmlTemplateEngine: "njk",
markdownTemplateEngine: "njk",
passthroughFileCopy: true,
};
};