-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
110 lines (96 loc) · 3.87 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
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
const cagovBuildSystem = require('@cagov/11ty-build-system');
const markdown = require('./docs/src/11ty/markdown.js');
const htmlTransform = require('./docs/src/11ty/html-transform.js');
const forUnsetComponents = require('./docs/src/11ty/for-unset-components.js');
const fs = require('fs');
module.exports = function (eleventyConfig) {
eleventyConfig.setLibrary('md', markdown);
eleventyConfig.addPlugin(cagovBuildSystem, {
processors: {
sass: {
watch: ['docs/src/css/**/*'],
output: '_site_dist/index.css',
minify: true,
options: {
file: 'docs/src/css/sass/index.scss',
includePaths: ['./src/css/sass'],
},
},
esbuild: [
{
watch: ['docs/src/js/**/*'],
options: {
entryPoints: ['docs/src/js/index.js'],
bundle: true,
minify: true,
outfile: '_site_dist/built.js',
},
},
],
},
});
forUnsetComponents((folder) => eleventyConfig.ignores.add(folder));
eleventyConfig.addFilter('calculateReadabilityGrade', (value) => {
// This readability score grading scale was created with these thresholds intentionally by the ODI content team. These score display values represent the desired values corresponding to the ARI analysis. Using these round numbers is preferable to an equation that returns any integer because it matches hemingwayapp's scoring where grade levels are only returned as whole numbers.
let readabilityScore = 100;
if(value >= 16) { readabilityScore = 0; }
if(value < 16) { readabilityScore = 10; }
if(value < 15) { readabilityScore = 20; }
if(value < 14) { readabilityScore = 30; }
if(value < 13) { readabilityScore = 40; }
if(value < 12) { readabilityScore = 50; }
// there is no slot for a score of 60
if(value < 11) { readabilityScore = 70; }
if(value < 10) { readabilityScore = 80; }
if(value < 9) { readabilityScore = 90; }
if(value < 8) { readabilityScore = 95; }
if(value < 7) { readabilityScore = 100; }
return readabilityScore;
})
eleventyConfig.addFilter('roundNumber', (value) => {
return Math.round(parseFloat(value));
})
eleventyConfig.addFilter('getScoreColor', (value) => {
if(parseInt(value) > 89) {
return 'speedlify-score-good';
}
if(value > 49) {
return 'speedlify-score-ok';
}
return 'speedlify-score-bad'
})
eleventyConfig.addTransform('htmlTransform', htmlTransform);
eleventyConfig.setUseGitIgnore(false);
eleventyConfig.addPassthroughCopy({
'docs/src/assets/illustrations': 'illustrations',
});
eleventyConfig.addPassthroughCopy({ 'docs/src/assets/img': 'img' });
// eleventyConfig.addPassthroughCopy({ 'docs/src/assets/article-content': 'content/img' });
eleventyConfig.addPassthroughCopy({ 'docs/src/assets/papers': 'papers' });
eleventyConfig.addPassthroughCopy({ 'docs/src/css/fonts': 'fonts' });
eleventyConfig.addPassthroughCopy({ '_site_dist/*': '/' });
eleventyConfig.addPassthroughCopy({ '_build_dist/*': 'builds' });
eleventyConfig.addPassthroughCopy({ 'docs/src/assets/papers/bobra-water-1': 'papers/bobra-water-1' });
eleventyConfig.on("eleventy.after", async ({ results }) => {
// Generate map of all HTML files for tests.
const files = results.map((r) => {
const { content, ...paths } = r;
return paths;
});
const htmlFiles = files.filter((p) => p?.outputPath?.endsWith(".html"));
const htmlFileJson = JSON.stringify(htmlFiles, null, 2);
fs.writeFileSync("./_site_dist/allFiles.json", htmlFileJson, "utf8");
});
return {
htmlTemplateEngine: 'njk',
markdownTemplateEngine: 'njk',
templateFormats: ['html', 'njk', '11ty.js', 'md'],
dir: {
input: '.',
output: '_site',
includes: 'docs/site/_includes',
layouts: 'docs/site/_includes/layouts',
data: 'docs/site/_data',
},
};
};