-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.eleventy.js
More file actions
84 lines (74 loc) · 2.54 KB
/
Copy path.eleventy.js
File metadata and controls
84 lines (74 loc) · 2.54 KB
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
const htmlmin = require("html-minifier-terser");
module.exports = function (eleventyConfig) {
// Use Nunjucks as template engine for HTML files (not Liquid)
// eleventyConfig.setHtmlTemplateEngine("njk"); // TODO
// This makes the Eleventy command quieter (with less detail)
eleventyConfig.setQuietMode(true);
// This will stop the default behaviour of foo.html files being turned into foo/index.html files
eleventyConfig.addGlobalData("permalink", "{{ page.filePathStem }}.html");
// This will make Eleventy not use your .gitignore file to ignore files
eleventyConfig.setUseGitIgnore(false);
// This will copy these folders to the output without modifying them at all
eleventyConfig.addPassthroughCopy("assets/img");
eleventyConfig.addPassthroughCopy("content/layout-generator/test");
// This defines which files will be copied
eleventyConfig.setTemplateFormats([
"html",
"njk",
"txt",
"js",
"css",
"xml",
"json",
]);
// Custom Filter
eleventyConfig.addFilter("prepareImageUrl", function (str) {
if (str.includes("://")) return str;
return "../assets/img/links/websites/" + str;
});
eleventyConfig.addFilter("recTurnToClasses", function (str) {
if (!str) return "";
return str.toLowerCase().replaceAll(" ", "").replaceAll(",", " ");
});
eleventyConfig.addFilter("recTurnToDecade", function (str) {
if (!str) return "";
const year = parseInt(str);
if (year > 1980) {
const decade = Math.floor(year / 10) * 10;
return ("" + decade).replace("19", "") + "s";
}
if (year >= 1950) return "1950-79";
if (year >= 1900) return "1900-49";
return "1800s";
});
eleventyConfig.addFilter("sortByTerm", function (arr) {
// console.log("Sort filter called with:", arr); // SHOWS IN CONSOLE
return arr.slice().sort((a, b) => a.term.localeCompare(b.term));
});
eleventyConfig.addFilter("removeSpaces", function (str) {
return str.replace(/\s+/g, "");
});
// Minify HTML
eleventyConfig.addTransform("htmlmin", function (content) {
if ((this.page.outputPath || "").endsWith(".html")) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true,
});
return minified;
}
return content;
});
// This defines the input and output directories
return {
// This makes sure HTML files use Nunjucks
htmlTemplateEngine: "njk",
dir: {
input: "content",
output: "public",
},
};
};