-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patheleventy.config.js
134 lines (113 loc) · 4.73 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
132
133
134
import { randomUUID } from "node:crypto";
import { IdAttributePlugin, RenderPlugin } from "@11ty/eleventy";
import eleventyNavigationPlugin from "@11ty/eleventy-navigation";
import brokenLinksPlugin from "eleventy-plugin-broken-links";
import fluidPlugin from "eleventy-plugin-fluid";
import footnotesPlugin from "eleventy-plugin-footnotes";
import _ from "lodash";
import parse from "./src/_transforms/parse.js";
export default function eleventy(eleventyConfig) {
eleventyConfig.addGlobalData("now", () => new Date());
eleventyConfig.addPlugin(eleventyNavigationPlugin);
eleventyConfig.addPlugin(RenderPlugin);
eleventyConfig.addPlugin(footnotesPlugin);
eleventyConfig.addPlugin(fluidPlugin, {
defaultLanguage: "en",
supportedLanguages: {
en: {
slug: "en",
name: "English"
},
fr: {
slug: "fr",
name: "Français",
dir: "ltr",
uioSlug: "fr"
}
}
});
["en", "fr"].forEach((lang) => {
eleventyConfig.addCollection(`pages_${lang}`, (collection) => {
return collection.getFilteredByGlob(`src/collections/pages/${lang}/*.md`);
});
eleventyConfig.addCollection(`projects_${lang}`, (collection) => {
return collection.getFilteredByGlob(`src/collections/projects/${lang}/*.md`);
});
eleventyConfig.addCollection(`events_${lang}`, (collection) => {
return collection.getFilteredByGlob(`src/collections/events/${lang}/*.md`);
});
eleventyConfig.addCollection(`resources_${lang}`, (collection) => {
return collection.getFilteredByGlob(`src/collections/resources/${lang}/*.md`);
});
eleventyConfig.addCollection(`announcements_${lang}`, (collection) => {
return collection.getFilteredByGlob(`src/collections/announcements/${lang}/*.md`);
});
eleventyConfig.addCollection(`topics_${lang}`, (collection) => {
return collection.getFilteredByGlob(`src/collections/topics/${lang}/*.md`);
});
});
eleventyConfig.addFilter("find", function find(collection = [], key = "", value) {
return collection.find((post) => _.get(post, key) === value);
});
eleventyConfig.addFilter("findTranslation", function find(page, collection = [], lang, desiredLang) {
const expectedFilePathStem = page.filePathStem.replace(lang, desiredLang);
let translationUrl = false;
collection.forEach((el) => {
if (el.filePathStem === expectedFilePathStem) {
translationUrl = el.url;
}
});
return translationUrl;
});
eleventyConfig.addPairedShortcode("disclosure", async function (content, label) {
const contentRenderer = await RenderPlugin.String(content, "md", {});
const renderedContent = await contentRenderer();
const contentId = randomUUID();
return `<inclusive-disclosure>
<button aria-controls="${contentId}">${label}</button>
<div content id="${contentId}">${renderedContent}</div>
</inclusive-disclosure>`;
});
/*
Provide a custom duplicate of eleventy-plugin-fluid's uioInit shortcode in
order to run it without the text-size preference.
*/
eleventyConfig.addShortcode("uioCustomInit", (locale, direction) => {
let options = {
preferences: ["fluid.prefs.lineSpace", "fluid.prefs.textFont", "fluid.prefs.contrast", "fluid.prefs.enhanceInputs"],
auxiliarySchema: {
terms: {
templatePrefix: "/lib/infusion/src/framework/preferences/html",
messagePrefix: "/lib/infusion/src/framework/preferences/messages"
}
},
prefsEditorLoader: {
lazyLoad: true
},
locale: locale,
direction: direction
};
return `<script>fluid.uiOptions.multilingual(".flc-prefsEditor-separatedPanel", ${JSON.stringify(options)});</script>`;
});
eleventyConfig.addTransform("parse", parse);
eleventyConfig.addPassthroughCopy({
"src/admin/config.yml": "admin/config.yml"
});
eleventyConfig.addPassthroughCopy({ "src/assets/fonts": "assets/fonts" });
eleventyConfig.addPlugin(brokenLinksPlugin, {
forbidden: "error",
broken: "error",
cacheDuration: "60s",
loggingLevel: 1,
excludeInputs: ["**/*/*.css"]
});
eleventyConfig.addPlugin(IdAttributePlugin);
return {
dir: {
input: "src"
},
templateFormats: ["njk", "md", "css", "png", "jpg", "svg"],
htmlTemplateEngine: "njk",
markdownTemplateEngine: "njk"
};
}