-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
164 lines (125 loc) · 5.04 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
const fs = require('fs');
module.exports = function (config) {
// don't use .gitignore (allows compiling sass to css into a monitored folder WITHOUT committing it to repo)
config.setUseGitIgnore(false);
// Processing configuration
config.addPassthroughCopy('src/favicon.ico');
config.addPassthroughCopy('src/admin');
config.addPassthroughCopy('src/assets');
// Eleventy Navigation (https://www.11ty.dev/docs/plugins/navigation/)
config.addPlugin(require('@11ty/eleventy-navigation'));
// Eleventy RSS Feed (https://www.11ty.dev/docs/plugins/rss/)
config.addPlugin(require('@11ty/eleventy-plugin-rss'));
// Filter to generate a Table of Contents from page content
config.addPlugin(require('eleventy-plugin-toc'))
// TODO: use https://www.npmjs.com/package/eleventy-plugin-nesting-toc instead?
// Filter to calculate reading time from text content or a collection object
config.addPlugin(require('eleventy-plugin-reading-time'));
// TODO https://www.npmjs.com/package/eleventy-plugin-meta-generator
// Eleventy Syntax Highlighting (https://www.11ty.dev/docs/plugins/syntaxhighlight/)
config.addPlugin(require('@11ty/eleventy-plugin-syntaxhighlight'));
// Merge Data (https://www.11ty.dev/docs/data-deep-merge/)
config.setDataDeepMerge(true);
// Custom Collections
config.addCollection('pages', collection => collection
.getFilteredByGlob('./src/pages/**/*')
);
config.addCollection('posts', collection => collection
.getFilteredByGlob('./src/posts/**/*')
.filter(item => item.data.draft !== true && item.date <= new Date())
.reverse()
.map((cur, i, all) => {
cur.data['siblings'] = {
'next': all[i - 1],
'prev': all[i + 1],
};
return cur;
})
);
config.addCollection('projects', collection => collection
.getFilteredByGlob('./src/projects/**/*')
.sort((a, b) => a.data.weight - b.data.weight)
);
config.addCollection('tags', collection => {
let tags = new Set();
collection.getAll().forEach(item => {
if ('tags' in item.data) {
for (const tag of item.data.tags) {
tags.add(tag);
}
}
});
return [...tags];
});
// Markdown Configuration
const md = require('markdown-it')({
html: true,
breaks: true,
linkify: true,
});
config.setLibrary('md', md
.use(require('markdown-it-attrs'))
.use(require('markdown-it-container'), '', {
validate: () => true,
render: (tokens, idx) => {
if (tokens[idx].nesting === 1) {
const classList = tokens[idx].info.trim()
return `<div ${classList && `class="${classList}"`}>`;
} else {
return `</div>`;
}
}
})
.use(require('markdown-it-fontawesome'))
.use(require('markdown-it-footnote'))
);
// override markdown-it-footnote anchor template to use a different unicode character
md.renderer.rules.footnote_anchor = (tokens, idx, options, env, slf) => {
var id = slf.rules.footnote_anchor_name(tokens, idx, options, env, slf);
if (tokens[idx].meta.subId > 0) {
id += ':' + tokens[idx].meta.subId;
}
/* ⇑ with escape code to prevent display as Apple Emoji on iOS */
return ' <a href="#fnref' + id + '" class="footnote-backref">\u21d1\uFE0E</a>';
};
config.setFrontMatterParsingOptions({
excerpt: true,
});
config.addNunjucksFilter('markdownify', str => md.render(str));
config.addFilter('jsonify', variable => JSON.stringify(variable));
config.addFilter('slugify', str => require('slugify')(str, {
lower: true,
replacement: '-',
remove: /[*+~.·,()''`´%!?¿:@]/g
}));
config.addFilter('where', (array, key, value) => array.filter(item => {
const keys = key.split('.');
const reducedKey = keys.reduce((object, key) => object[key], item);
return (reducedKey === value ? item : false);
}));
config.addFilter('date', (date, format = '') => require('moment')(date).format(format));
// Configure BrowserSync to serve the 404 page for missing files
config.setBrowserSyncConfig({
callbacks: {
ready: (_err, browserSync) => {
const content_404 = fs.readFileSync('dist/404.html');
browserSync.addMiddleware('*', (_req, res) => {
// render the 404 content instead of redirecting
res.write(content_404);
res.end();
});
}
}
});
return {
templateFormats: ['html', 'njk', 'liquid', 'md',],
pathPrefix: '/',
passthroughFileCopy: true,
dir: {
input: 'src',
includes: '_includes',
data: '_data',
output: 'dist'
}
};
};