forked from hidde/eleventy-wcag-reporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
77 lines (66 loc) · 2.72 KB
/
.eleventy.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
const fs = require('fs')
const path = require('path')
const markdownShortcode = require("eleventy-plugin-markdown-shortcode");
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const scTable = require("./src/_utils/scTable.js");
const sampleImage = require("./src/_utils/sampleImage.js");
const scUri = require("./src/_utils/scUri.js");
const scName = require("./src/_utils/scName.js");
const slugify = require("./src/_utils/slugify.js");
const reportsFolderRelative = 'src/reports';
const reportsFolder = path.join(__dirname, reportsFolderRelative)
const reports = fs.readdirSync(reportsFolder)
.filter(reportName => {
const reportPath = path.join(reportsFolder, reportName)
return fs.existsSync(reportPath) && fs.lstatSync(reportPath).isDirectory()
})
const sanitizeNumber = (numberWithDots) => {
const numberString = numberWithDots.split('.').map(numb => numb = Number(numb) < 10 ? '0' + numb : numb).join('');
return Number(numberString);
}
module.exports = (function(eleventyConfig) {
eleventyConfig.addFilter("sc_uri", scUri);
eleventyConfig.addFilter("sc_name", scName);
eleventyConfig.addFilter("slugify", slugify);
eleventyConfig.addNunjucksShortcode('sc_table', scTable);
eleventyConfig.addNunjucksShortcode('sample_image', sampleImage);
eleventyConfig.addLayoutAlias("report", "report.njk");
eleventyConfig.addPlugin(markdownShortcode);
eleventyConfig.addPlugin(syntaxHighlight);
// create a collection of issues specific to each report, sorted by success criterion
for (let i=0; i < reports.length; i++) {
eleventyConfig.addCollection(reports[i], function (collectionApi) {
return collectionApi
.getFilteredByGlob(`${reportsFolderRelative}/${reports[i]}/**/*.md`)
.filter(item => !(item.data.sc === "none") && !(item.data.sc === undefined))
.sort((a, b) => {
const numbA = sanitizeNumber(a.data.sc);
const numbB = sanitizeNumber(b.data.sc);
if (numbA < numbB) return -1;
if (numbA > numbB) return 1;
return 0;
});
});
}
// create a collection of “tips” specific to each report (all issues with sc set to "none")
for (let i=0; i < reports.length; i++) {
eleventyConfig.addCollection(`${reports[i]}-tips`, function (collectionApi) {
return collectionApi
.getFilteredByGlob(`${reportsFolderRelative}/${reports[i]}/**/*.md`)
.filter(item => (item.data.sc === "none"))
});
}
// Base Config
return {
dir: {
input: "src",
output: "dist",
includes: "_includes",
layouts: "_layouts",
data: "_data"
},
templateFormats: ["njk", "md", "css", "png", "jpg", "svg"],
htmlTemplateEngine: "njk",
markdownTemplateEngine: "njk"
}
});