-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
87 lines (79 loc) · 2.36 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
import { EleventyRenderPlugin, InputPathToUrlTransformPlugin, IdAttributePlugin } from 'npm:@11ty/eleventy';
import { eleventyImageTransformPlugin } from 'npm:@11ty/eleventy-img';
import markdownIt from 'npm:markdown-it';
import miniHtml from 'npm:html-minifier-terser';
import yaml from 'npm:js-yaml';
import { parse as csvParse } from 'csv-parse/sync';
const md = markdownIt({
html: true,
linkify: true,
typographer: true
});
export default function (eleventyConfig) {
eleventyConfig.setDataFileBaseName('root');
eleventyConfig.addPassthroughCopy({ './ournet/assets/': '/' });
eleventyConfig.addPassthroughCopy('./ournet/style.css');
eleventyConfig.addPassthroughCopy('./ournet/print.css');
eleventyConfig.addWatchTarget('./ournet/*.css');
eleventyConfig.setLibrary('md', md);
// Data files //
eleventyConfig.addDataExtension('yaml,yml', contents => yaml.load(contents));
eleventyConfig.addDataExtension('csv', contents => csvParse(contents, {
columns: true,
skip_empty_lines: true
}));
// Plugins //
eleventyConfig.addPlugin(EleventyRenderPlugin);
eleventyConfig.addPlugin(InputPathToUrlTransformPlugin, {
extensions: 'html,liquid,md',
});
eleventyConfig.addPlugin(IdAttributePlugin);
eleventyConfig.addPlugin(eleventyImageTransformPlugin, {
extensions: 'html',
formats: ['webp', 'auto'],
defaultAttributes: {
loading: 'lazy',
decoding: 'async',
sizes: 'auto'
},
outputDir: './www/img/'
});
// Filters //
eleventyConfig.addFilter('markdownify', function (content) {
return md.renderInline(content);
});
eleventyConfig.addFilter('obfuscateEmail', (email) => {
return email.split('').map(function (char) {
return `&#${char.charCodeAt(0)};`;
}).join('');
});
// Production-only //
if (process.env.ELEVENTY_ENV != 'development') {
// Minify output //
eleventyConfig.addTransform(miniHtml, async function (content) {
if ((this.page.outputPath || '').endsWith('.html')) {
const minified = miniHtml.minify(content, {
collapseWhitespace: true,
decodeEntities: true,
minifyCSS: true,
minifyJS: true,
noNewlinesBeforeTagClose: true,
quoteCharacter: "'",
removeComments: true,
sortAttributes: true,
sortClassName: true,
useShortDoctype: true,
});
return minified;
}
return content;
});
}
return {
dir: {
input: 'ournet',
output: 'www',
layouts: '_layouts',
},
};
}