forked from anza-xyz/kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypedoc.plugin.mjs
More file actions
24 lines (22 loc) · 832 Bytes
/
Copy pathtypedoc.plugin.mjs
File metadata and controls
24 lines (22 loc) · 832 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// @ts-check
import { dirname, resolve } from 'node:path';
import * as td from 'typedoc-plugin-markdown';
/** @param {td.MarkdownApplication} app */
export function load(app) {
// Set Markdown frontmatter for each page
app.renderer.on(td.MarkdownPageEvent.BEGIN, page => {
page.frontmatter = {
title: page.model.name,
};
});
// Rewrite all of the internal links
// - root relative for compatibility with Next.js
// - strip the .mdx extension
app.renderer.on(td.MarkdownPageEvent.END, page => {
if (!page.contents) return;
page.contents = page.contents.replace(/\(((?:[^\/\)]+\/)*[^\/\)]+)\.mdx\)/gm, (_, path) => {
const rootRelativeUrl = resolve('/api', dirname(page.url), path);
return `(${rootRelativeUrl})`;
});
});
}