This repository was archived by the owner on May 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
75 lines (62 loc) · 2.26 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
const htmlmin = require("html-minifier");
const CleanCSS = require("clean-css");
require('dotenv').config();
const isProduction = process.env.ELEVENTY_ENV === `production`;
module.exports = function (eleventyConfig) {
eleventyConfig.addGlobalData('env', process.env);
// Let some files pass through to public
eleventyConfig.addPassthroughCopy("./src/robots.txt");
eleventyConfig.addPassthroughCopy("./src/fonts");
eleventyConfig.addFilter("cssmin", function(code) {
return new CleanCSS({}).minify(code).styles;
});
// Return a subset of an array based on attr
eleventyConfig.addFilter("allButCurrent", function (arr, currPage) {
// Filters out current page
const pageArr = arr.filter((page) => page.url !== currPage);
return pageArr;
});
eleventyConfig.addFilter("pluckFromSelection", function (arr, selections, attr) {
return arr.filter((item) => selections.includes(item[attr]));
});
eleventyConfig.addFilter("pluckByValue", function (arr, value, attr) {
return arr.filter((item) => item[attr] === value);
});
eleventyConfig.addFilter("limit", function (arr, limit) {
return arr.slice(0, limit);
});
eleventyConfig.addFilter("slice", function (arr, start) {
return arr.slice(start, arr.length);
});
// Helper to sort pages collection by frontmatter "order"
eleventyConfig.addCollection("orderedPages", function (collection) {
return collection.getFilteredByTag("pages").sort((a, b) => {
return a.data.order - b.data.order;
});
});
// Helper to sort products collection by frontmatter "order"
eleventyConfig.addCollection("orderedProducts", function (collection) {
return collection.getFilteredByTag("products").sort((a, b) => {
return a.data.order - b.data.order;
});
});
// Minify HTML Output
eleventyConfig.addTransform("htmlmin", function(content, outputPath) {
// Eleventy 1.0+: use this.inputPath and this.outputPath instead
if( isProduction && outputPath && outputPath.endsWith(".html") ) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true
});
return minified;
}
return content;
});
return {
dir: {
input: "src",
output: "public",
},
};
};