-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
77 lines (70 loc) · 2.41 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
const eleventyNavigationPlugin = require('@11ty/eleventy-navigation');
const { imageShortcode } = require('./utils/imageShortcode');
const {
htmlDateString,
readableDate,
readableUTCDate,
} = require('./utils/dateFormatters');
const fs = require('fs');
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(eleventyNavigationPlugin);
eleventyConfig.setQuietMode(true);
eleventyConfig.addNunjucksAsyncShortcode('image', imageShortcode);
eleventyConfig.addPassthroughCopy({ './src/static': '/' });
// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string
eleventyConfig.addFilter('htmlDateString', htmlDateString());
eleventyConfig.addFilter('readableDate', readableDate());
eleventyConfig.addFilter('readableUTCDate', readableUTCDate());
eleventyConfig.addCollection('faveCategories', function (collectionApi) {
const allFavorites = collectionApi.getFilteredByTag('favorites');
let categories = allFavorites.filter((fave) => {
return fave.data.tags.filter((tag) => tag !== 'posts').length === 1;
});
categories = categories
.map((category) => {
// replace category date with latest category element date
// the category title -> toLowerCase is the tag
category.date = collectionApi
.getFilteredByTag(category.data.title.toLowerCase())
.reduce(
(acc, curr) => (acc > curr.data.date ? acc : curr.data.date),
category.date,
);
return category;
})
.sort((a, b) => a.date - b.date);
return categories;
});
// 404
eleventyConfig.setBrowserSyncConfig({
files: ['dist/**/*', 'src/styles/*', 'src/scripts/*'],
// from https://github.com/turbolinks/turbolinks/issues/147#issuecomment-236443089
snippetOptions: {
rule: {
match: /<\/head>/i,
fn: function (snippet, match) {
return snippet + match;
},
},
},
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();
});
},
},
});
return {
dir: {
input: 'src',
output: 'dist',
},
// passthroughFileCopy: true,
htmlTemplateEngine: 'njk',
markdownTemplateEngine: 'njk',
};
};