-
Notifications
You must be signed in to change notification settings - Fork 0
/
customTheme.mjs
48 lines (41 loc) · 1.41 KB
/
customTheme.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
40
41
42
43
44
45
46
47
48
import { MarkdownTheme, MarkdownThemeContext } from "typedoc-plugin-markdown";
/**
* @param {import('typedoc-plugin-markdown').MarkdownApplication} app
*/
export function load(app) {
app.renderer.defineTheme("customTheme", MyMarkdownTheme);
// adding a separator ensures that gitbook doesn't mark any page that begins with say "## Properties" as
// having the title Properties in the sidebar.
app.renderer.markdownHooks.on("page.begin", ({ page }) => {
// Don't add a separator to the main page, so we can control the title shown in gitbook
if (page.filename.endsWith("/docs/README.md")) {
return;
}
return `***\n`;
});
}
class MyMarkdownTheme extends MarkdownTheme {
getRenderContext(page) {
return new MyMarkdownThemeContext(this, page, this.application.options);
}
// this puts all the docs just inside their module directory, not nested for types, interfaces, etc.
getTemplateMapping(kind) {
const prev = super.getTemplateMapping(kind);
if (!prev) return prev;
prev.directory = ".";
return prev;
}
}
class MyMarkdownThemeContext extends MarkdownThemeContext {
_oldPartials = this.partials;
// customise partials
partials = {
...this.partials,
hierarchy: (model, options) => {
if (model.types[0].qualifiedName.endsWith("Controller")) {
return this._oldPartials.hierarchy(model, options);
}
},
inheritance: () => {},
};
}