docusaurus-plugin-typedoc 0.16.4 → 0.16.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,24 +11,12 @@ Generates static TypeDoc pages in Markdown with frontmatter as part of the Docus
11
11
 
12
12
  ## Installation
13
13
 
14
- 1. Install Docusaurus in the root of your project. See https://v2.docusaurus.io/docs/installation.
15
-
16
- 2. Install the plugin dependencies in the same location as the Docusaurus website directory.
14
+ > Install [Docusaurus](https://v2.docusaurus.io/docs/installation) in the root of your project and install the plugin dependencies in the same location as the Docusaurus website directory.
17
15
 
18
16
  ```shell
19
- cd docs-website
20
17
  npm install typedoc typedoc-plugin-markdown docusaurus-plugin-typedoc --save-dev
21
18
  ```
22
19
 
23
- ```
24
- ├──docs-website (docusaurus location)
25
- ├── package.json
26
- ├──package.json
27
- ├──src (typescript source files)
28
- ├──tsconfig.json
29
-
30
- ```
31
-
32
20
  ## Usage
33
21
 
34
22
  ### Config
@@ -58,16 +46,21 @@ TypeDoc will be bootstraped with the Docusaurus `start` and `build` [cli command
58
46
  "build": "docusaurus build",
59
47
  ```
60
48
 
61
- Once built the docs will be available at `/docs/api` or equivalent out directory.
49
+ Once built the docs will be available at `/docs/api` (or equivalent out directory).
50
+
51
+ ### Directory structure
62
52
 
63
53
  ```
64
- docs-website
65
- ├── build/ (static site dir)
66
- ├── docs/
67
- │ ├── api/ (compiled typedoc markdown)
68
- ├── docusaurus.config.js
69
- ├── package.json
70
- ├── sidebars.js
54
+ ├── docusauruss-website
55
+ ├── build/ (static site dir)
56
+ ├── docs/
57
+ │ ├── api/ (compiled typedoc markdown)
58
+ ├── docusaurus.config.js
59
+ ├── package.json
60
+ ├── sidebars.js
61
+ ├──package.json
62
+ ├──src (typescript source files)
63
+ ├──tsconfig.json
71
64
  ```
72
65
 
73
66
 
@@ -103,12 +96,12 @@ TypeDoc options can also be declared:
103
96
 
104
97
  Options specific to the plugin should also be declared in the same object.
105
98
 
106
- | Name | Default | Description |
107
- | :---------------------- | :------ | :------------------------------------------- |
108
- | `out` | `"api"` | Output directory relative to docs directory. |
109
- | `sidebar.categoryLabel` | `API` | The sidebar parent category label. |
110
- | `sidebar.fullNames` | `false` | Display full names with module path. |
111
- | `sidebar.position` | `null` | The position of the sidebar in the tree. |
99
+ | Name | Default | Description |
100
+ | :---------------------- | :------ | :------------------------------------------------------- |
101
+ | `out` | `"api"` | Output dir relative to docs dir (use `.` for no subdir). | |
102
+ | `sidebar.categoryLabel` | `API` | The sidebar parent category label. |
103
+ | `sidebar.fullNames` | `false` | Display full names with module path. |
104
+ | `sidebar.position` | `auto` | The position of the sidebar in the tree. |
112
105
 
113
106
  ### An example configuration
114
107
 
@@ -137,13 +130,16 @@ module.exports = {
137
130
  };
138
131
  ```
139
132
 
140
- ## Sidebar and Navbar
141
133
 
142
- ### Sidebar
134
+ ## Recipes
135
+
136
+ ### Sidebar and Navbar
137
+
138
+ #### Sidebar
143
139
 
144
140
  `sidebars.js` can be configured in following ways:
145
141
 
146
- 1 ) Generate the entire sidebar from file structure of your docs folder (default behaviour):
142
+ 1) Generate the entire sidebar from file structure of your docs folder (default behaviour):
147
143
 
