-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
.eleventy.js
59 lines (52 loc) · 1.9 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
const pkg = require("./package.json");
const chalk = require("chalk");
const inclusiveLanguage = require("./inclusive-language");
module.exports = {
initArguments: {},
configFunction: function(eleventyConfig, options = {}) {
try {
eleventyConfig.versionCheck(pkg["11ty"].compatibility);
} catch(e) {
console.log( `WARN: Eleventy Plugin (${pkg.name}) Compatibility: ${e.message}` );
}
// TODO move this into default argument when 0.5.5 or newer is released
/* {
words: "simply,obviously,basically,of course,clearly,just,everyone knows,however,easy",
templateFormats: ["md"]
} */
if(!options.words) {
options.words = "simply,obviously,basically,of course,clearly,just,everyone knows,however,easy";
}
if(!options.templateFormats) {
options.templateFormats = ["md"];
}
eleventyConfig.addLinter("inclusive-language", function(content, inputPath, outputPath) {
let words;
if(Array.isArray(options.words)) {
words = options.words;
} else if(typeof options.words === "string") {
words = options.words.split(",");
} else {
throw new Error("Invalid type for options.words (needs string or array) in eleventy-plugin-inclusive-language");
}
if(!Array.isArray(options.templateFormats)) {
throw new Error("Invalid type for options.templateFormats (needs array) in eleventy-plugin-inclusive-language");
}
let checkThisFile = false;
for( let format of options.templateFormats ) {
if( inputPath.endsWith("." + format) ) {
checkThisFile = true;
break;
}
}
if( !checkThisFile ) {
return;
}
let found = inclusiveLanguage(content, words);
if(found.length) {
console.warn(chalk.yellow(`Inclusive Language Linter (${inputPath}):`));
console.warn(" " + found.join("\n" + " "));
}
});
}
};