-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheleventy.config.js
41 lines (34 loc) · 1.17 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
const pug = require('pug');
module.exports = function(eleventyConfig, userOptions = {}) {
const basePugOptions = Object.assign({
basedir: eleventyConfig.dir.input,
cache: false,
filters: eleventyConfig.javascriptFunctions
}, userOptions.pugOptions);
eleventyConfig.addTemplateFormats('pug');
eleventyConfig.addExtension('pug', {
compileOptions: {
permalink(inputContent, inputPath) {
return function(data) {
return data.permalink
}
}
},
async compile(inputContent, inputPath) {
if (typeof userOptions.filter === 'function' && !userOptions.filter(inputContent, inputPath)) {
return;
}
const compileOptions = Object.assign(basePugOptions, { filename: inputPath });
const renderFunction = pug.compile(inputContent, compileOptions);
this.addDependencies(inputPath, renderFunction.dependencies);
return function(data) {
const functions = {};
for(const [name, func] of Object.entries(eleventyConfig.javascriptFunctions)) {
functions[name] = func.bind(data);
}
data.functions = functions;
return renderFunction(data);
}
}
});
}