generated from 5t3ph/11ty-sass-skeleton
-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
.eleventy.js
101 lines (86 loc) · 2.86 KB
/
.eleventy.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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 ghSlug = require('github-slugger').slug;
const time = require('./filters/time');
const type = require('./filters/type');
const get = require('./filters/get');
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(hljs);
eleventyConfig.addPlugin(nav);
eleventyConfig.addPlugin(toc);
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(get);
eleventyConfig.addWatchTarget('./src/styles/');
eleventyConfig.addPassthroughCopy('./src/css');
eleventyConfig.addPassthroughCopy("./src/**/*.svg");
// filters
eleventyConfig.addFilter('amp', type.amp);
eleventyConfig.addFilter('typogr', type.set);
eleventyConfig.addFilter('md', type.render);
eleventyConfig.addFilter('mdInline', type.inline);
eleventyConfig.addFilter('date', time.date);
// Get the first `n` elements of a collection.
eleventyConfig.addFilter('slice', (array, n) => {
if (n < 0) {
return array.slice(n);
}
return array.slice(0, n);
});
// 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.addPairedShortcode('note', type.note);
eleventyConfig.addPairedShortcode('warn', type.warn);
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) => {
const date = change.time;
changes.push({
post,
date,
url: post.url,
log: change.log,
latest: i === 0,
});
});
}
if (!post.data.draft) {
const date = post.data.created || post.date;
changes.push({
post,
date,
log: 'New page added',
latest: post.data.changes ? false : true,
creation: true,
});
}
});
return changes.map((item) => {
item.url = `/changelog${item.post.url}${ghSlug(time.date(item.date, 'iso'))}/`;
item.date_group = time.date(item.date, 'long');
return item;
}).sort((a, b) => b.date - a.date);
});
return {
markdownTemplateEngine: 'njk',
dir: {
input: 'src',
output: 'public',
layouts: '_layouts',
},
};
};