Renamed Files Aren't Tracked in Index.md File
Closed this issue · 2 comments
crutchcorn commented
What package is the bug related to?
typedoc-plugin-markdown
Describe the issue
If I add the following custom plugin:
import { MarkdownPageEvent } from 'typedoc-plugin-markdown'
import path from 'node:path'
/**
* @param {import("typedoc-plugin-markdown").MarkdownApplication} app
*/
export function load(app) {
app.renderer.on(
MarkdownPageEvent.BEGIN,
/**
* @param {import("typedoc-plugin-markdown").MarkdownPageEvent} page
*/
(page) => {
const dirname = path.dirname(page.filename)
const basename = path.basename(page.filename)
const name = basename.split('.')
if (name[0] !== 'index') {
name.splice(0, 1)
}
const newBasename = name.join('.').toLowerCase();
page.filename = path.join(dirname, newBasename)
},
)
}
That I use to rename files to match our needs for TanStack Form, then it will generate the following index.md
file:
# @tanstack/angular-form
## Classes
- [TanStackField](Class.TanStackField.md)
## Functions
- [injectForm](Function.injectForm.md)
- [injectStore](Function.injectStore.md)
Despite the file paths being as such:
index.md
injectform.md
injectstore.md
tanstackfield.md
TypeDoc configuration
Expected behavior
The index.md
paths should match the final output of the file names themselves
tgreyuk commented
@crutchcorn The index.md pages have already been written before the event gets triggered on individual page. You need to update all the urls before the pages start to render.
You can do this with MarkdownRendererEvent.BEGIN
.
Try this:
app.renderer.on(
MarkdownRendererEvent.BEGIN,
/**
* @param {import("typedoc-plugin-markdown").MarkdownRendererEvent} renderer
*/ (renderer) => {
renderer.urls = renderer.urls?.map((urlMapping) => {
const name = urlMapping.url.split(".");
if (name[0] !== "index") {
name.splice(0, 1);
}
const newBasename = name.join(".").toLowerCase();
urlMapping.url = newBasename;
urlMapping.model.url = newBasename;
return urlMapping;
});
}
);
crutchcorn commented
This is awesome, thank you so much for your help!