-
Notifications
You must be signed in to change notification settings - Fork 105
/
eleventy.config.js
74 lines (60 loc) · 1.84 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
69
70
71
72
73
74
const _ = require('lodash');
const { renderer } = require('./lib/markdown');
function getPageTitles(collections) {
const pageTitles = {};
collections.all.forEach((item) => {
let title;
if (item.data.tag) {
if (collections.inlineTags.includes(item)) {
title = `{@${item.data.tag}}`;
} else {
title = `@${item.data.tag}`;
}
} else if (item.data.title) {
title = item.data.title;
}
pageTitles[item.page.filePathStem] = title;
});
return pageTitles;
}
const memoizedGetPageTitles = _.memoize(getPageTitles);
function sortBy(items, key) {
return _.sortBy(items, (item) => _.get(item, key));
}
module.exports = (eleventyConfig) => {
eleventyConfig.addFilter('keys', (value) => Object.keys(value));
eleventyConfig.addFilter('relatedList', (related, collections) => {
const pageTitles = memoizedGetPageTitles(collections);
const relatedList = related.map((path) => {
return {
title: pageTitles[path],
path,
};
});
return sortBy(relatedList, 'title');
});
eleventyConfig.addFilter('sortTags', (value) => {
return sortBy(value, 'data.tag');
});
// Use `layout.njk` as the default layout.
eleventyConfig.addGlobalData('layout', 'layout.njk');
// Use `/foo.html` as the output filename rather than `/foo/index.html`.
eleventyConfig.addGlobalData('permalink', () => {
return (data) => `${data.page.filePathStem}.${data.page.outputFileExtension}`;
});
eleventyConfig.addPassthroughCopy('./images');
eleventyConfig.addPassthroughCopy('./styles');
eleventyConfig.setLibrary('md', renderer());
eleventyConfig.setNunjucksEnvironmentOptions({
throwOnUndefined: true,
});
return {
dir: {
data: 'data',
includes: 'includes',
input: 'content',
output: '_site',
},
markdownTemplateEngine: 'njk',
};
};