11'use strict';
22
33import { readFile } from 'node:fs/promises';
4- import { extname } from 'node:path';
4+ import { basename, relative } from 'node:path';
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,20 @@ 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 = 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,
41+ basename: basename(relativePath),
4042 });
4143 }
4244
@@ -51,9 +53,14 @@ export async function processChunk(inputSlice, itemIndices) {
5153export async function* generate(_, worker) {
5254 const { ast: config } = getConfig();
5355
54- const files = globSync(config.input, { ignore: config.ignore }).filter(
55- p => extname(p) === '.md'
56- );
56+ const files = config.input.flatMap(input => {
57+ const parent = globParent(input);
58+
59+ return globSync(input, { ignore: config.ignore }).map(child => [
60+ child,
61+ parent,
62+ ]);
63+ });
5764
5865 // Parse markdown files in parallel using worker threads
5966 for await (const chunkResult of worker.stream(files)) {
0 commit comments