-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
125 lines (93 loc) · 3.32 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
const Image = require('@11ty/eleventy-img');
const { parse } = require("csv-parse/sync");
const { DateTime } = require('luxon')
const pluginRss = require("@11ty/eleventy-plugin-rss");
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.addDataExtension("csv", (contents) => {
const parsed = parse(contents, {
columns: true,
skip_empty_lines: true,
});
return parsed;
})
eleventyConfig.addShortcode("image", async function (src, alt, sizes) {
let metadata = await Image(src, {
widths: [350, "auto"],
formats: ["webp", "jpeg"],
}, {
outputDir: "_static/img/",
urlPath: "/img/"
});
let imageAttributes = {
alt,
sizes,
loading: "lazy",
decoding: "async",
};
let options = {
outputDir: "_static/img/",
urlPath: "/img/"
}
// You bet we throw an error on a missing alt (alt="" works okay)
return Image.generateHTML(metadata, imageAttributes, options);
})
eleventyConfig.addShortcode("imageAsFile", async function (src, alt) {
let options = {
outputDir: "_static/img/",
urlPath: "/img/"
}
let metadata = await Image(src, {
widths: ["auto"],
formats: ["webp"],
}, options);
fullsize = metadata.webp[0]
return fullsize.outputPath
})
eleventyConfig.addShortcode("galleryImage", async function (src, alt) {
let options = {
outputDir: "_static/img/",
urlPath: "/img/"
}
let metadata = await Image(src, {
widths: [350, "auto"],
formats: ["webp"],
}, options);
thumbnail = metadata['webp'][0]
fullsize = metadata['webp'][1]
return `<a href="${fullsize.url}"
data-pswp-width="${fullsize.width}"
data-pswp-height="${fullsize.height}"
target="_blank">
<img src="${thumbnail.url}" alt="${alt}" />
</a>`
})
eleventyConfig.addFilter('htmlDateString', (dateObj) => {
// dateObj input: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string
return DateTime.fromJSDate(dateObj, { zone: 'utc' }).toFormat('yyyy-LL-dd');
});
eleventyConfig.addFilter("readableDate", (dateObj, format) => {
// Formatting tokens for Luxon: https://moment.github.io/luxon/#/formatting?id=table-of-tokens
return DateTime.fromJSDate(dateObj, { zone: "utc" }).toFormat(format || "yyyy-LL-dd");
});
eleventyConfig.addFilter("limit", function (input_array, limit) {
return input_array.slice(0, limit);
});
eleventyConfig.addPassthroughCopy("img")
eleventyConfig.addPassthroughCopy({
"_static/": "/",
"node_modules/photoswipe/dist/photoswipe-lightbox.esm.min.js": "assets/photoswipe-lightbox.esm.min.js",
"node_modules/photoswipe/dist/photoswipe.esm.min.js": "assets/photoswipe.esm.min.js",
"node_modules/photoswipe/dist/photoswipe.css": "assets/photoswipe.css"
});
return {
dir: {
input: "content",
includes: "../_includes",
data: "../_data",
output: "_site"
}
}
};