-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy patheleventy.config.js
More file actions
145 lines (123 loc) · 5.62 KB
/
Copy patheleventy.config.js
File metadata and controls
145 lines (123 loc) · 5.62 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import eleventyNavigation from '@11ty/eleventy-navigation';
import fluidPlugin from 'eleventy-plugin-fluid';
import pluginRss from '@11ty/eleventy-plugin-rss';
import { eleventyImageTransformPlugin } from '@11ty/eleventy-img';
import { chunkArray, createPagination } from './src/assets/scripts/utilities.js';
import parseTransform from './src/transforms/parse.js';
import categoryFromFocusFilter from './src/filters/category-from-focus.js';
import getFilteredByTagSlug from './src/utils/get-filtered-by-tag-slug.js';
import getResourceTagLabelFilter from './src/filters/get-resource-tag-label.js';
import getUniqueTags from './src/utils/get-unique-tags.js';
import htmlSymbolFilter from './src/filters/html-symbol.js';
import markdownFilter from './src/filters/markdown.js';
import paginateFilter from './src/filters/paginate.js';
import randomizeFilter from './src/filters/randomize.js';
import expanderShortcode from './src/shortcodes/expander.js';
import imageAndTextShortcode from './src/shortcodes/image-and-text.js';
import youtubeShortcode from './src/shortcodes/youtube.js';
/**
* @param {object} eleventyConfig - The Eleventy configuration object.
* @returns {object} - Eleventy configuration.
*/
export default function eleventy(eleventyConfig) {
eleventyConfig.addCollection('events', (collection) => {
const events = [
...collection.getFilteredByGlob('src/collections/events/*.md'),
];
return events.toSorted((a, b) => b.data.eventDate - a.data.eventDate);
});
eleventyConfig.addCollection('initiatives', (collection) => {
const initiatives = [
...collection.getFilteredByGlob('src/collections/initiatives/*.md'),
];
return initiatives.toSorted((a, b) => b.data.date - a.data.date);
});
eleventyConfig.addCollection('recount', (collection) => {
const recount = [
...collection.getFilteredByGlob('src/collections/recount/*.md'),
];
return recount.toSorted((a, b) => b.data.date - a.data.date);
});
eleventyConfig.addCollection('views', (collection) => {
const views = [
...collection.getFilteredByGlob('src/collections/views/*.md'),
];
return views.toSorted((a, b) => b.data.date - a.data.date);
});
eleventyConfig.addCollection('resources', (collection) => {
const resources = [...collection.getFilteredByGlob('src/collections/resources/*.md')];
return resources.toSorted((a, b) => a.data.title.localeCompare(b.data.title, undefined, {
ignorePunctuation: 'true',
sensitivity: 'base',
usage: 'sort',
}));
});
eleventyConfig.addCollection('pages', (collection) => [
...collection.getFilteredByGlob('src/collections/pages/*.md'),
]);
eleventyConfig.addCollection('initiativesTags', (collection) => getUniqueTags(collection.getFilteredByGlob('src/collections/initiatives/*.md')));
eleventyConfig.addCollection('allTags', (collection) => {
const postsByTag = [];
for (const tag of getUniqueTags(collection.getAll())) {
postsByTag.push({ ...tag, posts: getFilteredByTagSlug(tag.slug, collection) });
}
const pageSize = 10;
const paginatedPostsByTag = [];
for (const tag of postsByTag) {
const postsWithTag = chunkArray(tag.posts, pageSize);
for (let pageNumber = 1; pageNumber <= postsWithTag.length; pageNumber++) {
const tagPage = {
slug: tag.slug,
title: tag.name,
posts: postsWithTag[pageNumber - 1],
pagination: createPagination(tag.posts, pageSize, pageNumber, '/tags/' + tag.slug + '/page/:page'),
};
// Add the root page that has the same content as the first page
// The root page is defined as such by its lack of "pageNumber" property
if (pageNumber === 1) {
paginatedPostsByTag.push(tagPage);
}
paginatedPostsByTag.push({ ...tagPage, pageNumber });
}
}
return paginatedPostsByTag;
});
// Add plugins.
eleventyConfig.addPlugin(eleventyNavigation);
eleventyConfig.addPlugin(eleventyImageTransformPlugin);
eleventyConfig.addPlugin(fluidPlugin, {
i18n: false,
});
eleventyConfig.addPlugin(pluginRss);
// Add filters.
eleventyConfig.addFilter('categoryFromFocus', categoryFromFocusFilter);
eleventyConfig.addFilter('getResourceTagLabel', getResourceTagLabelFilter);
eleventyConfig.addFilter('htmlSymbolFilter', htmlSymbolFilter);
eleventyConfig.addFilter('markdownFilter', markdownFilter);
eleventyConfig.addFilter('randomizeFilter', randomizeFilter);
eleventyConfig.addFilter('paginate', paginateFilter);
// Add shortcodes.
eleventyConfig.addPairedShortcode('expander', expanderShortcode);
eleventyConfig.addPairedShortcode('imageAndText', imageAndTextShortcode);
eleventyConfig.addShortcode('youtube', youtubeShortcode);
// Add transforms.
eleventyConfig.addTransform('parse', parseTransform);
// Configure passthrough file copy.
eleventyConfig.addPassthroughCopy({ 'src/_redirects': '_redirects' });
eleventyConfig.addPassthroughCopy({ 'node_modules/infusion': 'lib/infusion' });
eleventyConfig.addPassthroughCopy({ 'src/assets/fonts': 'assets/fonts' });
eleventyConfig.addPassthroughCopy({ 'src/assets/images': 'assets/images' });
eleventyConfig.addPassthroughCopy({ 'src/uploads': 'uploads' });
eleventyConfig.addPassthroughCopy({ 'src/assets/scripts': 'assets/scripts' });
eleventyConfig.addPassthroughCopy({ 'node_modules/lite-youtube-embed/src/lite-yt-embed.js': 'assets/scripts/lite-yt-embed.js' });
eleventyConfig.addPassthroughCopy({ 'node_modules/lite-youtube-embed/src/lite-yt-embed.css': 'assets/styles/lite-yt-embed.css' });
eleventyConfig.addPassthroughCopy({ 'src/admin/config.yml': 'admin/config.yml' });
eleventyConfig.addPassthroughCopy({ 'node_modules/axios/dist/axios.min.js': 'lib/axios.min.js' });
return {
dir: {
input: 'src',
},
passthroughFileCopy: true,
markdownTemplateEngine: 'njk',
};
}