-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse-pages.js
33 lines (32 loc) · 1006 Bytes
/
parse-pages.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
const fs = require("fs");
const yaml = require("js-yaml");
const glob = require("glob");
const util = require("util");
try {
glob(`./src/assets/pages/**/*.md`, (err, files) => {
if (err) {
console.log(`cannot read the pages folder`, err);
}
const pages = [];
files.forEach((file) => {
let fileContents = fs.readFileSync(file, "utf8");
let page = yaml.load(fileContents.split("---", 2)[1]);
const fragments = file.split("/");
const pagesIndex = fragments.indexOf("pages");
page.fileName = fragments.slice(pagesIndex + 1).join("/");
pages.push(page);
});
fs.writeFileSync(
"./src/app/shared/pages-metas.ts",
"import {PageMeta} from './page-meta';\n" +
"\nexport const pagesMetas: PageMeta[] = "
);
fs.appendFileSync(
"./src/app/shared/pages-metas.ts",
util.inspect(pages, false, 2, false)
);
fs.appendFileSync("./src/app/shared/pages-metas.ts", ";");
});
} catch (e) {
console.log(e);
}