From dfda3fd271de9fee30acfc172dd11bf327d2f7b0 Mon Sep 17 00:00:00 2001 From: Ed Chapel Date: Fri, 22 May 2020 12:37:51 +0200 Subject: [PATCH] Adds skipSidebar option for docusaurus2 * Extends #108 to the docusaurus2 theme also. * Skips finding docusaurus root when skip is enabled. * Updates documentation to indicate it is usable for both docusaurus themes. --- README.md | 2 +- src/index.ts | 2 +- src/subthemes/docusaurus/theme.ts | 16 +++++++++------- src/subthemes/docusaurus2/theme.ts | 16 +++++++++------- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 95446e9af..f94e5dc0d 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ The following arguments can be used in addition to the default [TypeDoc argument - `--hideBreadcrumbs`
Do not print breadcrumbs. - `--skipSidebar`
- Do not update the `sidebar.json` file when used with `docusaurus` theme. + Do not update the `sidebar.json` file when used with `docusaurus` or `docusaurus2` theme. ## License diff --git a/src/index.ts b/src/index.ts index cc535c9a7..2c5a4c7f0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -54,7 +54,7 @@ export = (PluginHost: Application) => { }); app.options.addDeclaration({ - help: 'Skips updating of the sidebar.json file when used with docusaurus theme', + help: 'Skips updating of the sidebar.json file when used with docusaurus or docusaurus2 theme', name: 'skipSidebar', type: ParameterType.Boolean, }); diff --git a/src/subthemes/docusaurus/theme.ts b/src/subthemes/docusaurus/theme.ts index 582472606..abb437126 100644 --- a/src/subthemes/docusaurus/theme.ts +++ b/src/subthemes/docusaurus/theme.ts @@ -15,14 +15,16 @@ export default class DocusaurusTheme extends MarkdownTheme { } onRendererEnd(renderer: RendererEvent) { - const docusarusRoot = this.findDocusaurusRoot(renderer.outputDirectory); - if (docusarusRoot === null) { - this.application.logger.warn( - `[typedoc-markdown-plugin] sidebars.json not written as could not locate docusaurus root directory. In order to to implemnent sidebars.json functionality, the output directory must be a child of a 'docs' directory.`, - ); - return; + if (!this.application.options.getValue('skipSidebar')) { + const docusarusRoot = this.findDocusaurusRoot(renderer.outputDirectory); + if (docusarusRoot === null) { + this.application.logger.warn( + `[typedoc-markdown-plugin] sidebars.json not written as could not locate docusaurus root directory. In order to to implemnent sidebars.json functionality, the output directory must be a child of a 'docs' directory.`, + ); + return; + } + this.writeSideBar(renderer, docusarusRoot); } - if (!this.application.options.getValue('skipSidebar')) { this.writeSideBar(renderer, docusarusRoot); } } writeSideBar(renderer: RendererEvent, docusarusRoot: string) { diff --git a/src/subthemes/docusaurus2/theme.ts b/src/subthemes/docusaurus2/theme.ts index be1d295b0..2a19813a4 100644 --- a/src/subthemes/docusaurus2/theme.ts +++ b/src/subthemes/docusaurus2/theme.ts @@ -17,14 +17,16 @@ export default class Docusaurus2Theme extends MarkdownTheme { } onRendererEnd(renderer: RendererEvent) { - const docusarusRoot = this.findDocusaurus2Root(renderer.outputDirectory); - if (docusarusRoot === null) { - this.application.logger.warn( - `[typedoc-markdown-plugin] ${this.sidebarName} not written as could not locate docusaurus root directory. In order to to implemnent ${this.sidebarName} functionality, the output directory must be a child of a 'docs' directory.`, - ); - return; + if (!this.application.options.getValue('skipSidebar')) { + const docusarusRoot = this.findDocusaurus2Root(renderer.outputDirectory); + if (docusarusRoot === null) { + this.application.logger.warn( + `[typedoc-markdown-plugin] ${this.sidebarName} not written as could not locate docusaurus root directory. In order to to implemnent ${this.sidebarName} functionality, the output directory must be a child of a 'docs' directory.`, + ); + return; + } + this.writeSideBar(renderer, docusarusRoot); } - this.writeSideBar(renderer, docusarusRoot); } writeSideBar(renderer: RendererEvent, docusarusRoot: string) {