generated from clenemt/eleventy-webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
92 lines (81 loc) · 2.87 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
const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight')
const NavigationPlugin = require('@11ty/eleventy-navigation');
const ErrorOverlayPlugin = require('eleventy-plugin-error-overlay');
const RssPlugin = require('@11ty/eleventy-plugin-rss')
const filters = require('./utils/filters');
const markdown = require('./utils/markdown');
const shortcodes = require('./utils/shortcodes');
const transforms = require('./utils/transforms');
module.exports = (config) => {
const manifestPath = path.resolve(__dirname, '_site/assets/manifest.json');
// Allow for customizing the built in markdown parser.
config.setLibrary('md', markdown);
// Allow eleventy to understand yaml files
config.addDataExtension('yml', (contents) => yaml.safeLoad(contents));
// Plugins
config.addPlugin(NavigationPlugin);
// Shows error name, message, and fancy stacktrace
config.addPlugin(ErrorOverlayPlugin);
// rss
config.addPlugin(RssPlugin)
// syntax highlighting
config.addPlugin(syntaxHighlight)
// Filters
Object.keys(filters).forEach((key) => {
config.addFilter(key, filters[key]);
});
// Transforms
Object.keys(transforms).forEach((key) => {
config.addTransform(key, transforms[key]);
});
// Shortcodes
config.addShortcode('icon', shortcodes.icon);
config.addShortcode('date', shortcodes.date)
config.addShortcode('unifont', shortcodes.unifont)
config.addPairedShortcode('markdown', shortcodes.markdown);
config.addNunjucksAsyncShortcode('image', shortcodes.image);
config.addNunjucksAsyncShortcode('webpack', shortcodes.webpack);
// Pass-through files
config.addPassthroughCopy('src/_headers');
config.addPassthroughCopy('src/favicon.ico');
// Everything inside static is copied verbatim to `_site`
config.addPassthroughCopy('src/assets/static');
// BrowserSync Overrides
config.setBrowserSyncConfig({
...config.browserSyncConfig,
// Reload when manifest file changes
files: [manifestPath],
// Show 404 page on invalid urls
callbacks: {
ready: (err, browserSync) => {
browserSync.addMiddleware('*', (req, res) => {
const fourOFour = fs.readFileSync('dist/404.html');
res.writeHead(404, {"Content-Type": "text/html; charset=UTF-8"});
res.write(fourOFour);
res.end();
});
}
},
// Speed/clean up build time
ui: false,
ghostMode: false
});
return {
dir: {
input: 'src',
output: 'dist',
includes: 'includes',
layouts: 'layout',
data: 'data'
},
// Allow nunjucks, markdown and 11ty files to be processed
templateFormats: ['njk', 'md', '11ty.js'],
htmlTemplateEngine: 'njk',
// Allow pre-processing `.md` files with nunjucks
// thus transforming the shortcodes
markdownTemplateEngine: 'njk'
};
};