-
Notifications
You must be signed in to change notification settings - Fork 85
/
custom-frontmatter.mjs
39 lines (35 loc) · 1 KB
/
custom-frontmatter.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// @ts-check
import { MarkdownPageEvent } from 'typedoc-plugin-markdown';
/**
* @param {import('typedoc-plugin-markdown').MarkdownApplication} app
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
export function load(app) {
app.renderer.on(
MarkdownPageEvent.BEGIN,
(page) => {
/**
* Update page.frontmatter object using information from the page model
*
* Here if the page is a class, we set the title to the class name
*/
page.frontmatter = {
// e.g add a title
title: page.model?.name,
// spread the existing frontmatter
...page.frontmatter,
};
},
);
app.renderer.on(
MarkdownPageEvent.END,
(page) => {
page.contents = replaceAndFormat(page.contents)
},
);
}
const replaceAndFormat = (text) => {
text = text.replace(/\/[A-Za-z]+\.md/g, (match) => match.toLowerCase().replace('.md', ''));
text = text.replaceAll('(../', '(/apidocs/');
return text
};