-
Notifications
You must be signed in to change notification settings - Fork 1
/
.eleventy.js
118 lines (96 loc) · 2.8 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
const rssPlugin = require('@11ty/eleventy-plugin-rss');
const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight');
const fs = require('fs');
const pluginTOC = require('eleventy-plugin-toc')
const filters = require('./src/11ty/filters');
const filtersMethods = Object.entries(filters);
// Import transforms
const parseTransform = require('./src/transforms/parse-transform.js');
const markdownConfig = require('./src/utils/markdown.js');
// Import data files
const site = require('./src/_data/site.json');
const passthroughItems = [
"src/_redirects",
"src/fonts",
"src/images",
"src/js",
"src/uploads",
"src/admin/config.yml",
"src/admin/previews.js",
"node_modules/nunjucks/browser/nunjucks-slim.js"
]
module.exports = function (config) {
// Filters
filtersMethods.forEach(([name, filter]) => {
config.addFilter(name, filter)
});
// Transforms
config.addTransform('parse', parseTransform);
passthroughItems.forEach(item => {
config.addPassthroughCopy(item);
})
config.addWatchTarget("src/_includes/partials/global/service-worker.js");
const isStarredPost = post => post.data.star;
config.addCollection('posts', collection => {
return [
...collection.getFilteredByGlob('./src/posts/*.md')
].reverse();
});
config.addCollection('postFeed', collection => {
return [...collection.getFilteredByGlob('./src/posts/*.md')]
.reverse()
.slice(0, site.maxPostsPerPage);
});
config.addCollection('starFeed', collection => {
return [...collection.getFilteredByGlob('./src/posts/*.md').filter(isStarredPost)]
.reverse()
.slice(0, site.maxPostsPerPage);
});
config.addCollection('work', collection => {
return collection.getFilteredByGlob('./src/work/*.md')
.sort((a, b) => b.data.start - a.data.start);
});
// Plugins
config.addPlugin(rssPlugin);
config.addPlugin(syntaxHighlight);
config.addPlugin(pluginTOC, {
tags: ['h2', 'h3', 'h4'],
wrapper: 'nav',
wrapperClass: 'toc'
});
// 404
config.setBrowserSyncConfig({
ui: false,
// Replicate click on all opened tabs
ghostMode: false,
callbacks: {
ready: function (err, browserSync) {
const content_404 = fs.readFileSync('dist/404.html');
browserSync.addMiddleware('*', (req, res) => {
// Provides the 404 content without redirect.
res.write(content_404);
res.end();
});
}
}
});
config.setLibrary("md", markdownConfig)
config.setFrontMatterParsingOptions({
excerpt: true,
excerpt_separator: "---"
});
return {
templateFormats: [
"md",
"njk",
],
markdownTemplateEngine: "njk",
htmlTemplateEngine: "njk",
dataTemplateEngine: "njk",
dir: {
input: 'src',
output: 'dist'
},
passthroughFileCopy: true
};
};