forked from oddbird/css-sandbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.eleventy.js
More file actions
92 lines (79 loc) · 2.57 KB
/
Copy path.eleventy.js
File metadata and controls
92 lines (79 loc) · 2.57 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const nav = require('@11ty/eleventy-navigation');
const hljs = require('@11ty/eleventy-plugin-syntaxhighlight');
const pluginRss = require("@11ty/eleventy-plugin-rss");
const toc = require('eleventy-plugin-toc');
const yaml = require('js-yaml');
const _ = require('lodash');
const type = require('./filters/type');
const getChangelog = (collection) => {
return _.flatMap(
_.filter(collection, 'data.changes'),
(page) => {
const pageData = _.get(page, 'data.changes');
return pageData.map((change) => {
const date = new Date(change.time);
change.date = date.toLocaleDateString('en-US');
change.url = page.url;
change.source = page.data.title;
return change;
})
}
).sort((a, b) => b.time - a.time);
};
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(hljs);
eleventyConfig.addPlugin(nav);
eleventyConfig.addPlugin(toc);
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addWatchTarget('./src/sass/');
eleventyConfig.addPassthroughCopy('./src/css');
eleventyConfig.addPassthroughCopy('./src/favicon.svg');
// filters
eleventyConfig.addFilter('amp', type.amp);
eleventyConfig.addFilter('typogr', type.set);
eleventyConfig.addFilter('md', type.render);
eleventyConfig.addFilter('mdInline', type.inline);
eleventyConfig.addFilter('getChangelog', getChangelog);
// config
eleventyConfig.setLibrary('md', type.mdown);
eleventyConfig.addDataExtension('yaml', yaml.safeLoad);
eleventyConfig.setQuietMode(true);
eleventyConfig.setDataDeepMerge(true);
// shortcodes
eleventyConfig.addPairedShortcode('md', type.render);
eleventyConfig.addPairedShortcode('mdInline', type.inline);
eleventyConfig.addPairedShortcode('typogr', type.set);
eleventyConfig.addCollection("changes", function(collectionApi) {
const all = collectionApi.getAll();
const changes = [];
all.forEach((post) => {
if (post.data.changes) {
post.data.changes
.sort((a, b) => b.time - a.time)
.forEach((change, i) => {
changes.push({
post,
date: change.time,
log: change.log,
latest: i === 0,
});
});
}
changes.push({
post,
date: post.data.created || post.date,
log: 'New page added',
latest: post.data.changes ? false : true,
});
});
return changes.sort((a, b) => b.date - a.date);
});
return {
markdownTemplateEngine: 'njk',
dir: {
input: 'src',
output: 'public',
layouts: '_layouts',
},
};
};