-
Notifications
You must be signed in to change notification settings - Fork 1
/
eleventy.config.js
110 lines (94 loc) · 3.82 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
import { RenderPlugin } from "@11ty/eleventy";
import fetch from "@11ty/eleventy-fetch";
import { eleventyImageTransformPlugin } from "@11ty/eleventy-img";
import syntaxHighlightTransform from "./src/_transforms/syntax-highlight.js";
// Import {$} from 'execa';
import newIssueUrl from "./src/_utils/new-issue-url.js";
export default function eleventy(eleventyConfig) {
eleventyConfig.addShortcode("newIssueUrl", newIssueUrl);
eleventyConfig.addLayoutAlias("report", "report.njk");
eleventyConfig.addGlobalData("successCriteria", async () => {
const url = "https://raw.githubusercontent.com/w3c/wcag/main/guidelines/wcag.json";
try {
const json = await fetch(url, {
duration: "1d",
type: "json"
});
const results = {};
for (const principle of json.principles) {
for (const guideline of principle.guidelines) {
for (const sc of guideline.successcriteria) {
results[sc.num] = {
number: sc.num,
principle: principle.handle,
guideline: guideline.handle,
name: sc.handle,
level: sc.level,
versions: sc.versions,
id: sc.id.replace("WCAG2:", "")
};
}
}
}
return results;
} catch (error) {
console.error(`Fetch failed in successcriteria.js. ${error}`);
}
});
eleventyConfig.addTransform("syntaxHighlight", syntaxHighlightTransform);
eleventyConfig.addPlugin(RenderPlugin);
eleventyConfig.addPlugin(eleventyImageTransformPlugin, {
extensions: "html",
formats: ["webp", "jpeg"],
urlPath: "/assets/images/processed/",
outputDir: "./_site/assets/images/processed/",
defaultAttributes: {
loading: "lazy",
decoding: "async"
}
});
eleventyConfig.addFilter("withoutTips", (issues) => issues.filter((item) => Object.hasOwn(item, "sc") && item.sc !== ""));
eleventyConfig.addFilter("withoutViolations", (issues) => issues.filter((item) => item.sc === "" || !Object.hasOwn(item, "sc")));
eleventyConfig.addAsyncFilter("formatDate", (value) =>
new Date(value).toLocaleString("en-CA", {
year: "numeric",
month: "long",
day: "numeric"
})
);
eleventyConfig.addCollection("reports", (collectionApi) => collectionApi.getFilteredByGlob("src/collections/reports/*.md"));
eleventyConfig.addPassthroughCopy({
"src/admin/config.yml": "admin/config.yml"
});
eleventyConfig.addPassthroughCopy({
"src/assets/fonts": "assets/fonts",
"src/assets/images": "assets/images",
"src/assets/scripts": "assets/scripts",
"src/assets/styles": "assets/styles"
});
eleventyConfig.addPassthroughCopy({
"node_modules/@zachleat/table-saw/table-saw.js": "assets/scripts/table-saw.js"
});
// EleventyConfig.on(
// "eleventy.after",
// async ({ _dir, results, _runMode, _outputMode }) => {
// for (const result of results) {
// if (result.inputPath.startsWith("./src/collections/reports/")) {
// const { stdout } =
// await $`weasyprint --pdf-variant=pdf/ua-1 ${result.outputPath} ./_site${result.url}report.pdf`;
// }
// }
// },
// );
return {
dir: {
input: "src",
includes: "_includes",
layouts: "_layouts",
data: "_data"
},
templateFormats: ["njk", "md", "css", "png", "jpg", "svg"],
htmlTemplateEngine: "njk",
markdownTemplateEngine: "njk"
};
}