-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheleventy.config.js
More file actions
131 lines (108 loc) · 4.3 KB
/
Copy patheleventy.config.js
File metadata and controls
131 lines (108 loc) · 4.3 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
/**
* Most adjustments must be made in `./src/_config/*`
*
* Hint VS Code for eleventyConfig autocompletion.
* © Henry Desroches - https://gist.github.com/xdesro/69583b25d281d055cd12b144381123bf
* @param {import("@11ty/eleventy/src/UserConfig")} eleventyConfig -
* @returns {Object} -
*/
// register dotenv for process.env.* variables to pickup
import dotenv from 'dotenv';
dotenv.config();
// add yaml support
import yaml from 'js-yaml';
// config import
import {getAllPosts, showInSitemap, tagList} from './src/_config/collections.js';
import events from './src/_config/events.js';
import filters from './src/_config/filters.js';
import plugins from './src/_config/plugins.js';
import shortcodes from './src/_config/shortcodes.js';
export default async function (eleventyConfig) {
// --------------------- Events: before build
eleventyConfig.on('eleventy.before', async () => {
await events.buildAllCss();
await events.buildAllJs();
});
// --------------------- custom wtach targets
eleventyConfig.addWatchTarget('./src/assets/**/*.{css,js,svg,png,jpeg}');
eleventyConfig.addWatchTarget('./src/_includes/**/*.{webc}');
// --------------------- layout aliases
eleventyConfig.addLayoutAlias('base', 'base.njk');
eleventyConfig.addLayoutAlias('page', 'page.njk');
eleventyConfig.addLayoutAlias('post', 'post.njk');
eleventyConfig.addLayoutAlias('tags', 'tags.njk');
// --------------------- Collections
eleventyConfig.addCollection('allPosts', getAllPosts);
eleventyConfig.addCollection('showInSitemap', showInSitemap);
eleventyConfig.addCollection('tagList', tagList);
// --------------------- Plugins
eleventyConfig.addPlugin(plugins.htmlConfig);
eleventyConfig.addPlugin(plugins.drafts);
eleventyConfig.addPlugin(plugins.EleventyRenderPlugin);
eleventyConfig.addPlugin(plugins.rss);
eleventyConfig.addPlugin(plugins.syntaxHighlight);
eleventyConfig.addPlugin(plugins.webc, {
components: ['./src/_includes/webc/**/*.webc'],
useTransform: true
});
eleventyConfig.addPlugin(plugins.eleventyImageTransformPlugin, {
formats: ['webp', 'jpeg'],
widths: ['auto'],
htmlOptions: {
imgAttributes: {
loading: 'lazy',
decoding: 'async',
sizes: 'auto'
},
pictureAttributes: {}
}
});
// --------------------- bundle
eleventyConfig.addBundle('css', {hoist: true});
// --------------------- Library and Data
eleventyConfig.setLibrary('md', plugins.markdownLib);
eleventyConfig.addDataExtension('yaml', contents => yaml.load(contents));
// --------------------- Filters
eleventyConfig.addFilter('toIsoString', filters.toISOString);
eleventyConfig.addFilter('formatDate', filters.formatDate);
eleventyConfig.addFilter('markdownFormat', filters.markdownFormat);
eleventyConfig.addFilter('splitlines', filters.splitlines);
eleventyConfig.addFilter('striptags', filters.striptags);
eleventyConfig.addFilter('shuffle', filters.shuffleArray);
eleventyConfig.addFilter('alphabetic', filters.sortAlphabetically);
eleventyConfig.addFilter('slugify', filters.slugifyString);
// --------------------- Shortcodes
eleventyConfig.addShortcode('svg', shortcodes.svgShortcode);
eleventyConfig.addShortcode('image', shortcodes.imageShortcode);
eleventyConfig.addShortcode('imageKeys', shortcodes.imageKeysShortcode);
eleventyConfig.addShortcode('year', () => `${new Date().getFullYear()}`);
// --------------------- Events: after build
if (process.env.ELEVENTY_RUN_MODE === 'serve') {
eleventyConfig.on('eleventy.after', events.svgToJpeg);
}
// --------------------- Passthrough File Copy
// -- same path
['src/assets/fonts/', 'src/assets/images/template', 'src/assets/og-images'].forEach(path =>
eleventyConfig.addPassthroughCopy(path)
);
eleventyConfig.addPassthroughCopy({
// -- to root
'src/assets/images/favicon/*': '/',
// -- node_modules
'node_modules/lite-youtube-embed/src/lite-yt-embed.{css,js}': `assets/components/`
});
// ---------------------- ignore test files
if (process.env.ELEVENTY_ENV != 'test') {
eleventyConfig.ignores.add('src/common/pa11y.njk');
}
// --------------------- general config
return {
markdownTemplateEngine: 'njk',
dir: {
output: 'dist',
input: 'src',
includes: '_includes',
layouts: '_layouts'
}
};
}