148
144
  ```js
149
145
  module.exports = {
@@ -156,9 +152,9 @@ module.exports = {
156
152
  };
157
153
  ```
158
154
 
159
- 2 ) Alternatively, if you wish to manually control other parts of your sidebar you can use a slice for the TypeDoc sidebar.
155
+ 2) Alternatively, if you wish to manually control other parts of your sidebar you can use a slice for the TypeDoc sidebar.
160
156
 
161
- >note: `sidebar.categoryLabel` and `sidebar.position` options are ignored with this implementation)
157
+ > note: `sidebar.categoryLabel` and `sidebar.position` options are ignored with this implementation)
162
158
 
163
159
  ```js
164
160
  module.exports = {
@@ -176,7 +172,7 @@ module.exports = {
176
172
 
177
173
  Please see https://docusaurus.io/docs/sidebar for sidebar documentation.
178
174
 
179
- ### Navbar
175
+ #### Navbar
180
176
 
181
177
  A navbar item can be configured in `themeConfig` options in `docusaurus.config.js`:
182
178
 
@@ -197,7 +193,6 @@ A navbar item can be configured in `themeConfig` options in `docusaurus.config.j
197
193
 
198
194
  Please see https://docusaurus.io/docs/api/themes/configuration#navbar-items for navbar documentation.
199
195
 
200
- ## Additional config
201
196
 
202
197
  ### Multi instance
203
198
 
package/dist/options.js CHANGED
@@ -18,6 +18,8 @@ const DEFAULT_PLUGIN_OPTIONS = {
18
18
  entryDocument: 'index.md',
19
19
  plugin: ['none'],
20
20
  watch: false,
21
+ indexSlug: undefined,
22
+ theme: 'docusaurus',
21
23
  };
