forked from madrilene/eleventy-excellent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eleventy.config.js
114 lines (92 loc) · 3.93 KB
/
eleventy.config.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
/**
* Most adjustments must be made in `./src/_config/*`
*/
/**
* Configures Eleventy with various settings, collections, plugins, filters, shortcodes, and more.
* 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, onlyMarkdown, 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) {
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('onlyMarkdown', onlyMarkdown);
eleventyConfig.addCollection('tagList', tagList);
// --------------------- Plugins
eleventyConfig.addPlugin(plugins.htmlConfig);
eleventyConfig.addPlugin(plugins.cssConfig);
eleventyConfig.addPlugin(plugins.jsConfig);
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
});
// --------------------- 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('toAbsoluteUrl', filters.toAbsoluteUrl);
eleventyConfig.addFilter('slugify', filters.slugifyString);
// --------------------- Shortcodes
eleventyConfig.addShortcode('svg', shortcodes.svgShortcode);
eleventyConfig.addShortcode('image', shortcodes.imageShortcode);
eleventyConfig.addShortcode('year', () => `${new Date().getFullYear()}`);
// --------------------- Events ---------------------
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/`
});
// --------------------- Build Settings
eleventyConfig.setDataDeepMerge(true);
// --------------------- general config
return {
markdownTemplateEngine: 'njk',
dir: {
output: 'dist',
input: 'src',
includes: '_includes',
layouts: '_layouts'
}
};
}