Skip to content

Commit 14923fc

Browse files
committed
Adapt toc extracting to account frontmatter syntax
1 parent bfc905a commit 14923fc

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

scripts/extract-tocs.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
const unified = require("unified");
66
const markdown = require("remark-parse");
7+
const matter = require("gray-matter");
78
const stringify = require("remark-stringify");
89
const slug = require('remark-slug');
910
const glob = require("glob");
@@ -53,7 +54,8 @@ const processor = unified()
5354
.use(headers);
5455

5556
const processFile = filepath => {
56-
const content = fs.readFileSync(filepath, "utf8");
57+
const raw = fs.readFileSync(filepath, "utf8");
58+
const { content, data } = matter(raw);
5759
const result = processor.processSync(content);
5860

5961
const pagesPath = path.resolve("./pages");
@@ -84,7 +86,7 @@ const createTOC = result => {
8486
}, {});
8587
};
8688

87-
const createManualToc = () => {
89+
const createLatestManualToc = () => {
8890
const MD_DIR = path.join(__dirname, "../pages/docs/manual/latest");
8991
const TARGET_FILE = path.join(__dirname, "../index_data/manual_toc.json");
9092

@@ -95,6 +97,17 @@ const createManualToc = () => {
9597
fs.writeFileSync(TARGET_FILE, JSON.stringify(toc), "utf8");
9698
};
9799

100+
const createV800ManualToc = () => {
101+
const MD_DIR = path.join(__dirname, "../pages/docs/manual/v8.0.0");
102+
const TARGET_FILE = path.join(__dirname, "../index_data/manual_v800_toc.json");
103+
104+
const files = glob.sync(`${MD_DIR}/*.md?(x)`);
105+
const result = files.map(processFile);
106+
const toc = createTOC(result);
107+
108+
fs.writeFileSync(TARGET_FILE, JSON.stringify(toc), "utf8");
109+
};
110+
98111
const createReasonCompilerToc = () => {
99112
const MD_DIR = path.join(__dirname, "../pages/docs/reason-compiler/latest");
100113
const TARGET_FILE = path.join(__dirname, "../index_data/reason_compiler_toc.json");
@@ -156,7 +169,8 @@ debugToc();
156169
*/
157170

158171
// main
159-
createManualToc();
172+
createLatestManualToc();
173+
createV800ManualToc();
160174
createReasonCompilerToc();
161175
createReasonReactToc();
162176
createGenTypeToc();

0 commit comments

Comments
 (0)