-
Notifications
You must be signed in to change notification settings - Fork 6
/
lint-content.js
48 lines (41 loc) · 1019 Bytes
/
lint-content.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
import { readdir } from "fs/promises";
import vfile from "to-vfile";
import report from "vfile-reporter";
import unified from "unified";
import parse from "remark-parse";
import stringify from "remark-stringify";
import remark2retext from "remark-retext";
import english from "retext-english";
import passive from "retext-passive";
import readability from "retext-readability";
const source = "./content";
const analyzer = unified()
.use(parse)
.use(
remark2retext,
unified()
.use(english)
.use(passive)
.use(readability, {
age: 20,
threshold: 4 / 7,
}),
)
.use(stringify);
const main = async () => {
const files = await readdir(source);
let errored = false;
await Promise.all(files.map(async (path) => {
const content = await vfile.read(`${source}/${path}`);
analyzer.process(content, (error, file) => {
if (error) {
console.error(report(error));
errored = true;
} else {
console.log(report(file));
}
});
}));
if (errored) process.exit(1);
};
main();