generated from fluid-project/trivet
-
Notifications
You must be signed in to change notification settings - Fork 1
/
eleventy.config.js
159 lines (141 loc) · 5.63 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
Copyright the Trivet copyright holders.
See the AUTHORS.md file at the top-level directory of this distribution and at
https://github.com/inclusive-design/acaw-cama/raw/main/AUTHORS.md.
Licensed under the New BSD license. You may not use this file except in compliance with this License.
You may obtain a copy of the New BSD License at
https://github.com/inclusive-design/acaw-cama/raw/main/LICENSE.md.
*/
const fluidPlugin = require("eleventy-plugin-fluid");
const navigationPlugin = require("@11ty/eleventy-navigation");
const { EleventyI18nPlugin } = require("@11ty/eleventy");
const pluginPWA = require("eleventy-plugin-pwa-v2");
const brokenLinksPlugin = require("eleventy-plugin-broken-links");
const getYouTubeID = require("get-youtube-id");
const title = require("title");
const slugify = require("@sindresorhus/slugify");
const rosetta = require("rosetta");
const i18n = rosetta();
i18n.locale("en");
for (let lang of ["en", "fr"]) {
i18n.set(lang, require(`./src/_includes/i18n/${lang}.js`));
}
// Import transforms
const parseTransform = require("./src/_transforms/parse-transform.js");
module.exports = (eleventyConfig) => {
eleventyConfig.setUseGitIgnore(false);
// Collections
for (let lang of ["en", "fr"]) {
eleventyConfig.addCollection(`submissions_${lang}`, function (collectionApi) {
return collectionApi.getFilteredByGlob(`src/collections/submissions/${lang}/*.md`).sort(function (a, b) {
return a.data.title.localeCompare(b.data.title);
});
});
eleventyConfig.addCollection(`themes_${lang}`, function (collectionApi) {
return collectionApi.getFilteredByGlob(`src/collections/themes/${lang}/*.md`).sort(function (a, b) {
return a.data.title.localeCompare(b.data.title);
});
});
}
// Filters
eleventyConfig.addFilter("i18n", function (key, langOverride) {
let lang = langOverride || this.page?.lang || this.ctx?.page?.lang || this.context?.environments?.page?.lang;
return i18n.t(key, {}, lang);
});
eleventyConfig.addFilter("titlecase", function (value) {
return title(value, {
special: ["ASL", "LSQ"]
});
});
eleventyConfig.addFilter("youtubeId", function (value) {
return getYouTubeID(value);
});
eleventyConfig.addFilter("englishTitle", function (id) {
const collections = this.ctx?.collections || {};
const submissions = collections.submissions_en || [];
const submission = submissions.find((item) => item.data.id === id);
if (submission) {
return submission.data.title;
}
throw new Error(`Unknown submission ID: "${id}"`);
});
// Shortcodes
eleventyConfig.addShortcode("localizedFormat", function (format, formatLocale, langOverride) {
let lang = langOverride || this.page?.lang || this.ctx?.page?.lang || this.context?.environments?.page?.lang;
return i18n.t(`submission-formats.${format}`, { formatLocale: i18n.t(`languages.${formatLocale}`, {}, lang) }, lang);
});
eleventyConfig.addShortcode("formatUrl", function (submissionId, format, formatLocale) {
const collections = this.ctx?.collections || {};
const submissions = collections.submissions_en || [];
const submission = submissions.find((item) => item.data.id === submissionId);
if (submission) {
let extension;
const slug = slugify(submission.data.title);
switch (format) {
case "slides":
extension = "pptx";
break;
default:
extension = "docx";
}
if (format === "pdf") {
return `https://idrc.cachefly.net/acaw-cama/${submissionId}/${slug}-text-${formatLocale}.pdf`;
}
return `https://idrc.cachefly.net/acaw-cama/${submissionId}/${slug}-${format}-${formatLocale}.${extension}`;
}
throw new Error(`Unknown submission ID: "${submissionId}"`);
});
// Transforms
eleventyConfig.addTransform("parse", parseTransform);
// Passthrough copy
eleventyConfig.addPassthroughCopy({
"src/admin/config.yml": "admin/config.yml"
});
eleventyConfig.addPassthroughCopy({ "src/assets/icons": "/" });
eleventyConfig.addPassthroughCopy({ "src/assets/fonts": "assets/fonts" });
eleventyConfig.addPassthroughCopy({ "src/assets/images": "assets/images" });
eleventyConfig.addPassthroughCopy({
"src/assets/uploads": "assets/uploads"
});
// Plugins
eleventyConfig.addPlugin(brokenLinksPlugin, {
forbidden: "error",
broken: "error",
cacheDuration: "60s",
loggingLevel: 1
});
eleventyConfig.addPlugin(navigationPlugin);
eleventyConfig.addPlugin(EleventyI18nPlugin, {
defaultLanguage: "en"
});
eleventyConfig.addPlugin(fluidPlugin, {
i18n: false
});
eleventyConfig.addPlugin(pluginPWA, {
swDest: "./_site/sw.js",
globDirectory: "./_site",
cacheId: "acaw-cama",
globIgnores: [],
runtimeCaching: [
{
urlPattern: /\/$/,
handler: "NetworkFirst"
},
{
urlPattern: /\.html$/,
handler: "NetworkFirst"
},
{
urlPattern: /^.*\.(jpg|png|mp4|gif|webp|ico|svg|woff2|woff|eot|ttf|otf|ttc|json)$/,
handler: "StaleWhileRevalidate"
}
]
});
return {
dir: {
input: "src"
},
passthroughFileCopy: true,
markdownTemplateEngine: "njk"
};
};