22
24
  const getPluginOptions = (opts) => {
23
25
  const options = {
package/dist/plugin.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { LoadContext } from '@docusaurus/types';
2
2
  import { PluginOptions } from './types';
3
- export default function pluginDocusaurus(context: LoadContext, opts: Partial<PluginOptions>): Promise<{
3
+ export default function pluginDocusaurus(context: LoadContext, opts: Partial<PluginOptions>): {
4
4
  name: string;
5
- } | undefined>;
5
+ loadContent(): Promise<void>;
6
+ };
package/dist/plugin.js CHANGED
@@ -24,33 +24,36 @@ const typedoc_1 = require("typedoc");
24
24
  const typedoc_plugin_markdown_1 = require("typedoc-plugin-markdown");
25
25
  const options_1 = require("./options");
26
26
  const render_1 = require("./render");
27
+ const theme_1 = require("./theme");
27
28
  const apps = [];
28
- async function pluginDocusaurus(context, opts) {
29
- if (opts.id && !apps.includes(opts.id)) {
30
- apps.push(opts.id);
31
- const { siteDir } = context;
32
- const options = (0, options_1.getPluginOptions)(opts);
33
- const outputDir = path.resolve(siteDir, options.docsRoot, options.out);
34
- (0, render_1.removeDir)(outputDir);
35
- const app = new typedoc_1.Application();
36
- app.options.setValue('theme', path.resolve(__dirname));
37
- (0, typedoc_plugin_markdown_1.load)(app);
38
- (0, render_1.bootstrap)(app, options);
39
- const project = app.convert();
40
- if (!project) {
41
- return;
42
- }
43
- if (options.watch) {
44
- app.convertAndWatch(async (project) => {
45
- await app.generateDocs(project, outputDir);
46
- });
47
- }
48
- else {
49
- await app.generateDocs(project, outputDir);
50
- }
51
- }
29
+ function pluginDocusaurus(context, opts) {
52
30
  return {
53
31
  name: 'docusaurus-plugin-typedoc',
32
+ async loadContent() {
33
+ if (opts.id && !apps.includes(opts.id)) {
34
+ apps.push(opts.id);
35
+ const { siteDir } = context;
36
+ const options = (0, options_1.getPluginOptions)(opts);
37
+ const outputDir = path.resolve(siteDir, options.docsRoot, options.out);
38
+ (0, render_1.removeDir)(outputDir);
39
+ const app = new typedoc_1.Application();
40
+ app.renderer.defineTheme('docusaurus', theme_1.DocusaurusTheme);
41
+ (0, typedoc_plugin_markdown_1.load)(app);
42
+ (0, render_1.bootstrap)(app, options);
43
+ const project = app.convert();
44
+ if (!project) {
45
+ return;
46
+ }
47
+ if (options.watch) {
48
+ app.convertAndWatch(async (project) => {
49
+ await app.generateDocs(project, outputDir);
50
+ });
51
+ }
52
+ else {
53
+ await app.generateDocs(project, outputDir);
54
+ }
55
+ }
56
+ },
54
57
  };
55
58
  }
56
59
  exports.default = pluginDocusaurus;
package/dist/render.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { Application } from 'typedoc';
1
+ import { Application, ProjectReflection } from 'typedoc';
2
2
  import { PluginOptions } from './types';
3
3
  export declare const bootstrap: (app: Application, options: PluginOptions) => void;
4
+ export declare function render(project: ProjectReflection, outputDirectory: string): Promise<void>;
4
5
  export declare function removeDir(path: string): void;
package/dist/render.js CHANGED
@@ -19,7 +19,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
19
19
  return result;
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.removeDir = exports.bootstrap = void 0;
22
+ exports.removeDir = exports.render = exports.bootstrap = void 0;
23
23
  const fs = __importStar(require("fs"));
24
24
  const typedoc_1 = require("typedoc");
25
25
  const bootstrap = (app, options) => {
@@ -31,6 +31,9 @@ const bootstrap = (app, options) => {
31
31
  exports.bootstrap = bootstrap;
32
32
  async function render(project, outputDirectory) {
33
33
  var _a;
34
+ if (!this.prepareTheme()) {
35
+ return;
36
+ }
34
37
  const output = new typedoc_1.RendererEvent(typedoc_1.RendererEvent.BEGIN, outputDirectory, project);
35
38
  output.urls = this.theme.getUrls(project);
36
39
  this.trigger(output);
@@ -41,6 +44,7 @@ async function render(project, outputDirectory) {
41
44
  this.trigger(typedoc_1.RendererEvent.END, output);
42
45
  }
43
46
  }
47
+ exports.render = render;
44
48
  const addTypedocReaders = (app) => {
45
49
  app.options.addReader(new typedoc_1.TypeDocReader());
46
50
  app.options.addReader(new typedoc_1.TSConfigReader());
@@ -61,6 +65,9 @@ const addTypedocDeclarations = (app) => {
61
65
  app.options.addDeclaration({
62
66
  name: 'readmeTitle',
63
67
  });
68
+ app.options.addDeclaration({
69
+ name: 'indexSlug',
70
+ });
64
71
  app.options.addDeclaration({
65
72
  name: 'sidebar',
66
73
  type: typedoc_1.ParameterType.Mixed,
package/dist/theme.d.ts CHANGED
@@ -4,6 +4,7 @@ import { SidebarOptions } from './types';
4
4
  export declare class DocusaurusTheme extends MarkdownTheme {
5
5
  sidebar: SidebarOptions;
6
6
  readmeTitle: string;
7
+ indexSlug: string;
7
8
  constructor(renderer: Renderer);
8
9
  getRelativeUrl(url: string): string;
9
10
  onPageEnd(page: PageEvent<DeclarationReflection>): void;
@@ -13,6 +14,7 @@ export declare class DocusaurusTheme extends MarkdownTheme {
13
14
  getSidebarPosition(page: PageEvent<DeclarationReflection>): "0.5" | "0" | null;
14
15
  getId(page: PageEvent): string;
15
16
  getTitle(page: PageEvent): any;
17
+ getSlug(): string;
16
18
  get mappings(): {
17
19
  kind: ReflectionKind[];
18
20
  isLeaf: boolean;
package/dist/theme.js CHANGED
@@ -52,7 +52,7 @@ class DocusaurusTheme extends theme_1.MarkdownTheme {
52
52
  });
53
53
  }
54
54
  getRelativeUrl(url) {
55
- const relativeUrl = super.getRelativeUrl(url).replace(/.md/g, '');
55
+ const relativeUrl = super.getRelativeUrl(url);
56
56
  if (path.basename(relativeUrl).startsWith('index')) {
57
57
  return relativeUrl.replace('index', '');
58
58
  }
@@ -83,10 +83,7 @@ class DocusaurusTheme extends theme_1.MarkdownTheme {
83
83
  title: pageTitle,
84
84
  };
85
85
  if (page.url === this.entryDocument) {
86
- items = {
87
- ...items,
88
- slug: `/${path.relative(process.cwd(), this.out).replace(/\\/g, '/')}/`,
89
- };
86
+ items = { ...items, slug: this.getSlug() };
90
87
  }
91
88
  if (sidebarLabel && sidebarLabel !== pageTitle) {
92
89
  items = { ...items, sidebar_label: sidebarLabel };
@@ -137,6 +134,15 @@ class DocusaurusTheme extends theme_1.MarkdownTheme {
137
134
  }
138
135
  return (0, front_matter_1.getPageTitle)(page);
139
136
  }
137
+ getSlug() {
138
+ if (this.indexSlug) {
139
+ return this.indexSlug;
140
+ }
141
+ if (this.out === process.cwd()) {
142
+ return '/';
143
+ }
144
+ return `/${path.relative(process.cwd(), this.out).replace(/\\/g, '/')}/`;
145
+ }
140
146
  get mappings() {
141
147
  return super.mappings.map((mapping) => {
142
148
  if (mapping.kind.includes(typedoc_1.ReflectionKind.Namespace)) {
@@ -158,6 +164,9 @@ __decorate([
158
164
  __decorate([
159
165
  (0, typedoc_1.BindOption)('readmeTitle')
160
166
  ], DocusaurusTheme.prototype, "readmeTitle", void 0);
167
+ __decorate([
168
+ (0, typedoc_1.BindOption)('indexSlug')
169
+ ], DocusaurusTheme.prototype, "indexSlug", void 0);
161
170
  exports.DocusaurusTheme = DocusaurusTheme;
162
171
  const writeCategoryYaml = (categoryPath, label, position) => {
163
172
  const yaml = [`label: "${label}"`];
package/dist/types.d.ts CHANGED
@@ -14,6 +14,8 @@ export interface PluginOptions {
14
14
  hideBreadcrumbs: boolean;
15
15
  hidePageTitle: boolean;
16
16
  entryDocument: string;
17
+ indexSlug?: string;
18
+ theme?: string;
17
19
  }
18
20
  export interface FrontMatter {
19
21
  id: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docusaurus-plugin-typedoc",
3
- "version": "0.16.4",
3
+ "version": "0.16.8",
4
4
  "description": "A Docusaurus v2 plugin to build API documentation with TypeDoc.",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -16,8 +16,8 @@
16
16
  },
17
17
  "homepage": "https://github.com/tgreyuk/typedoc-plugin-markdown/tree/master/packages/docusaurus-plugin-typedoc",
18
18
  "peerDependencies": {
19
- "typedoc": ">=0.21.0",
20
- "typedoc-plugin-markdown": ">=3.10.0"
19
+ "typedoc": ">=0.22.0",
20
+ "typedoc-plugin-markdown": ">=3.11.10"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@docusaurus/types": "^2.0.0-beta.0"
@@ -42,5 +42,5 @@
42
42
  "typescript",
43
43
  "api"
44
44
  ],
45
- "gitHead": "07d11744f1312dda8f1017b5ab54456f3521eb75"
45
+ "gitHead": "eb688bb8ef85b24fc873f80d6182804fcc2d2dfc"
46
46
  }