Skip to content

Commit

Permalink
fix: define slug as '/' when out = '.'
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Nov 27, 2021
1 parent 1271fdf commit f22f049
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/docusaurus-plugin-typedoc/src/options.ts
Expand Up @@ -17,6 +17,7 @@ const DEFAULT_PLUGIN_OPTIONS: PluginOptions = {
entryDocument: 'index.md',
plugin: ['none'],
watch: false,
indexSlug: undefined,
};

export const getPluginOptions = (
Expand Down
4 changes: 4 additions & 0 deletions packages/docusaurus-plugin-typedoc/src/render.ts
Expand Up @@ -62,6 +62,10 @@ const addTypedocDeclarations = (app: Application) => {
name: 'readmeTitle',
} as StringDeclarationOption);

app.options.addDeclaration({
name: 'indexSlug',
} as StringDeclarationOption);

app.options.addDeclaration({
name: 'sidebar',
type: ParameterType.Mixed,
Expand Down
18 changes: 14 additions & 4 deletions packages/docusaurus-plugin-typedoc/src/theme.ts
Expand Up @@ -37,6 +37,9 @@ export class DocusaurusTheme extends MarkdownTheme {
@BindOption('readmeTitle')
readmeTitle!: string;

@BindOption('indexSlug')
indexSlug!: string;

constructor(renderer: Renderer) {
super(renderer);

Expand Down Expand Up @@ -94,10 +97,7 @@ export class DocusaurusTheme extends MarkdownTheme {
title: pageTitle,
};
if (page.url === this.entryDocument) {
items = {
...items,
slug: `/${path.relative(process.cwd(), this.out).replace(/\\/g, '/')}/`,
};
items = { ...items, slug: this.getSlug() };
}
if (sidebarLabel && sidebarLabel !== pageTitle) {
items = { ...items, sidebar_label: sidebarLabel as string };
Expand Down Expand Up @@ -157,6 +157,16 @@ export class DocusaurusTheme extends MarkdownTheme {
return getPageTitle(page);
}

getSlug() {
if (this.indexSlug) {
return this.indexSlug;
}
if (this.out === process.cwd()) {
return '/';
}
return `/${path.relative(process.cwd(), this.out).replace(/\\/g, '/')}/`;
}

get mappings() {
return super.mappings.map((mapping) => {
if (mapping.kind.includes(ReflectionKind.Namespace)) {
Expand Down
1 change: 1 addition & 0 deletions packages/docusaurus-plugin-typedoc/src/types.ts
Expand Up @@ -14,6 +14,7 @@ export interface PluginOptions {
hideBreadcrumbs: boolean;
hidePageTitle: boolean;
entryDocument: string;
indexSlug?: string;
}

export interface FrontMatter {
Expand Down
Expand Up @@ -27,6 +27,7 @@ Object {
"hideInPageTOC": true,
"hidePageTitle": true,
"id": "default",
"indexSlug": undefined,
"out": "api",
"plugin": Array [
"none",
Expand Down

0 comments on commit f22f049

Please sign in to comment.