-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy path.eleventy.js
executable file
·62 lines (55 loc) · 1.87 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
const { DateTime } = require("luxon");
const isProduction = process.env.ELEVENTY_ENV === "production";
const htmlnano = require("htmlnano");
const htmlSave = require("htmlnano").presets.safe;
module.exports = function (eleventyConfig) {
// Folders to copy to build dir
eleventyConfig.addPassthroughCopy("src/static");
// Filter to parse dates
eleventyConfig.addFilter("htmlDateString", function (dateObj) {
return DateTime.fromJSDate(dateObj, {
zone: "utc",
}).toFormat("yyyy-LL-dd");
});
// Example Collections
// Filter source file names using a glob
// eleventyConfig.addCollection("posts", function (collectionApi) {
// return collectionApi.getFilteredByGlob("./src/_posts/**/*.md");
// });
// Compress/Minify HTML output on production builds
eleventyConfig.addTransform("compressHTMLOutput", (content, outputPath) => {
const options = {
removeEmptyAttributes: false, // Disable the module "removeEmptyAttributes"
collapseWhitespace: "conservative", // Pass options to the module "collapseWhitespace"
};
// posthtml, posthtml-render, and posthtml-parse options
const postHtmlOptions = {
lowerCaseTags: true, // https://github.com/posthtml/posthtml-parser#options
quoteAllAttributes: false, // https://github.com/posthtml/posthtml-render#options
};
if (outputPath.endsWith(".html") && isProduction) {
return htmlnano
.process(content, options, htmlSave, postHtmlOptions)
.then(function (result) {
return result.html;
})
.catch(function (err) {
console.error(err);
});
}
return content;
});
// This allows Eleventy to watch for file changes during local development.
eleventyConfig.setUseGitIgnore(false);
return {
dir: {
input: "src/",
output: "dist",
includes: "_includes",
layouts: "_layouts",
},
templateFormats: ["html", "md", "njk"],
htmlTemplateEngine: "njk",
passthroughFileCopy: true,
};
};