-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy patheleventy.config.js
131 lines (115 loc) · 3.84 KB
/
eleventy.config.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
126
127
128
129
130
131
import { readFile } from "node:fs/promises";
import process from "node:process";
import "dotenv/config";
import { EleventyRenderPlugin } from "@11ty/eleventy";
import { eleventyImageTransformPlugin } from "@11ty/eleventy-img";
import eleventySyntaxHighlight from "@11ty/eleventy-plugin-syntaxhighlight";
import eleventyLightningCss from "@11tyrocks/eleventy-plugin-lightningcss";
import * as collections from "./lib/collections/index.js";
import * as filters from "./lib/filters/index.js";
import * as shortcodes from "./lib/shortcodes/index.js";
import * as transforms from "./lib/transforms/index.js";
import { markdownParser } from "./lib/markdown.js";
import navigation from "./src/_data/navigation.js";
// Can’t use import attributes until supported by Acorn dependency
// See: https://github.com/11ty/eleventy/issues/3128
let appJson = await readFile(new URL(`src/app.json`, import.meta.url));
let app = JSON.parse(appJson.toString());
app = { ...app, url: process.env.URL || "" };
// Authorship
const author = {
avatar: "/.well-known/avatar.png",
email: "reply@paulrobertlloyd.com",
name: app.name,
url: app.url,
};
// Get current year
const currentYear = new Date().getFullYear();
/**
* Get Eleventy configuration
* @param {object} eleventy - Eleventy configuration
* @returns {object} Updated Eleventy configuration
*/
// eslint-disable-next-line unicorn/no-anonymous-default-export
export default function (eleventy) {
// Collections
for (const [name, collection] of Object.entries(collections)) {
eleventy.addCollection(name, collection);
}
// Extensions
eleventy.addTemplateFormats("markdown");
eleventy.addExtension("markdown", { key: "md" });
// Filters
for (const [name, filter] of Object.entries(filters)) {
eleventy.addFilter(name, filter);
}
// Global data
eleventy.addGlobalData("app", app);
eleventy.addGlobalData("author", author);
eleventy.addGlobalData("currentYear", currentYear);
// Passthrough
eleventy.addPassthroughCopy({
"./src/assets/avatar.png": ".well-known/avatar.png",
});
eleventy.addPassthroughCopy({ "./src/content/media": "media" });
eleventy.addPassthroughCopy({ "./src/app.json": "app.webmanifest" });
eleventy.addPassthroughCopy("./src/robots.txt");
eleventy.addPassthroughCopy("./src/assets");
// Plugins
eleventy.addPlugin(eleventyImageTransformPlugin, {
failOnError: false,
htmlOptions: {
imgAttributes: {
loading: "lazy",
decoding: "async",
},
},
statsOnly: true,
...(process.env.NODE_ENV === "production"
? {
formats: ["webp", "jpeg"],
widths: [320, 640, 960, 1280],
urlFormat: ({ src, format, width }) =>
`/images/${width}/${format}/${src.split("/").slice(3).join("/")}`,
}
: {
formats: ["auto"],
widths: ["auto"],
urlFormat: ({ src }) => `/media/${src.split("/").slice(3).join("/")}`,
}),
});
eleventy.addPlugin(EleventyRenderPlugin);
eleventy.addPlugin(eleventySyntaxHighlight);
eleventy.addPlugin(eleventyLightningCss);
// Shortcodes
for (const [name, shortcode] of Object.entries(shortcodes)) {
eleventy.addShortcode(name, shortcode);
}
// Transforms
if (process.env.NODE_ENV === "production") {
for (const [name, transform] of Object.entries(transforms)) {
eleventy.addTransform(name, transform);
}
}
// Folder data
eleventy.setDataFileBaseName("_data");
// Libraries
eleventy.setLibrary("md", markdownParser);
// Liquid
eleventy.setLiquidOptions({
cache: true,
globals: { app, author, currentYear, navigation },
jsTruthy: true,
strictFilters: true,
});
eleventy.setLiquidParameterParsing("builtin");
// Config
return {
dir: {
input: "src",
output: "www",
layouts: "_layouts",
},
templateFormats: ["css", "liquid", "md", "11ty.js"],
};
}