-
Notifications
You must be signed in to change notification settings - Fork 0
/
eleventy.config.js
68 lines (58 loc) · 1.93 KB
/
eleventy.config.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
// Plugins
const cacheBuster = require('@mightyplow/eleventy-plugin-cache-buster');
const htmlmin = require('html-minifier');
const filtersDates = require('./src/filters/dates.js');
const filtersTimestamp = require('./src/filters/timestamp.js');
// Toggle minification of HTML code
const minifyHtml = false;
module.exports = (config) => {
// Cache buster plugin
const cacheBusterOptions = {
outputDirectory: 'build',
createResourceHash(outputDirectoy, url, target) {
return Date.now();
}
};
config.addPlugin(cacheBuster(cacheBusterOptions));
// Add a readable date formatter filter to Nunjucks
config.addFilter('dateDisplay', filtersDates);
// Add a HTML timestamp formatter filter to Nunjucks
config.addFilter('htmlDateDisplay', filtersTimestamp);
// Minify our HTML
config.addTransform('htmlmin', (content, outputPath) => {
if (minifyHtml && outputPath.endsWith('.html')) {
const minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true
});
return minified;
}
return content;
});
// Collections
config.addCollection('blog', collection => (
collection.getFilteredByTag('blog').reverse()
));
// Layout aliases
config.addLayoutAlias('default', 'layouts/default.njk');
config.addLayoutAlias('post', 'layouts/post.njk');
// Include our static assets
config.addPassthroughCopy('src/site/images');
config.addPassthroughCopy({ 'src/site/temp/css': 'css' });
config.addPassthroughCopy({ 'src/site/temp/js': 'js' });
// Want to use selfhosted fonts? Uncomment the following line:
//config.addPassthroughCopy('src/site/fonts');
return {
dir: {
input: 'src/site',
output: 'build',
includes: 'includes',
data: 'data'
},
htmlTemplateEngine: 'njk',
markdownTemplateEngine: 'njk',
templateFormats: ['md', 'njk', 'txt'],
passthroughFileCopy: true
};
};