11'use strict' ;
22
33import { readFile } from 'node:fs/promises' ;
4- import { extname } from 'node:path' ;
4+ import { relative , sep } from 'node:path/posix ' ;
55
6+ import globParent from 'glob-parent' ;
67import { globSync } from 'tinyglobby' ;
7- import { VFile } from 'vfile' ;
88
99import { STABILITY_INDEX_URL } from './constants.mjs' ;
1010import getConfig from '../../utils/configuration/index.mjs' ;
11+ import { withExt } from '../../utils/file.mjs' ;
1112import { QUERIES } from '../../utils/queries/index.mjs' ;
1213import { getRemark } from '../../utils/remark.mjs' ;
1314
@@ -24,19 +25,19 @@ export async function processChunk(inputSlice, itemIndices) {
2425
2526 const results = [ ] ;
2627
27- for ( const path of filePaths ) {
28+ for ( const [ path , parent ] of filePaths ) {
2829 const content = await readFile ( path , 'utf-8' ) ;
29- const vfile = new VFile ( {
30- path,
31- value : content . replace (
32- QUERIES . stabilityIndexPrefix ,
33- match => `[${ match } ](${ STABILITY_INDEX_URL } )`
34- ) ,
35- } ) ;
30+ const value = content . replace (
31+ QUERIES . stabilityIndexPrefix ,
32+ match => `[${ match } ](${ STABILITY_INDEX_URL } )`
33+ ) ;
34+
35+ const relativePath = sep + withExt ( relative ( parent , path ) ) ;
3636
3737 results . push ( {
38- tree : remarkProcessor . parse ( vfile ) ,
39- file : { stem : vfile . stem , basename : vfile . basename } ,
38+ tree : remarkProcessor . parse ( value ) ,
39+ // The path is the relative path minus the extension
40+ path : relativePath ,
4041 } ) ;
4142 }
4243
@@ -51,9 +52,14 @@ export async function processChunk(inputSlice, itemIndices) {
5152export async function * generate ( _ , worker ) {
5253 const { ast : config } = getConfig ( ) ;
5354
54- const files = globSync ( config . input , { ignore : config . ignore } ) . filter (
55- p => extname ( p ) === '.md'
56- ) ;
55+ const files = config . input . flatMap ( input => {
56+ const parent = globParent ( input ) ;
57+
58+ return globSync ( input , { ignore : config . ignore } ) . map ( child => [
59+ child ,
60+ parent ,
61+ ] ) ;
62+ } ) ;
5763
5864 // Parse markdown files in parallel using worker threads
5965 for await ( const chunkResult of worker . stream ( files ) ) {
0 commit comments