-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheleventy.config.js
More file actions
88 lines (77 loc) · 2.67 KB
/
Copy patheleventy.config.js
File metadata and controls
88 lines (77 loc) · 2.67 KB
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
import { feedPlugin } from '@11ty/eleventy-plugin-rss';
import { JSDOM } from 'jsdom';
import slugify from '@sindresorhus/slugify';
import tags from './tags.js';
export default function (eleventyConfig) {
// Global data
eleventyConfig.addGlobalData('windowTitle', 'cberes');
eleventyConfig.addGlobalData('siteTitle', 'Corey Beres');
// 👀
eleventyConfig.addWatchTarget("./articles/");
// Copy files
eleventyConfig.addPassthroughCopy({assets: '/'});
eleventyConfig.addPassthroughCopy('articles/**/*.{png,jpg}');
// Collections
eleventyConfig.addCollection('tagsList', collectionApi => {
const knownTags = new Set(tags);
const foundTags = collectionApi.getAll()
.flatMap(item => item.data.tags || [])
.reduce((acc, tag) => {
acc.add(tag);
return acc;
}, new Set());
foundTags.delete('articles'); // all items have this tag
// check that we know all tags and all known tags are actually used
if (!setEquals(knownTags, foundTags)) {
const tagsToAdd = foundTags.difference(knownTags);
const tagsToRemove = knownTags.difference(foundTags);
throw new Error(`Update list of tags! Add: ${[...tagsToAdd]} Remove: ${[...tagsToRemove]}`);
}
return [...foundTags].sort();
});
// add templates for all tags
tags.forEach(tag => {
eleventyConfig.addTemplate(`tags/${slugify(tag)}.njk`, `<p>All articles with the tag <em>{{ tag }}</em> ({{ collections[tag].length }})</p>`, {
layout: 'paged.njk',
tag,
title: tag,
pagination: {
data: `collections.${tag}`,
reverse: true,
size: 6
}
});
});
// RSS
eleventyConfig.addPlugin(feedPlugin, {
type: 'atom', // or 'rss', 'json'
outputPath: '/rss.xml',
collection: {
name: 'articles', // iterate over `collections.articles`
limit: 0, // 0 means no limit
},
metadata: {
language: 'en',
title: 'cberes',
subtitle: 'Personal homepage for Corey Beres. Mostly thoughts about software and skateboards.',
base: 'https://cberes.com/',
author: {
name: 'Corey Beres',
email: '', // Optional
}
}
});
// Summary shortcode
eleventyConfig.addShortcode('summarize', function (item) {
const dom = new JSDOM(item.content);
const summary = dom.window.document.getElementById('summary');
return (summary || dom.window.document.querySelector('p')).textContent;
});
// Nunjucks filters
eleventyConfig.addNunjucksFilter('firstItems', function(array, count) {
return array.slice(0, count);
});
};
function setEquals(a, b) {
return a === b || (a.size === b.size && [...a].every((it => b.has(it))));
}