/
.eleventy.js
143 lines (133 loc) · 4.81 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
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
const esbuild = require('esbuild');
const path = require('path');
const PluginFootnotes = require('eleventy-plugin-footnotes');
const {
asideShortcode,
definitionShortcode,
imageShortcode,
iconShortcode,
socialIconShortcode,
quoteShortcode,
faviconShortcode,
artworkShortcode,
hashArtShortcode,
nanoIdShortcode,
detailsShortcode,
} = require('./config/shortcodes');
const {
limit,
sortByKey,
toHtml,
where,
toISOString,
formatDate,
dividedBy,
toAbsoluteUrl,
getLatestCollectionItemDate,
cleanCSS,
toAbsoluteImageUrl,
pathParse,
pathJoin,
toUTCString,
} = require('./config/filters/filters');
const {
getAllPosts,
getAllUniqueCategories,
getPostsByCategory,
} = require('./config/collections');
const markdownLib = require('./config/plugins/markdown');
const { dir, imagePaths, scriptDirs } = require('./config/constants');
const { slugifyString } = require('./config/utils');
const { escape } = require('lodash');
const TEMPLATE_ENGINE = 'liquid';
module.exports = (eleventyConfig) => {
eleventyConfig.setLiquidOptions({
// Allows for dynamic include/partial names. If true, include names must be quoted. Defaults to true as of beta/1.0.
dynamicPartials: true,
});
// Watch targets
eleventyConfig.addWatchTarget(imagePaths.input);
eleventyConfig.addWatchTarget(scriptDirs.input);
// Pass-through copy for static assets
eleventyConfig.addPassthroughCopy(path.join(dir.input, dir.assets, 'fonts'));
eleventyConfig.addPassthroughCopy(path.join(dir.input, dir.assets, 'videos'));
eleventyConfig.addPassthroughCopy(path.join(imagePaths.input, '404'));
eleventyConfig.addPassthroughCopy(path.join(imagePaths.input, 'art'));
// Custom shortcodes
eleventyConfig.addPairedShortcode('aside', asideShortcode);
eleventyConfig.addPairedShortcode('quote', quoteShortcode);
eleventyConfig.addPairedShortcode('definition', definitionShortcode);
eleventyConfig.addPairedShortcode('artwork', artworkShortcode);
eleventyConfig.addPairedShortcode('details', detailsShortcode);
eleventyConfig.addShortcode('image', imageShortcode);
eleventyConfig.addShortcode('favicon', faviconShortcode);
eleventyConfig.addShortcode('icon', iconShortcode);
eleventyConfig.addShortcode('socialIcon', socialIconShortcode);
eleventyConfig.addShortcode('hashArt', hashArtShortcode);
eleventyConfig.addShortcode('nanoid', nanoIdShortcode);
// Custom filters
eleventyConfig.addFilter('limit', limit);
eleventyConfig.addFilter('sortByKey', sortByKey);
eleventyConfig.addFilter('where', where);
eleventyConfig.addFilter('escape', escape);
eleventyConfig.addFilter('toHtml', toHtml);
eleventyConfig.addFilter('toIsoString', toISOString);
eleventyConfig.addFilter('toUTCString', toUTCString);
eleventyConfig.addFilter('formatDate', formatDate);
eleventyConfig.addFilter('dividedBy', dividedBy);
eleventyConfig.addFilter('toAbsoluteUrl', toAbsoluteUrl);
eleventyConfig.addFilter('toAbsoluteImageUrl', toAbsoluteImageUrl);
eleventyConfig.addFilter('slugify', slugifyString);
eleventyConfig.addFilter('toJson', JSON.stringify);
eleventyConfig.addFilter('fromJson', JSON.parse);
eleventyConfig.addFilter('getLatestCollectionItemDate', getLatestCollectionItemDate);
eleventyConfig.addFilter('cleanCSS', cleanCSS);
eleventyConfig.addFilter('keys', Object.keys);
eleventyConfig.addFilter('values', Object.values);
eleventyConfig.addFilter('entries', Object.entries);
eleventyConfig.addFilter('pathParse', pathParse);
eleventyConfig.addFilter('pathJoin', pathJoin);
// Custom collections
eleventyConfig.addCollection('posts', getAllPosts);
eleventyConfig.addCollection('categories', getAllUniqueCategories);
eleventyConfig.addCollection('postsByCategory', getPostsByCategory);
// Plugins
eleventyConfig.addPlugin(PluginFootnotes, {
baseClass: 'footnotes',
classes: {
container: 'rhythm',
},
title: 'Footnotes',
titleId: 'footnotes-label',
backLinkLabel: (footnote, index) => `Back to reference ${index + 1}`,
});
eleventyConfig.setLibrary('md', markdownLib);
// Post-processing
eleventyConfig.on('afterBuild', () => {
return esbuild.build({
entryPoints: [
path.join(scriptDirs.input, 'index.mjs'),
path.join(scriptDirs.input, 'demos/Carousel/index.mjs'),
path.join(scriptDirs.input, 'comments.mjs'),
],
entryNames: '[dir]/[name]',
outdir: scriptDirs.output,
format: 'esm',
outExtension: { '.js': '.mjs' },
bundle: true,
splitting: true,
minify: true,
sourcemap: process.env.ELEVENTY_ENV !== 'production',
loader: {
'.svg': 'text',
},
});
});
return {
dir,
dataTemplateEngine: TEMPLATE_ENGINE,
markdownTemplateEngine: TEMPLATE_ENGINE,
htmlTemplateEngine: TEMPLATE_ENGINE,
templateFormats: ['html', 'md', TEMPLATE_ENGINE],
};
};