-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy patheleventy.config.js
112 lines (97 loc) · 3.38 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
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 || "" };
// 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("currentYear", currentYear);
// Passthrough
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,
statsOnly: true,
htmlOptions: {
imgAttributes: {
loading: "lazy",
decoding: "async",
},
},
widths: [320, 640, 960, 1280],
urlFormat: ({ src, format, width }) =>
process.env.NODE_ENV === "production"
? `/images/${width}/${format}/${src.split("/").slice(3).join("/")}`
: `/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, currentYear, navigation },
jsTruthy: true,
strictFilters: true,
});
eleventy.setLiquidParameterParsing("builtin");
// Config
return {
dir: {
input: "src",
output: "www",
layouts: "_layouts",
},
templateFormats: ["css", "liquid", "md", "11ty.js"],
};
}