-
Notifications
You must be signed in to change notification settings - Fork 1
/
.eleventy.js
48 lines (40 loc) · 1.42 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
const CleanCSS = require("clean-css");
const { EleventyHtmlBasePlugin } = require("@11ty/eleventy");
module.exports = function (eleventyConfig) {
eleventyConfig.addPassthroughCopy("fonts");
eleventyConfig.addPassthroughCopy("**/*.jpg");
eleventyConfig.addFilter("cssmin", function (code) {
return new CleanCSS({}).minify(code).styles;
});
// Filters, custom functions to use in njk templates
eleventyConfig.addFilter("readableDate", (dateObj) => {
dateObj ??= new Date(); // if null or undefined, then create new obj with current time
// Options so date looks like "August 6, 2023"
const dateOptions = {
year: "numeric",
month: "long",
day: "numeric",
};
return dateObj.toLocaleDateString("en-us", {
timeZone: "utc",
...dateOptions,
}); // Use utc tz so that no tz conversion occurs
});
eleventyConfig.addFilter("htmlDateString", (dateObj) => {
dateObj ??= new Date(); // if null or undefined, then create new obj with current time
// Use utc tz so that no tz conversion occurs
// Convert to YYYY/MM/DD, then replace forward slashes with dashes to return YYYY-MM-DD
return dateObj
.toLocaleDateString("en-ZA", { timezone: "utc" })
.replace(/\//g, "-");
});
eleventyConfig.addPlugin(EleventyHtmlBasePlugin);
return {
dir: {
input: "content", // default: "."
includes: "../_includes", // default: "_includes"
data: "../_data", // default: "_data"
output: "_site",
},
};
};