-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
73 lines (65 loc) · 2.7 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
const { EleventyI18nPlugin } = require("@11ty/eleventy");
const pluginRss = require("@11ty/eleventy-plugin-rss");
const CleanCSS = require("clean-css");
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const htmlmin = require("html-minifier");
module.exports = function (eleventyConfig) {
eleventyConfig.addWatchTarget("./src/sass/");
eleventyConfig.addPassthroughCopy("./src/js"); // All files is "src/js" are copied as such in "public/js"
eleventyConfig.addPassthroughCopy("./src/img"); // All files is "src/img" are copied as such in "public/img"
eleventyConfig.addPassthroughCopy("./src/_redirects"); // _redirects file is copied as such in "public/"
eleventyConfig.addShortcode("shortcodes", function () {
this.page
});
eleventyConfig.addPlugin(EleventyI18nPlugin, {
// any valid BCP 47-compatible language tag is supported
defaultLanguage: "en", // Required, this site uses "en"
errorMode: "allow-fallback", // only throw an error when the content is missing at both /en/slug and /slug
});
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(syntaxHighlight, {
preAttributes: {
tabindex: 0,
},
});
// Prism and Chota define a tag class. This leads to styling conflicts
// So we replace .tag in Chota with .chip.
eleventyConfig.addFilter("tagtochip", function (css) {
return css.replaceAll('.tag', '.chip');
});
// Minify CSS code
eleventyConfig.addFilter("cssmin", function (css) {
return new CleanCSS({}).minify(css).styles;
});
// Convert date string into a local date string
eleventyConfig.addFilter("localdate", function (dateString) {
const date = new Date(dateString);
return date.toLocaleDateString();
});
// Convert de date string into a ISO date string i.e. 1977-04-22T06:00:00
eleventyConfig.addFilter("isodate", function (dateString) {
const date = new Date(dateString).toISOString();
return date.substring(0, date.lastIndexOf('.'));
});
// Minify HTML
eleventyConfig.addTransform("htmlmin", function (content) {
if (this.page.outputPath && this.page.outputPath.endsWith(".html")) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true
});
return minified;
}
return content;
});
return {
htmlTemplateEngine: "njk", // Forces the use of Nunjucks templates
markdownTemplateEngine: "njk",
dir: {
input: "src",
output: "public",
},
pathPrefix: ""
};
};