11'use strict' ;
22
3- import { readFile } from 'node:fs/promises' ;
43import { extname } from 'node:path' ;
54
65import { globSync } from 'glob' ;
7- import { VFile } from 'vfile' ;
86
9- import createQueries from '../../utils/queries/index .mjs' ;
7+ import createLoader from '../../loaders/markdown .mjs' ;
108import { getRemark } from '../../utils/remark.mjs' ;
119
12- const remarkProcessor = getRemark ( ) ;
13-
14- const { updateStabilityPrefixToLink } = createQueries ( ) ;
15-
16- /**
17- * Parses a single markdown file into an AST.
18- *
19- * @param {string } filePath - Path to the markdown file
20- * @returns {Promise<ParserOutput<import('mdast').Root>> }
21- */
22- const parseMarkdownFile = async filePath => {
23- const fileContents = await readFile ( filePath , 'utf-8' ) ;
24-
25- const vfile = new VFile ( { path : filePath , value : fileContents } ) ;
10+ const { loadFiles } = createLoader ( ) ;
2611
27- // Normalizes all the Stability Index prefixes with Markdown links
28- updateStabilityPrefixToLink ( vfile ) ;
29-
30- // Parses the API doc into an AST tree using `unified` and `remark`
31- const tree = remarkProcessor . parse ( vfile ) ;
32-
33- return { file : { stem : vfile . stem , basename : vfile . basename } , tree } ;
34- } ;
12+ const remarkProcessor = getRemark ( ) ;
3513
3614/**
3715 * This generator parses Markdown API doc files into AST trees.
@@ -57,15 +35,17 @@ export default {
5735 * @returns {Promise<Array<ParserOutput<import('mdast').Root>>> }
5836 */
5937 async processChunk ( inputSlice , itemIndices ) {
60- const results = [ ] ;
38+ const filePaths = itemIndices . map ( idx => inputSlice [ idx ] ) ;
6139
62- for ( const idx of itemIndices ) {
63- const parsed = await parseMarkdownFile ( inputSlice [ idx ] ) ;
40+ const vfiles = await Promise . all ( loadFiles ( filePaths ) ) ;
6441
65- results . push ( parsed ) ;
66- }
42+ return vfiles . map ( vfile => {
43+ const tree = remarkProcessor . parse ( vfile ) ;
44+
45+ const minimalVfile = { stem : vfile . stem , basename : vfile . basename } ;
6746
68- return results ;
47+ return { file : minimalVfile , tree } ;
48+ } ) ;
6949 } ,
7050
7151 /**
0 commit comments