-
Notifications
You must be signed in to change notification settings - Fork 5
/
eleventy.config.js
102 lines (85 loc) · 2.79 KB
/
eleventy.config.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
import rssPlugin from '@11ty/eleventy-plugin-rss';
import syntaxHighlight from '@11ty/eleventy-plugin-syntaxhighlight';
import slugify from 'slugify';
// import pluginPWA from 'eleventy-plugin-pwa';
import dateFilter from './src/filters/date-filter.js';
import w3DateFilter from './src/filters/w3-date-filter.js';
import parseTransform from './src/transforms/parse-transform.js';
import htmlMinTransform from './src/transforms/html-min-transform.js';
const EXCLUDED_TAGS = ['blog', 'all'];
export default config => {
// Add filters
config.addFilter('dateFilter', dateFilter);
config.addFilter('w3DateFilter', w3DateFilter);
// Plugins
config.addPlugin(rssPlugin);
config.addPlugin(syntaxHighlight);
// config.addPlugin(pluginPWA, {
// globPatterns: [
// '**/*.{css,js,mjs,map,jpg,png,gif,webp,ico,svg,woff2,woff,eot,ttf,otf,ttc,json}'
// ]
// });
// Transforms
config.addTransform('htmlmin', htmlMinTransform);
config.addTransform('parse', parseTransform);
// Returns a collection of blog posts in reverse date order
config.addCollection('blog', collection => {
return [...collection.getFilteredByGlob('./src/posts/*.md')].reverse();
});
config.addCollection('tags', collection => {
const items = [];
// Grabs every collection, finds items with tags and uses them to
// populate the items array if they are not excluded
collection.getAll().forEach(item => {
if (!item.data.tags) {
return;
}
item.data.tags
.filter(tag => !EXCLUDED_TAGS.includes(tag))
.forEach(tag => {
items.push(tag);
});
});
return [...new Set(items)].map(item => ({
text: item,
url: `/tag/${slugify(item.toLowerCase())}`
}));
});
config.addCollection('categories', collection => {
const items = [];
// Grabs all items with categories and generates a loopable
// collection of them
collection.getAll().forEach(item => {
if (!item.data.categories) {
return;
}
let categories = item.data.categories;
if (typeof categories === 'string') {
categories = [categories];
}
categories.forEach(category => {
items.push(category);
});
});
return [...new Set(items)].map(item => ({
text: item,
url: `/category/${slugify(item.toLowerCase())}`
}));
});
// Tell 11ty to use the .eleventyignore and ignore our .gitignore file
config.setUseGitIgnore(false);
// Pass through
config.addPassthroughCopy('./src/favicons/');
config.addPassthroughCopy('./src/media/');
config.addPassthroughCopy('./src/scripts/');
return {
markdownTemplateEngine: 'njk',
dataTemplateEngine: 'njk',
htmlTemplateEngine: 'njk',
dir: {
input: 'src',
output: 'dist'
},
passthroughFileCopy: true
};
};