4
4
*/
5
5
const unified = require ( "unified" ) ;
6
6
const markdown = require ( "remark-parse" ) ;
7
+ const matter = require ( "gray-matter" ) ;
7
8
const stringify = require ( "remark-stringify" ) ;
8
9
const slug = require ( 'remark-slug' ) ;
9
10
const glob = require ( "glob" ) ;
@@ -53,7 +54,8 @@ const processor = unified()
53
54
. use ( headers ) ;
54
55
55
56
const processFile = filepath => {
56
- const content = fs . readFileSync ( filepath , "utf8" ) ;
57
+ const raw = fs . readFileSync ( filepath , "utf8" ) ;
58
+ const { content, data } = matter ( raw ) ;
57
59
const result = processor . processSync ( content ) ;
58
60
59
61
const pagesPath = path . resolve ( "./pages" ) ;
@@ -84,7 +86,7 @@ const createTOC = result => {
84
86
} , { } ) ;
85
87
} ;
86
88
87
- const createManualToc = ( ) => {
89
+ const createLatestManualToc = ( ) => {
88
90
const MD_DIR = path . join ( __dirname , "../pages/docs/manual/latest" ) ;
89
91
const TARGET_FILE = path . join ( __dirname , "../index_data/manual_toc.json" ) ;
90
92
@@ -95,6 +97,17 @@ const createManualToc = () => {
95
97
fs . writeFileSync ( TARGET_FILE , JSON . stringify ( toc ) , "utf8" ) ;
96
98
} ;
97
99
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
+
98
111
const createReasonCompilerToc = ( ) => {
99
112
const MD_DIR = path . join ( __dirname , "../pages/docs/reason-compiler/latest" ) ;
100
113
const TARGET_FILE = path . join ( __dirname , "../index_data/reason_compiler_toc.json" ) ;
@@ -156,7 +169,8 @@ debugToc();
156
169
*/
157
170
158
171
// main
159
- createManualToc ( ) ;
172
+ createLatestManualToc ( ) ;
173
+ createV800ManualToc ( ) ;
160
174
createReasonCompilerToc ( ) ;
161
175
createReasonReactToc ( ) ;
162
176
createGenTypeToc ( ) ;
0 commit comments