ig-typedoc-theme
Version:
infragistics theme for typedoc API documentation with versioning and localization
53 lines (52 loc) • 2.36 kB
JavaScript
import { cpSync } from "fs";
import path from "path";
import { fileURLToPath } from "url";
import { navigation } from "./partials/navigation.js";
import { index } from "./partials/index.js";
import { memberSources } from "./partials/member.sources.js";
import { memberDeclaration } from "./partials/member.declarations.js";
import { reflectionTemplate } from "./templates/reflection.js";
import { memberSignatureBody } from "./partials/member.signature.body.js";
import { breadcrumb } from "./partials/breadcrumb.js";
import { DefaultTheme, DefaultThemeRenderContext, JSX, RendererEvent, } from "typedoc";
import { defaultLayout } from "./layouts/default.js";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
function bind(fn, first) {
return (...r) => fn(first, ...r);
}
export class IgThemeRenderContext extends DefaultThemeRenderContext {
constructor(theme, page, options) {
super(theme, page, options);
this.reflectionTemplate = bind(reflectionTemplate, this);
this.navigation = bind(navigation, this);
this.index = bind(index, this);
this.memberSources = bind(memberSources, this);
this.memberDeclaration = bind(memberDeclaration, this);
this.memberSignatureBody = bind(memberSignatureBody, this);
this.breadcrumb = bind(breadcrumb, this);
this.defaultLayout = (template, props) => {
return defaultLayout(this, template, props);
};
}
}
export class IgTheme extends DefaultTheme {
_ctx;
constructor(renderer) {
super(renderer);
}
getRenderContext(pageEvent) {
this._ctx ||= new IgThemeRenderContext(this, pageEvent, this.application.options);
return this._ctx;
}
}
export function load(app) {
app.renderer.hooks.on("head.end", (context) => (JSX.createElement("link", { rel: "stylesheet", href: context.relativeURL("assets/css/main.css") })));
app.renderer.hooks.on("body.end", (context) => (JSX.createElement("script", { src: context.relativeURL("assets/common.js") })));
app.renderer.on(RendererEvent.END, () => {
const from = path.resolve(__dirname, "assets");
const to = path.resolve(app.options.getValue("out"), "assets");
cpSync(from, to, { recursive: true });
});
app.renderer.defineTheme("igtheme", IgTheme);
}