-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmetadata-check.mjs
46 lines (39 loc) · 1.3 KB
/
metadata-check.mjs
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
import fs from "fs";
import { v4 as uuidv4 } from "uuid";
import { dirname } from "path";
import parseMD from "parse-md";
import { MeiliSearch } from "meilisearch";
import dotenv from "dotenv";
import process from "process";
dotenv.config();
const fields = ["slug", "title", "pageImg", "description"];
let filesWithError = [];
function readFilesSync(dirname) {
fs.readdirSync(dirname).forEach((filename) => {
if (!fs.lstatSync(dirname + filename).isDirectory()) {
const fileContent = fs.readFileSync(dirname + filename, "utf-8");
if (filename.endsWith(".md") || filename.endsWith(".mdx")) {
const { metadata } = parseMD(fileContent);
fields.forEach((field) => {
if (!metadata.hasOwnProperty(field)) {
console.info(
`${dirname}${filename}: '${field}' field is missing from metadata`
);
filesWithError = [
...filesWithError,
`${filename}: ${field} field is missing fr`,
];
}
});
}
} else {
readFilesSync(dirname + filename + "/");
}
});
}
readFilesSync("./docs/");
if (filesWithError.length > 0) {
console.error(
`Please fix the metadata issue(s). Always include the following meta data fields: 'description', 'title', 'pageImg', 'slug'.`
);
}