Skip to content

Commit 4fadd91

Browse files
committed
Add support for automatically loading themes with "typedoc-theme"
1 parent 3b5174e commit 4fadd91

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
- TypeDoc will now detect and warn if multiple instances of the package are loaded. This usually means that a plugin has its own version of TypeDoc installed, which will lead to things breaking in unexpected ways.
66
It will only work if both loaded TypeDocs are v0.22.9 or later.
7+
- TypeDoc will now automatically load packages with `typedoctheme` or `typedoc-theme` in their keywords.
8+
Plugins which define a custom theme should include this keyword so that they can be automatically collected and displayed at https://typedoc.org/guides/themes/.
79

810
### Bug Fixes
911

src/lib/application.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
CallbackLogger,
1212
loadPlugins,
1313
writeFile,
14-
discoverNpmPlugins,
14+
discoverPlugins,
1515
NeverIfInternal,
1616
TSConfigReader,
1717
} from "./utils/index";
@@ -135,9 +135,7 @@ export class Application extends ChildableComponent<
135135
}
136136
this.logger.level = this.options.getValue("logLevel");
137137

138-
const plugins = this.options.isSet("plugin")
139-
? this.options.getValue("plugin")
140-
: discoverNpmPlugins(this);
138+
const plugins = discoverPlugins(this);
141139
loadPlugins(this, plugins);
142140

143141
this.options.reset();

src/lib/utils/general.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export type NeverIfInternal<T> = IfInternal<never, T>;
4141
const loadSymbol = Symbol.for("typedoc_loads");
4242
const getLoads = () => globalThis[loadSymbol as never] || 0;
4343

44-
// @ts-expect-error
44+
// @ts-expect-error there's no way to add symbols to globalThis, sadly.
4545
globalThis[loadSymbol] = getLoads() + 1;
4646

4747
export function hasBeenLoadedMultipleTimes() {

src/lib/utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export type {
4848
TypeDocOptionValues,
4949
ParameterTypeToOptionTypeMap,
5050
} from "./options";
51-
export { discoverNpmPlugins, loadPlugins } from "./plugins";
51+
export { discoverPlugins, loadPlugins } from "./plugins";
5252
export { sortReflections } from "./sort";
5353
export type { SortStrategy } from "./sort";
5454

src/lib/utils/plugins.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ export function loadPlugins(app: Application, plugins: readonly string[]) {
3737
}
3838
}
3939

40-
export function discoverNpmPlugins(app: Application): string[] {
40+
export function discoverPlugins(app: Application): string[] {
41+
// If the plugin option is set, then automatic discovery is disabled, and we should just
42+
// return the plugins that the user has asked for.
43+
if (app.options.isSet("plugin")) {
44+
return app.options.getValue("plugin");
45+
}
46+
4147
const result: string[] = [];
4248
discover();
4349
return result;
@@ -100,6 +106,13 @@ function loadPackageInfo(logger: Logger, fileName: string): any {
100106
}
101107
}
102108

109+
const PLUGIN_KEYWORDS = [
110+
"typedocplugin",
111+
"typedoc-plugin",
112+
"typedoctheme",
113+
"typedoc-theme",
114+
];
115+
103116
/**
104117
* Test whether the given package info describes a TypeDoc plugin.
105118
*/
@@ -116,7 +129,7 @@ function isPlugin(info: any): boolean {
116129
return keywords.some(
117130
(keyword) =>
118131
typeof keyword === "string" &&
119-
keyword.toLocaleLowerCase() === "typedocplugin"
132+
PLUGIN_KEYWORDS.includes(keyword.toLocaleLowerCase())
120133
);
121134
}
122135

0 commit comments

Comments
 (0)