Skip to content

Instantly share code, notes, and snippets.

@jgke
Created March 24, 2024 09:38
Show Gist options
  • Save jgke/dab922b1d2b3cb5f2b98043edcbb140f to your computer and use it in GitHub Desktop.
Save jgke/dab922b1d2b3cb5f2b98043edcbb140f to your computer and use it in GitHub Desktop.
Show TypeDoc namespace members on the same page
// filename: ./typedoc-theme/index.ts
// compile with:
// npx tsc --target esnext --module commonjs --moduleresolution node --esmoduleinterop index.ts
import { Application, DeclarationReflection, DefaultTheme, ReflectionKind, UrlMapping } from 'typedoc';
export class Theme extends DefaultTheme {
buildUrls(reflection: DeclarationReflection, urls: UrlMapping[]): UrlMapping[] {
if (reflection.kind === ReflectionKind.Project) return super.buildUrls(reflection, urls);
if (reflection.kind === ReflectionKind.Namespace || reflection.kind === ReflectionKind.Module) {
const mapping = super['getMapping'](reflection);
if (!reflection.url || !DefaultTheme.URL_PREFIX.test(reflection.url)) {
const url = [mapping.directory, DefaultTheme.getUrl(reflection) + '.html'].join('/');
urls.push(new UrlMapping(url, reflection, mapping.template));
reflection.url = url;
reflection.hasOwnDocument = true;
}
reflection.traverse((child) => {
DefaultTheme.applyAnchorUrl(child, reflection);
});
return super.buildUrls(reflection, urls);
}
return urls;
}
}
export function load(app: Application) {
app.renderer.defineTheme('mydefault', Theme);
}
{
"entryPoints": ["src"],
"entryPointStrategy": "expand",
"out": "docs",
"plugin": ["./typedoc-theme/index.js"],
"theme": "mydefault"
}
@jgke
Copy link
Author

jgke commented Mar 24, 2024

The buildUrls function is mostly equivalent to https://github.com/TypeStrong/typedoc/blob/30e614cd9e7b5a154afa6a78f2e54f16550bfb4f/src/lib/output/themes/default/DefaultTheme.tsx#L222

The original function is licensed under Apache 2. Any modifications done are under CC0 https://creativecommons.org/public-domain/cc0/ -- feel free to use as you see fit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment