-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheleventy.config.js
More file actions
78 lines (65 loc) · 2.01 KB
/
eleventy.config.js
File metadata and controls
78 lines (65 loc) · 2.01 KB
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
const path = require('path');
const {calcFileHash} = require('./src/_utils/file');
const {bustCacheForUrl} = require('./src/_utils/url');
module.exports = eleventyConfig => {
eleventyConfig.addPassthroughCopy('src/!(_copy|_data|_includes|_layouts|_js|_styles|_utils)/**/*.{png,gif,jpg,svg}');
eleventyConfig.setServerOptions({
liveReload: true,
domDiff: true,
port: 8080,
watch: [],
showAllHosts: false,
https: {
// key: './localhost.key',
// cert: './localhost.cert',
},
encoding: 'utf-8',
showVersion: false,
});
const markdownIt = require('markdown-it');
const markdownItAnchor = require('markdown-it-anchor')
const mdOptions = {
html: true,
breaks: true,
linkify: true
};
eleventyConfig.setLibrary('md', markdownIt(mdOptions).use(markdownItAnchor));
const hashCache = {};
eleventyConfig.addFilter('bust', function (url) { // no arrow func here
const [urlPath] = url.split('?');
const filePath = path.join('build', urlPath);
if(!hashCache[filePath]) {
hashCache[filePath] = calcFileHash(filePath);
}
return bustCacheForUrl(url, hashCache[filePath]);
});
eleventyConfig.addFilter('mdFilter', function (content) {
const md = new markdownIt({
html: true
});
return md.render(content);
});
eleventyConfig.addFilter('excerpt', function (content, words) {
const arr = content.split(' ');
const newArr = arr.slice(0, words);
return newArr.join(' ') + (newArr.length<arr.length ? '...' : '')
});
const pluginTOC = require('eleventy-plugin-toc')
eleventyConfig.addPlugin(pluginTOC, {
ul: true
})
const { eleventyImageTransformPlugin } = require("@11ty/eleventy-img");
eleventyConfig.addPlugin(eleventyImageTransformPlugin);
return {
dir: {
input: 'src',
data: '_data',
includes: '_includes',
layouts: '_layouts',
output: 'build'
},
templateFormats: ['njk', 'html', 'md'],
markdownTemplateEngine: 'njk',
htmlTemplateEngine: 'njk'
}
}