-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheleventy.config.js
More file actions
68 lines (59 loc) · 1.93 KB
/
eleventy.config.js
File metadata and controls
68 lines (59 loc) · 1.93 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
import Image from "@11ty/eleventy-img";
import syntaxHighlight from "@11ty/eleventy-plugin-syntaxhighlight";
import path from "path";
const shortcodes = {
image: async function(src, alt, sizes = "(max-width: 669px) 100vw, (min-width: 670) 670px", widths = [700, 1400, 4032]) {
console.log("Processing " + src);
const directory = path.relative("src", path.dirname(src));
const extension = path.extname(src);
let metadata = await Image(src, {
widths: widths,
formats: ["svg", "avif", "webp"],
urlPath: "/" + directory,
outputDir: "./_site/" + directory,
svgShortCircuit: true
});
let imageAttributes = {
alt,
sizes,
loading: "lazy",
decoding: "async",
};
let highsrc = (extension == ".svg") ? metadata.svg.at(-1) : metadata.webp.at(-1);
return `<a href="${highsrc.url}">${Image.generateHTML(metadata, imageAttributes)}</a>`
}
}
const filters = {
formatDate: function(date) {
return new Intl.DateTimeFormat(
'en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
}).format(new Date(date));
},
formatYear: function(date) {
return new Intl.DateTimeFormat(
'en-US', {
year: 'numeric'
}).format(new Date(date));
},
isoDate: function(date) {
return new Date(date).toISOString().split('T')[0]; // Returns YYYY-MM-DD format
}
}
export default function (eleventyConfig) {
eleventyConfig.addPassthroughCopy("src/favicon-32x32.png");
eleventyConfig.addPassthroughCopy("CNAME");
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.addNunjucksAsyncShortcode("image", shortcodes.image);
eleventyConfig.addLiquidShortcode("image", shortcodes.image);
eleventyConfig.addFilter("formatDate", filters.formatDate);
eleventyConfig.addFilter("formatYear", filters.formatYear);
eleventyConfig.addFilter("isoDate", filters.isoDate);
return {
dir: {
input: "src",
},
};
}