-
Notifications
You must be signed in to change notification settings - Fork 8
/
.eleventy.js
87 lines (72 loc) · 2.58 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
const { DateTime } = require("luxon");
const navigationPlugin = require('@11ty/eleventy-navigation');
const rssPlugin = require('@11ty/eleventy-plugin-rss');
const Image = require("@11ty/eleventy-img");
const EleventyFetch = require("@11ty/eleventy-fetch");
const { EleventyHtmlBasePlugin } = require("@11ty/eleventy");
module.exports = function(eleventyConfig) {
// Universal Shortcodes (Adds to Liquid, Nunjucks, Handlebars)
eleventyConfig.addShortcode("bgImg", function(imgName, test) {
return ` style="background-image: url('./img/webp/${imgName}.webp');"`;
});
//Base Plugin
eleventyConfig.addPlugin(EleventyHtmlBasePlugin);
// blogposts collection
eleventyConfig.addCollection("components", function (collection) {
return collection.getFilteredByGlob("./src/components/*.njk").reverse();
});
function filterTagList(tags) {
return (tags || []).filter(tag => ["all", "nav"].indexOf(tag) === -1);
}
eleventyConfig.setDataDeepMerge(true);
function filterTagList(tags) {
return (tags || []).filter(tag => ["all", "nav", "post", "posts"].indexOf(tag) === -1);
}
eleventyConfig.addFilter("filterTagList", filterTagList)
eleventyConfig.addPassthroughCopy("src/fonts");
eleventyConfig.addCollection("tagList", collection => {
const tagsObject = {}
collection.getAll().forEach(item => {
if (!item.data.tags) return;
item.data.tags
.filter(tag => !['post', 'all'].includes(tag))
.forEach(tag => {
if(typeof tagsObject[tag] === 'undefined') {
tagsObject[tag] = 1
} else {
tagsObject[tag] += 1
}
});
});
const tagList = []
Object.keys(tagsObject).forEach(tag => {
tagList.push({ tagName: tag, tagCount: tagsObject[tag] })
})
return tagList.sort((a, b) => b.tagCount - a.tagCount)
});
// Add a filter using the Config API
eleventyConfig.addWatchTarget("./src/scss/");
eleventyConfig.setBrowserSyncConfig({
reloadDelay: 400
});
eleventyConfig.addFilter("readableDate", dateObj => {
return DateTime.fromJSDate(dateObj, {
zone: 'utc'
}).toFormat("dd LLL yyyy");
});
eleventyConfig.addCollection('componentstotal', (collection) => {
return collection.getFilteredByGlob('_components/**/*.njk');
});
// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string
eleventyConfig.addFilter('htmlDateString', (dateObj) => {
return DateTime.fromJSDate(dateObj, {
zone: 'utc'
}).toFormat('yyyy-LL-dd');
});
return {
dir: {
input: "src",
output: "dev"
}
};
};