generated from ar363/eleventy-stylus-blog-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
71 lines (63 loc) · 2.62 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
const { DateTime } = require('luxon')
const navigationPlugin = require('@11ty/eleventy-navigation')
const rssPlugin = require('@11ty/eleventy-plugin-rss')
module.exports = (config) => {
config.addPlugin(navigationPlugin);
config.addPlugin(rssPlugin);
config.addPassthroughCopy('css');
config.addPassthroughCopy('static');
config.addPassthroughCopy({"pictures/posts": "posts/pictures/posts"});
config.addPassthroughCopy({"pictures/extensions": "extensions/pictures/extensions"});
config.setDataDeepMerge(true);
config.addFilter('htmlDateString', (dateObj) => {
return DateTime.fromJSDate(dateObj, {zone: 'utc'}).toFormat('yyyy-LL-dd');
});
config.addFilter("readableDate", dateObj => {
return DateTime.fromJSDate(dateObj, {zone: 'utc'}).toFormat("dd LLL, yyyy");
});
config.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)
});
config.addCollection("categoryList", collection => {
const categoriesObject = {};
collection.getAll().forEach(item => {
if (!item.data.categories) return;
item.data.categories
.filter(categories => !['extensions', 'all'].includes(categories))
.forEach(category => {
if(typeof categoriesObject[category] === 'undefined') {
categoriesObject[category] = { categoryName: category, categoryCount: 1, posts: [item] };
} else {
categoriesObject[category].categoryCount++;
categoriesObject[category].posts.push(item);
}
});
});
const categoryList = [];
Object.keys(categoriesObject).forEach(category => {
categoryList.push({
categoryName: category,
categoryCount: categoriesObject[category].categoryCount,
posts: categoriesObject[category].posts
});
});
return categoryList.sort((a, b) => b.categoryCount - a.categoryCount);
});
}