-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
102 lines (91 loc) · 3.89 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const markdownIt = require('markdown-it');
const utils = require('./src/utils');
module.exports = eleventyConfig => {
// custom markdown library with automatic anchors for h2 headings
const markdownLib = markdownIt({
html: true,
typographer: true,
});
eleventyConfig.setLibrary('md', markdownLib);
// image manipulation
eleventyConfig.addFilter('imageWidth', utils.imageWidth);
eleventyConfig.addFilter('widthsToSrcset', utils.widthsToSrcset);
// utility methods
eleventyConfig.addFilter('firstNItems', (arr, n = 1) => arr.slice(0, n));
eleventyConfig.addFilter('implodeTruthy', (arr, glue = ', ') => arr.filter(item => !!item).join(glue));
eleventyConfig.addFilter('is_string', s => typeof s === 'string');
eleventyConfig.addFilter('is_object', s => typeof s === 'object');
eleventyConfig.addFilter('stripDate', utils.stripDate);
eleventyConfig.addFilter('findSections', utils.findSections);
// markdown render filter
eleventyConfig.addFilter('md', text => markdownLib.render(text));
eleventyConfig.addFilter('md_inline', text => markdownLib.renderInline(text));
// date functions
eleventyConfig.addFilter('date', date => (new Date(date)).toLocaleDateString('en-GB', { year: 'numeric', month: 'long', day: 'numeric' }));
eleventyConfig.addFilter('date_iso', date => (new Date(date).toISOString().split('T')[0]));
eleventyConfig.addFilter('date_id', (date, prefix = 'd') => `${prefix}${(new Date(date).toISOString().split('T')[0])}`);
// debug utility
eleventyConfig.addFilter('log', v => console.log(v));
// shortcode to get fontawesome icons
eleventyConfig.addShortcode('fontawesome', utils.fontawesome);
// get a sorted list of subject collections
const photosBySubject = collection => collection.getFilteredByTag('subject').sort((a, b) => {
return a.data.sort - b.data.sort;
});
// get a sorted list of subject collections, including the "favourites" page
const photosBySubjectWithFavourites = collection => ([
...photosBySubject(collection),
...(collection.getFilteredByTag('favourites'))
]);
// get a sorted list of projects
const photosByProject = collection => collection.getFilteredByTag('project').sort((a, b) => {
return b.date - a.date
});
// add subjects & project collections
eleventyConfig.addCollection('subjects', c => photosBySubject(c));
eleventyConfig.addCollection('subjects_favourites', c => photosBySubjectWithFavourites(c));
eleventyConfig.addCollection('projects', c => photosByProject(c));
// add the post tree for the navigation
eleventyConfig.addCollection('postTree', collection => {
return [
{
title: 'General',
posts: [
...collection.getFilteredByTag('homepage'),
...collection.getFilteredByTag('blog'),
...collection.getFilteredByTag('favourites'),
],
},
{
title: 'Photos by subject',
posts: photosBySubject(collection),
},
{
title: 'Photos by project',
posts: photosByProject(collection),
}
];
});
// configure eleventy file copy
eleventyConfig.addPassthroughCopy({
'site/assets': 'assets',
'site/root-assets/*': '.',
'site/_redirects': '_redirects',
'site/_headers': '_headers',
'site/photos': 'photos',
});
// watch css / js directories
eleventyConfig.addWatchTarget('src/');
return {
templateFormats: ['html', 'md', 'njk', '11ty.js'],
markdownTemplateEngine: 'njk',
pathPrefix: '/',
dir: {
input: 'site/',
output: 'dist/',
includes: "_includes",
layouts: "_includes/_layouts",
data: "_data",
},
}
}