Skip to content

Commit 808b8d0

Browse files
committed
fix(metadata): preserve api/basename identifiers for root index files
When path is '/' (set by the ast generator for index.md files), the derived api and basename values were empty strings. This broke all downstream generators that rely on api/basename as file identifiers (e.g. legacy-json writing index.json, legacy-json-all skipping the index section, legacy-html writing index.html, etc.). Add an 'index' fallback so that path='/' correctly maps to api='index' and basename='index', matching the pre-existing behavior for those identifiers.
1 parent 9c9c7f9 commit 808b8d0

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/generators/metadata/utils/parse.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ export const parseApiDoc = ({ path, tree }, typeMap) => {
4242
const nodeSlugger = createNodeSlugger();
4343

4444
// Slug the API (We use a non-class slugger, since we are fairly certain that `path` is unique)
45-
const api = slug(path.slice(1).replace(sep, '-'));
45+
// When path is the root ('/'), the file is an index and the api identifier falls back to 'index'
46+
const api = slug(path.slice(1).replace(sep, '-')) || 'index';
4647

4748
// Get all Markdown Footnote definitions from the tree
4849
const markdownDefinitions = selectAll('definition', tree);
@@ -83,7 +84,7 @@ export const parseApiDoc = ({ path, tree }, typeMap) => {
8384
const metadata = /** @type {import('../types').MetadataEntry} */ ({
8485
api,
8586
path,
86-
basename: basename(path),
87+
basename: basename(path) || 'index',
8788
heading: headingNode,
8889
});
8990

0 commit comments

Comments
 (0)