-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patheleventy.config.js
executable file
·141 lines (125 loc) · 4.56 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
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
const util = require('util');
const fs = require('fs');
// Theme Config
const config = require('./src/site/_data/theme.json');
// 11ty Files
const filters = require('./src/utils/filters.js');
const collections = require('./src/utils/collections.js');
const shortcodes = require('./src/utils/shortcodes.js');
//const transforms = require('./src/utils/transforms.js');
// Markdown Plugins
const markdownIt = require('markdown-it');
const markdownItAnchor = require('markdown-it-anchor');
const markdownItAttrs = require('markdown-it-attrs');
const markdownItFootnote = require('markdown-it-footnote');
const markdownItToc = require('markdown-it-table-of-contents');
const markdownItVideo = require('markdown-it-video');
// 11ty Plugins
// const pluginLazyImages = require('eleventy-plugin-lazyimages');
const pluginReadingTime = require('eleventy-plugin-reading-time');
const pluginRss = require('@11ty/eleventy-plugin-rss');
const pluginSyntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight');
module.exports = function (eleventyConfig) {
// Filters
Object.keys(filters).forEach(filterName => {
eleventyConfig.addFilter(filterName, filters[filterName])
});
// Collections
Object.keys(collections).forEach(collectionName => {
eleventyConfig.addCollection(collectionName, collections[collectionName])
});
/**
* Add Shortcodes
* @link https://www.11ty.io/docs/shortcodes/
*/
Object.keys(shortcodes).forEach(shortcodeName => {
eleventyConfig.addShortcode(shortcodeName, shortcodes[shortcodeName])
});
// WIP: Transforms
// Object.keys(transforms).forEach(transformName => {
// eleventyConfig.addTransform(transformName, transforms[transformName])
// });
// Load plugins
// eleventyConfig.addPlugin(pluginLazyImages, {
// imgSelector: 'img', // custom image selector
// placeholderQuality: 75
// });
eleventyConfig.addPlugin(pluginReadingTime);
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(pluginSyntaxHighlight);
eleventyConfig.setDataDeepMerge(true);
// Markdown Parsing
eleventyConfig.setLibrary('md',
markdownIt({
html: true,
breaks: true,
typographer: true
}).use(markdownItAnchor, {
permalink: true,
permalinkSymbol: '#',
permalinkClass: 'bookmark',
permalinkBefore: true,
level: 2
}).use(markdownItAttrs, {
leftDelimiter: '{',
rightDelimiter: '}',
allowedAttributes: []
}).use(markdownItToc, {
containerClass: 'md-toc',
includeLevel: [2, 3, 4, 5, 6],
listType: 'ul',
containerHeaderHtml: '<p class="md-toc-header">Table of Contents</p>'
}).use(markdownItVideo, {
youtube: { width: 640, height: 390 },
vimeo: { width: 500, height: 281 },
vine: { width: 600, height: 600, embed: 'simple' },
prezi: { width: 550, height: 400 }
}).use(markdownItFootnote)
);
// For inline excerpts/TLDRs
const mdRender = new markdownIt({});
eleventyConfig.addFilter('renderMarkdownInline', (rawString) => {
return mdRender.renderInline(rawString);
});
// Prepare assets for production
if (process.env.NODE_ENV === 'production') {
// Minify the html output when building production
eleventyConfig.addTransform('htmlmin', require('./src/utils/htmlmin.js') );
// CSS is handled via postcss-cli in package.json
// JavaScript is handled by terser is package.json
}
// Copy static assests
eleventyConfig.addPassthroughCopy({ 'src/site/_includes/_fonts': 'fonts' });
eleventyConfig.addPassthroughCopy({ 'src/site/_includes/_js': 'js' });
eleventyConfig.addPassthroughCopy('images');
eleventyConfig.addPassthroughCopy('src/site/admin');
eleventyConfig.addPassthroughCopy('src/site/_redirects');
// Browsersync for localhost:8181
eleventyConfig.setBrowserSyncConfig({
callbacks: {
ready: function(err, browserSync) {
const content_404 = fs.readFileSync('dist/404/index.html');
browserSync.addMiddleware("*", (req, res) => {
// Provides the 404 content without redirect.
res.write(content_404);
res.end();
});
},
},
ui: false,
ghostMode: false
});
return {
dir: {
input: 'src/site',
includes: '_includes',
layouts: `_themes/${config.theme}`, // .eleventyignore the rest
data: '_data',
output: 'dist' // the Publish directory
},
passthroughFileCopy: true,
templateFormats : ['njk', 'md', 'html', '11ty.js', 'txt'],
htmlTemplateEngine : 'njk',
markdownTemplateEngine : 'njk',
};
};