-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.eleventy.js
120 lines (98 loc) · 3.51 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
const yaml = require("js-yaml");
const htmlmin = require("html-minifier");
const eleventySass = require("eleventy-sass");
const MarkdownIt = require("markdown-it");
const markdownItAnchor = require("markdown-it-anchor");
const markdownItToc = require("markdown-it-table-of-contents");
const postcss = require("postcss");
const atImport = require("postcss-import");
const postCssMinify = require("postcss-minify");
const { EleventyI18nPlugin } = require("@11ty/eleventy");
const i18n = require('eleventy-plugin-i18n');
const translations = require('./src/_data/i18n');
const helpers = require('./eleventy-helpers');
module.exports = function (eleventyConfig) {
// ADD DELAY BEFORE RE-RUNNING
eleventyConfig.setWatchThrottleWaitTime(1000);
eleventyConfig.addPlugin(EleventyI18nPlugin, {
defaultLanguage: "en",
errorMode: "never", //"allow-fallback",
});
eleventyConfig.addPlugin(i18n, {
translations,
fallbackLocales: {
'*': 'en'
}
});
// Disable automatic use of your .gitignore
eleventyConfig.setUseGitIgnore(false);
// Merge data instead of overriding
eleventyConfig.setDataDeepMerge(true);
// human readable date
eleventyConfig.addFilter("readableDate", helpers.readableDateFilter);
eleventyConfig.addFilter("limitTo", helpers.limitToFilter);
eleventyConfig.addFilter("tidyHTML", helpers.tidyHTMLFilter);
eleventyConfig.addFilter("cloudinaryFilter", helpers.cloudinaryFilter);
eleventyConfig.addFilter("langFilter", helpers.langFilter);
const markdown = new MarkdownIt({
html: true,
});
eleventyConfig.setLibrary("md", markdown);
eleventyConfig.addFilter("markdown", helpers.markdownFilter);
// To Support .yaml Extension in _data
// You may remove this if you can use JSON
eleventyConfig.addDataExtension("yaml", (contents) => yaml.load(contents));
// Copy Static Files to /_Site
eleventyConfig.addPassthroughCopy({
"./src/admin/config.yml": "./admin/config.yml",
});
// Prepare Admin Live Preview templates
eleventyConfig.addPassthroughCopy({
"./src/admin/preview-templates/": "./admin/templates/",
"./src/_includes/": "./admin/templates/",
});
// scss
eleventyConfig.addPlugin(eleventySass, {
postcss: postcss([atImport, postCssMinify])
});
// Copy Image Folder to /_site
eleventyConfig.addPassthroughCopy("./src/static/img");
eleventyConfig.addPassthroughCopy("./src/static/js");
eleventyConfig.addPassthroughCopy("./src/static/fonts");
// Copy favicon to route of /_site
eleventyConfig.addPassthroughCopy("./src/static/img/favicon.ico");
eleventyConfig.addPassthroughCopy("./src/robots.txt");
// Minify HTML
eleventyConfig.addTransform("htmlmin", function (content, outputPath) {
// Eleventy 1.0+: use this.inputPath and this.outputPath instead
if (outputPath.endsWith(".html")) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true,
});
return minified;
}
return content;
});
eleventyConfig.addFilter("jsbundle", (code) => {
require('fs').writeFileSync('in.js', code)
require('esbuild').buildSync({
entryPoints: ['in.js'],
outfile: 'out.js',
minify: true,
bundle: true,
})
const bundle = require('fs').readFileSync('out.js', 'utf8')
return bundle
})
// Let Eleventy transform HTML files as nunjucks
// So that we can use .html instead of .njk
return {
dir: {
input: "src",
},
htmlTemplateEngine: "njk",
markdownTemplateEngine: "njk",
};
};