docusaurus-plugin-typedoc 0.16.6 → 0.17.0

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
@@ -32,7 +32,7 @@ module.exports = {
32
32
  // Plugin / TypeDoc options
33
33
  {
34
34
  entryPoints: ['../src/index.ts'],
35
- tsconfig: '../tsconfig.json'
35
+ tsconfig: '../tsconfig.json',
36
36
  },
37
37
  ],
38
38
  ],
@@ -63,7 +63,6 @@ Once built the docs will be available at `/docs/api` (or equivalent out director
63
63
  ├──tsconfig.json
64
64
  ```
65
65
 
66
-
67
66
  ## Options
68
67
 
69
68
  ### TypeDoc options
@@ -80,7 +79,7 @@ tsconfig: '../tsconfig.json'
80
79
  Additional TypeDoc plugins will need to be explicitly set:
81
80
 
82
81
  ```js
83
- plugin:['typedoc-plugin-xyz']
82
+ plugin: ['typedoc-plugin-xyz'];
84
83
  ```
85
84
 
86
85
  #### Other config options
@@ -96,18 +95,20 @@ TypeDoc options can also be declared:
96
95
 
97
96
  Options specific to the plugin should also be declared in the same object.
98
97
 
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. |
98
+ | Name | Default | Description |
99
+ | :---------------------- | :------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
100
+ | `out` | `"api"` | Output dir relative to docs dir (use `.` for no subdir). |
101
+ | `includeExtension` | `true` | Determines whether to preserve the `.md` extension in relative links. `true` is recommended as per [Docusaurus documentation](https://docusaurus.io/docs/docs-markdown-features#referencing-other-documents) |
102
+ | `frontmatter` | `null` | Additional frontmatter options object. See [Frontmatter](#frontmatter). |
103
+ | `sidebar.categoryLabel` | `API` | The sidebar parent category label. |
104
+ | `sidebar.fullNames` | `false` | Display full names with module path. |
105
+ | `sidebar.position` | `auto` | The position of the sidebar in the tree. |
106
+ | `sidebar.position` | `auto` | The position of the sidebar in the tree. |
105
107
 
106
108
  ### An example configuration
107
109
 
108
110
  ```js
109
111
  module.exports = {
110
-
111
112
  plugins: [
112
113
  [
113
114
  'docusaurus-plugin-typedoc',
@@ -115,14 +116,14 @@ module.exports = {
115
116
  // TypeDoc options
116
117
  entryPoints: ['../src/index.ts'],
117
118
  tsconfig: '../tsconfig.json',
118
- plugin:['typedoc-plugin-xyz'],
119
+ plugin: ['typedoc-plugin-xyz'],
119
120
 
120
121
  // Plugin options
121
122
  out: 'api-xyz',
122
123
  sidebar: {
123
124
  categoryLabel: 'API XYZ',
124
125
  position: 0,
125
- fullNames: true
126
+ fullNames: true,
126
127
  },
127
128
  },
128
129
  ],
@@ -130,7 +131,6 @@ module.exports = {
130
131
  };
131
132
  ```
132
133
 
133
-
134
134
  ## Recipes
135
135
 
136
136
  ### Sidebar and Navbar
@@ -139,7 +139,7 @@ module.exports = {
139
139
 
140
140
  `sidebars.js` can be configured in following ways:
141
141
 
142
- 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):
143
143
 
144
144
  ```js
145
145
  module.exports = {
@@ -152,7 +152,7 @@ module.exports = {
152
152
  };
153
153
  ```
154
154
 
155
- 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.
156
156
 
157
157
  > note: `sidebar.categoryLabel` and `sidebar.position` options are ignored with this implementation)
158
158
 
@@ -160,7 +160,7 @@ module.exports = {
160
160
  module.exports = {
161
161
  sidebar: {
162
162
  'Category 1': ['doc1', 'doc2', 'doc3'],
163
- 'API': [
163
+ API: [
164
164
  {
165
165
  type: 'autogenerated',
166
166
  dirName: 'api', // 'api' is the 'out' directory
@@ -193,19 +193,40 @@ A navbar item can be configured in `themeConfig` options in `docusaurus.config.j
193
193
 
194
194
  Please see https://docusaurus.io/docs/api/themes/configuration#navbar-items for navbar documentation.
195
195
 
196
+ ### Frontmatter
197
+
198
+ By default the plugin will configure minimal required [Frontmatter](https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-content-docs#markdown-front-matter) configuration.
199
+ Additionally required global Frontmatter options can be passed in using the `frontmatter` options object
200
+
201
+ `docusaurus.config.js`:
202
+
203
+ ```js
204
+ plugins: [
205
+ [
206
+ 'docusaurus-plugin-typedoc',
207
+ {
208
+ // .... other plugin option
209
+ frontmatter: {
210
+ pagination_prev: null,
211
+ pagination_next: null
212
+ }
213
+ ]
214
+ ]
215
+ ```
196
216
 
197
217
  ### Multi instance
198
218
 
199
219
  It is possible to build multi TypeDoc instances by passing in multiple configs with unique ids:
200
220
 
201
221
  `docusaurus.config.js`
222
+
202
223
  ```js
203
224
  module.exports = {
204
225
  plugins: [
205
226
  [
206
227
  'docusaurus-plugin-typedoc',
207
228
  {
208
- id:'api-1',
229
+ id: 'api-1',
209
230
  entryPoints: ['../api-1/src/index.ts'],
210
231
  tsconfig: '../api-1/tsconfig.json',
211
232
  },
@@ -213,7 +234,7 @@ module.exports = {
213
234
  [
214
235
  'docusaurus-plugin-typedoc',
215
236
  {
216
- id:'api-2',
237
+ id: 'api-2',
217
238
  entryPoints: ['../api-2/src/index.ts'],
218
239
  tsconfig: '../api-2/tsconfig.json',
219
240
  },
@@ -265,7 +286,7 @@ module.exports = {
265
286
  entryPoints: ['../packages/package-a', '../packages/package-b'],
266
287
  entryPointStrategy: 'packages',
267
288
  sidebar: {
268
- fullNames: true
289
+ fullNames: true,
269
290
  },
270
291
  },
271
292
  ],
package/dist/options.js CHANGED
@@ -18,7 +18,10 @@ const DEFAULT_PLUGIN_OPTIONS = {
18
18
  entryDocument: 'index.md',
19
19
  plugin: ['none'],
20
20
  watch: false,
21
+ includeExtension: true,
21
22
  indexSlug: undefined,
23
+ theme: 'docusaurus',
24
+ frontmatter: undefined,
22
25
  };
23
26
  const getPluginOptions = (opts) => {
24
27
  const options = {
package/dist/plugin.js CHANGED
@@ -24,6 +24,7 @@ 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
29
  function pluginDocusaurus(context, opts) {
29
30
  return {
@@ -36,7 +37,7 @@ function pluginDocusaurus(context, opts) {
36
37
  const outputDir = path.resolve(siteDir, options.docsRoot, options.out);
37
38
  (0, render_1.removeDir)(outputDir);
38
39
  const app = new typedoc_1.Application();
39
- app.options.setValue('theme', path.resolve(__dirname));
40
+ app.renderer.defineTheme('docusaurus', theme_1.DocusaurusTheme);
40
41
  (0, typedoc_plugin_markdown_1.load)(app);
41
42
  (0, render_1.bootstrap)(app, options);
42
43
  const project = app.convert();
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());
@@ -64,10 +68,17 @@ const addTypedocDeclarations = (app) => {
64
68
  app.options.addDeclaration({
65
69
  name: 'indexSlug',
66
70
  });
71
+ app.options.addDeclaration({
72
+ name: 'includeExtension',
73
+ });
67
74
  app.options.addDeclaration({
68
75
  name: 'sidebar',
69
76
  type: typedoc_1.ParameterType.Mixed,
70
77
  });
78
+ app.options.addDeclaration({
79
+ name: 'frontmatter',
80
+ type: typedoc_1.ParameterType.Mixed,
81
+ });
71
82
  };
72
83
  function removeDir(path) {
73
84
  if (fs.existsSync(path)) {
package/dist/theme.d.ts CHANGED
@@ -1,15 +1,17 @@
1
1
  import { DeclarationReflection, PageEvent, ReflectionKind, Renderer, RendererEvent } from 'typedoc';
2
2
  import { MarkdownTheme } from 'typedoc-plugin-markdown/dist/theme';
3
- import { SidebarOptions } from './types';
3
+ import { FrontMatter, SidebarOptions } from './types';
4
4
  export declare class DocusaurusTheme extends MarkdownTheme {
5
5
  sidebar: SidebarOptions;
6
6
  readmeTitle: string;
7
7
  indexSlug: string;
8
+ includeExtension: string;
9
+ frontmatter: FrontMatter;
8
10
  constructor(renderer: Renderer);
9
11
  getRelativeUrl(url: string): string;
10
12
  onPageEnd(page: PageEvent<DeclarationReflection>): void;
11
13
  onRendererEnd(renderer: RendererEvent): void;
12
- getYamlItems(page: PageEvent<DeclarationReflection>): any;
14
+ getYamlItems(page: PageEvent<DeclarationReflection>): FrontMatter;
13
15
  getSidebarLabel(page: PageEvent<DeclarationReflection>): string | undefined;
14
16
  getSidebarPosition(page: PageEvent<DeclarationReflection>): "0.5" | "0" | null;
15
17
  getId(page: PageEvent): string;
package/dist/theme.js CHANGED
@@ -52,9 +52,10 @@ 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 re = new RegExp(this.includeExtension === 'true' ? '' : '.md', 'g');
56
+ const relativeUrl = super.getRelativeUrl(url).replace(re, '');
56
57
  if (path.basename(relativeUrl).startsWith('index')) {
57
- return relativeUrl.replace('index', '');
58
+ return relativeUrl.replace('index', '').replace('.md', '');
58
59
  }
59
60
  return relativeUrl;
60
61
  }
@@ -94,9 +95,12 @@ class DocusaurusTheme extends theme_1.MarkdownTheme {
94
95
  if (page.url === page.project.url && this.entryPoints.length > 1) {
95
96
  items = { ...items, hide_table_of_contents: true };
96
97
  }
98
+ items = { ...items, custom_edit_url: null };
99
+ if (this.frontmatter) {
100
+ items = { ...items, ...this.frontmatter };
101
+ }
97
102
  return {
98
103
  ...items,
99
- custom_edit_url: null,
100
104
  };
101
105
  }
102
106
  getSidebarLabel(page) {
@@ -167,6 +171,12 @@ __decorate([
167
171
  __decorate([
168
172
  (0, typedoc_1.BindOption)('indexSlug')
169
173
  ], DocusaurusTheme.prototype, "indexSlug", void 0);
174
+ __decorate([
175
+ (0, typedoc_1.BindOption)('includeExtension')
176
+ ], DocusaurusTheme.prototype, "includeExtension", void 0);
177
+ __decorate([
178
+ (0, typedoc_1.BindOption)('frontmatter')
179
+ ], DocusaurusTheme.prototype, "frontmatter", void 0);
170
180
  exports.DocusaurusTheme = DocusaurusTheme;
171
181
  const writeCategoryYaml = (categoryPath, label, position) => {
172
182
  const yaml = [`label: "${label}"`];
package/dist/types.d.ts CHANGED
@@ -14,17 +14,12 @@ export interface PluginOptions {
14
14
  hideBreadcrumbs: boolean;
15
15
  hidePageTitle: boolean;
16
16
  entryDocument: string;
17
+ includeExtension?: boolean;
17
18
  indexSlug?: string;
19
+ theme?: string;
20
+ frontmatter: FrontMatter;
18
21
  }
19
- export interface FrontMatter {
20
- id: string;
21
- title: string;
22
- slug?: string;
23
- sidebar_label?: string;
24
- sidebar_position?: number;
25
- hide_title?: boolean;
26
- hide_table_of_contents?: boolean;
27
- }
22
+ export declare type FrontMatter = Record<string, string | boolean | number | null> | undefined;
28
23
  export interface SidebarOptions {
29
24
  fullNames?: boolean;
30
25
  categoryLabel: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docusaurus-plugin-typedoc",
3
- "version": "0.16.6",
3
+ "version": "0.17.0",
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"
@@ -30,7 +30,7 @@
30
30
  "test:init": "rm -rf test/site && npx @docusaurus/init@latest init test/site classic",
31
31
  "test:demo:start": "yarn run build && cd test/site && yarn run start",
32
32
  "test:demo:build": "yarn run build && cd test/site && yarn run build && yarn run serve",
33
- "test": "jest --colors"
33
+ "test": "jest --colors --updateSnapshot"
34
34
  },
35
35
  "author": "Thomas Grey",
36
36
  "license": "MIT",
@@ -42,5 +42,5 @@
42
42
  "typescript",
43
43
  "api"
44
44
  ],
45
- "gitHead": "eece3f13ce3b48ac51c119b432869983fc45cc6d"
45
+ "gitHead": "39b0da170611c2e27c821ef2f1869ff2e4bb0125"
46
46
  }