-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
62 lines (52 loc) · 1.6 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
const CleanCSS = require("clean-css");
const yaml = require("js-yaml");
const Image = require("@11ty/eleventy-img");
const { EleventyHtmlBasePlugin } = require("@11ty/eleventy");
/**
* @template T
* @typedef {{
* [P in keyof T]?:
* T[P] extends (infer U)[] ? RecursivePartial<U>[] :
* T[P] extends object | undefined ? RecursivePartial<T[P]> :
* T[P];
* }} RecursivePartial<T>
*/
/**
* @typedef {import('@11ty/eleventy/src/UserConfig')} EleventyConfig
* @typedef {ReturnType<import('@11ty/eleventy/src/defaultConfig')>} EleventyReturnValue
* @type {(eleventyConfig: EleventyConfig) => RecursivePartial<EleventyReturnValue>}
*/
module.exports = function (config) {
config.addPlugin(EleventyHtmlBasePlugin);
config.addFilter("cssmin", function (code) {
return new CleanCSS({}).minify(code).styles;
});
config.addShortcode("image", async function (src, alt, sizes, style) {
let metadata = await Image(src, {
widths: [300, 600],
formats: ["avif", "jpeg"],
outputDir: "dist/img",
});
let imageAttributes = {
alt,
sizes,
loading: "lazy",
decoding: "async",
style,
};
// You bet we throw an error on a missing alt (alt="" works okay)
return Image.generateHTML(metadata, imageAttributes);
});
config.addPassthroughCopy("assets");
config.addDataExtension("yaml", (contents) => yaml.load(contents));
config.addGlobalData("layout", "base.njk");
return {
dir: {
input: "pages",
includes: "../layouts",
data: "../data",
output: "dist",
},
pathPrefix: process.env.ELEVENTY_PATH_PREFIX,
};
};