-
Notifications
You must be signed in to change notification settings - Fork 1
/
eleventy.config.js
85 lines (62 loc) · 2.45 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
require('dotenv').config();
const
{ EleventyHtmlBasePlugin, EleventyRenderPlugin } = require('@11ty/eleventy');
module.exports = (eleventyConfig) => {
// Plugins
eleventyConfig.addPlugin(EleventyHtmlBasePlugin);
eleventyConfig.addPlugin(EleventyRenderPlugin);
eleventyConfig.addGlobalData('fragments', './site/_theme/layouts/fragments');
// Custom Data file formats: yaml
eleventyConfig.addDataExtension("yaml", contents => require("js-yaml").load(contents));
// Filters
require('fast-glob').sync(['./site/_filters/*.js']).forEach(file => {
let filters = require('./' + file);
Object.keys(filters).forEach(name => eleventyConfig.addFilter(name, filters[name]));
});
// Engine & Filter: Markdown
const Markdown = require('markdown-it')({
html: true, // Enable HTML tags in source
breaks: true, // Convert '\n' in paragraphs into <br>
linkify: true, // Autoconvert URL-like text to links
typographer: true, // Enable some language-neutral replacement + quotes beautification
})
.use(require('markdown-it-link-attributes'), {
pattern: /^(https?:)?\/\//,
attrs: {
target: '_blank',
rel: 'noopener'
}
});
eleventyConfig.setLibrary('md', Markdown);
eleventyConfig.addFilter('markdown', content => Markdown.render(String(content)));
// Engine: Nunjucks
eleventyConfig.setNunjucksEnvironmentOptions({ trimBlocks: true, lstripBlocks: true });
eleventyConfig.addPassthroughCopy({ 'site/static/': '.' });
eleventyConfig.addPassthroughCopy({ 'node_modules/@fontsource/sarabun/files/*{latin,thai}-{400,700}*.woff2': 'css/files' });
eleventyConfig.addPassthroughCopy({ 'site/_data/images/': 'images' });
eleventyConfig.setServerPassthroughCopyBehavior('passthrough');
if (process.env.NODE_ENV === 'production') {
eleventyConfig.ignores.add('site/admin.njk');
// Transform : html-minifier
eleventyConfig.addTransform('html-minify', async (content, outputPath) => {
if (outputPath && /(\.html|\.xml)$/.test(outputPath)) {
return require('html-minifier').minify(content, {
useShortDoctype: true,
minifyJS: true,
collapseWhitespace: true,
keepClosingSlash: true
});
}
return content;
});
}
return {
templateFormats: ['md', 'njk'],
markdownTemplateEngine: 'njk',
dir: {
input: './site',
includes: '_theme/layouts',
output: './public'
}
};
};