-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify-blog-content-headings.mjs
More file actions
58 lines (50 loc) · 1.16 KB
/
verify-blog-content-headings.mjs
File metadata and controls
58 lines (50 loc) · 1.16 KB
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
import { getBlogSourceEntries, scanMarkdownH1s } from './blog-heading-utils.mjs';
const failures = [];
const results = [];
function main() {
const entries = getBlogSourceEntries();
for (const entry of entries) {
const headings = scanMarkdownH1s(entry.body, entry.bodyStartLine);
if (headings.length === 0) {
results.push({ file: entry.relativePath, status: 'pass' });
continue;
}
failures.push({
file: entry.relativePath,
status: 'fail',
headings: headings.map((heading) => ({
line: heading.line,
text: heading.text,
duplicatesTitle: heading.text === entry.title,
})),
});
}
const summary = {
status: failures.length === 0 ? 'pass' : 'fail',
totals: {
files: results.length + failures.length,
passed: results.length,
failed: failures.length,
},
failures,
};
console.log(JSON.stringify(summary, null, 2));
if (failures.length > 0) {
process.exit(1);
}
}
try {
main();
} catch (error) {
console.error(
JSON.stringify(
{
status: 'fail',
error: error.message,
},
null,
2,
),
);
process.exit(1);
}