Skip to content

Commit

Permalink
fix: Fix manual sidebar backward compatibility (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed May 6, 2021
1 parent 88c8337 commit dc873d4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
9 changes: 8 additions & 1 deletion packages/docusaurus-plugin-typedoc/README.md
Expand Up @@ -86,6 +86,11 @@ module.exports = {
module.exports = {
someSidebar: {
'Category 1': ['doc1', 'doc2', 'doc3'],

// use seperate generated file
'API': require('./typedoc-sidebar.js'),

// or write inline
'API': [
{
type: 'autogenerated',
Expand All @@ -96,6 +101,8 @@ module.exports = {
};
```

> To maintain backward compatibility with previous versions a `./typedoc-sidebar.js` is created by default. Pass `sidebar.sidebarFile:null` to prevent this.
Please see https://docusaurus.io/docs/sidebar for sidebar documentation.

## Options
Expand Down Expand Up @@ -135,7 +142,7 @@ Note: Options declared in this manner will take priority and overwrite options d
| `sidebar.fullNames` | `false` | Display full names with module path. |
| `sidebar.position` | `null` | The position of the sidebar in the tree. |

If the sidebar is not required pass `sidebar: null` to skip sidebar generation.
If the manual sidebar is not required pass `sidebar.sidebarFile: null` to skip sidebar generation.

### An example configuration

Expand Down
9 changes: 3 additions & 6 deletions packages/docusaurus-plugin-typedoc/src/plugin.ts
Expand Up @@ -4,7 +4,7 @@ import MarkdownPlugin from 'typedoc-plugin-markdown';

import { getOutputDirectory } from './options';
import { bootstrap } from './render';
import { shouldWriteSidebar, writeSidebar } from './sidebar';
import { writeSidebar } from './sidebar';
import { PluginOptions } from './types';

// store list of plugin ids when running multiple instances
Expand All @@ -25,11 +25,8 @@ export default async function pluginDocusaurus(

const options = bootstrap(app, opts);

// Try not break legacy manual sidebar generation implementations
if (shouldWriteSidebar(siteDir, options)) {
app.logger.warn(
'As of docusaurus-plugin-markdown@0.14.0 manual sidebar generation is deprecated. Please see package Readme for details.',
);
// Do not break legacy manual sidebar generation implementations
if (options.sidebar.sidebarFile) {
writeSidebar(siteDir, options);
}

Expand Down
10 changes: 4 additions & 6 deletions packages/docusaurus-plugin-typedoc/src/sidebar.ts
Expand Up @@ -3,15 +3,13 @@ import * as path from 'path';

import { PluginOptions } from './types';

export const shouldWriteSidebar = (siteDir: string, options: PluginOptions) => {
const sidebarPath = path.resolve(siteDir, options.sidebar.sidebarFile);
return fs.existsSync(sidebarPath);
};

export const writeSidebar = (siteDir: string, options: PluginOptions) => {
const sidebarPath = path.resolve(siteDir, options.sidebar.sidebarFile);
if (!fs.existsSync(path.dirname(sidebarPath))) {
fs.mkdirSync(path.dirname(sidebarPath));
}
fs.writeFileSync(
sidebarPath,
`module.exports=[{type:'autogenerated',dirName:'${options.out}'}]`,
`module.exports=[{type:'autogenerated',dirName:'${options.out}'}];`,
);
};

0 comments on commit dc873d4

Please sign in to comment.