-
Notifications
You must be signed in to change notification settings - Fork 4
/
.eleventy.js
99 lines (85 loc) · 3.04 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
const fs = require('fs');
const pluginSyntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight');
const pluginNavigation = require('@11ty/eleventy-navigation');
const markdownIt = require('markdown-it');
const markdownItAnchor = require('markdown-it-anchor');
const pluginTOC = require('eleventy-plugin-nesting-toc');
const { getSlugMap, getSortedCollection, indexItems } = require('./src/_11ty/collections');
const { htmlDateString, readableDate, split } = require('./src/_11ty/filters');
require('dotenv').config({ path: `.env.${process.env.NODE_ENV || 'development'}` });
// https://www.11ty.dev/docs/config/
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(pluginSyntaxHighlight);
eleventyConfig.addPlugin(pluginNavigation);
eleventyConfig.addPlugin(pluginTOC, {
wrapperClass: 'entry__toc',
});
/* Markdown Overrides */
let markdownLibrary = markdownIt({
html: true,
breaks: true,
linkify: true,
typographer: true,
}).use(markdownItAnchor);
eleventyConfig.setLibrary('md', markdownLibrary);
eleventyConfig.setDataDeepMerge(true);
eleventyConfig.setUseGitIgnore(false);
// For rendering JSON API routes
eleventyConfig.addJavaScriptFunction('renderApi', data => JSON.stringify(data, null, '\t'));
/**
* Add custom collections
*
* @see https://www.11ty.dev/docs/collections/#advanced-custom-filtering-and-sorting
*/
eleventyConfig.addCollection('sortedEntries', collectionApi =>
getSortedCollection(collectionApi, 'entries'),
);
eleventyConfig.addCollection('entriesMap', collectionApi => getSlugMap(collectionApi, 'entries'));
eleventyConfig.addCollection('indexItems', indexItems);
/**
* Add custom filters
*
* @see https://www.11ty.dev/docs/filters/
*/
eleventyConfig.addFilter('htmlDateString', htmlDateString);
eleventyConfig.addFilter('readableDate', readableDate);
eleventyConfig.addFilter('split', split);
/**
* Add custom watch targets
*
* @see https://www.11ty.dev/docs/config/#add-your-own-watch-targets
*/
eleventyConfig.addWatchTarget('./bundle/');
eleventyConfig.addWatchTarget('./src/assets/styles/');
eleventyConfig.addWatchTarget('./src/pages/');
/**
* Copy directories to _site
*
* @see https://www.11ty.dev/docs/copy/#passthrough-file-copy
*/
eleventyConfig.addPassthroughCopy('src/static/img');
eleventyConfig.addPassthroughCopy('src/static/fonts');
eleventyConfig.addPassthroughCopy({ bundle: 'assets/scripts' });
// Browsersync Overrides
eleventyConfig.setBrowserSyncConfig({
callbacks: {
ready: function (err, browserSync) {
const content_404 = fs.readFileSync('_site/404.html');
browserSync.addMiddleware('*', (req, res) => {
// Provides the 404 content without redirect.
res.write(content_404);
res.end();
});
},
},
ui: false,
ghostMode: false,
});
return {
templateFormats: ['md', 'njk', 'html', 'liquid', '11ty.js'],
// These are all optional, defaults are shown:
dir: {
input: 'src',
},
};
};