docusaurus-plugin-typedoc 1.0.0-next.0 → 1.0.0-next.2

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
@@ -95,14 +95,12 @@ TypeDoc options can also be declared:
95
95
 
96
96
  Options specific to the plugin should also be declared in the same object.
97
97
 
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. |
98
+ | Name | Default | Description |
99
+ | :---------------------- | :------ | :------------------------------------------------------- |
100
+ | `out` | `"api"` | Output dir relative to docs dir (use `.` for no subdir). |
101
+ | `sidebar.categoryLabel` | `API` | The sidebar parent category label. |
102
+ | `sidebar.fullNames` | `false` | Display full names with module path. |
103
+ | `sidebar.position` | `auto` | The position of the sidebar in the tree. |
106
104
 
107
105
  ### An example configuration
108
106
 
@@ -195,7 +193,7 @@ Please see https://docusaurus.io/docs/api/themes/configuration#navbar-items for
195
193
  ### Frontmatter
196
194
 
197
195
  By default the plugin will configure minimal required [Frontmatter](https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-content-docs#markdown-front-matter) configuration.
198
- Additionally required global Frontmatter options can be passed in using the `frontmatter` options object
196
+ Additionally required global Frontmatter options can be passed in using the `frontmatterGlobals` options object
199
197
 
200
198
  `docusaurus.config.js`:
201
199
 
@@ -205,7 +203,7 @@ plugins: [
205
203
  'docusaurus-plugin-typedoc',
206
204
  {
207
205
  // .... other plugin option
208
- frontmatter: {
206
+ frontmatterGlobals: {
209
207
  pagination_prev: null,
210
208
  pagination_next: null
211
209
  }
package/dist/options.js CHANGED
@@ -10,8 +10,7 @@ const DEFAULT_PLUGIN_OPTIONS = {
10
10
  fullNames: false,
11
11
  categoryLabel: 'API',
12
12
  collapsed: true,
13
- indexLabel: undefined,
14
- readmeLabel: 'Readme',
13
+ indexLabel: 'Overview',
15
14
  position: null,
16
15
  autoConfiguration: true,
17
16
  },
@@ -21,10 +20,8 @@ const DEFAULT_PLUGIN_OPTIONS = {
21
20
  entryDocument: 'index.md',
22
21
  plugin: ['none'],
23
22
  watch: false,
24
- includeExtension: true,
25
- indexSlug: undefined,
26
23
  theme: 'docusaurus',
27
- frontmatter: undefined,
24
+ enableFrontmatter: true,
28
25
  };
29
26
  const getPluginOptions = (opts) => {
30
27
  const options = {
package/dist/render.js CHANGED
@@ -66,23 +66,10 @@ const addTypedocDeclarations = (app) => {
66
66
  app.options.addDeclaration({
67
67
  name: 'globalsTitle',
68
68
  });
69
- app.options.addDeclaration({
70
- name: 'readmeTitle',
71
- });
72
- app.options.addDeclaration({
73
- name: 'indexSlug',
74
- });
75
- app.options.addDeclaration({
76
- name: 'includeExtension',
77
- });
78
69
  app.options.addDeclaration({
79
70
  name: 'sidebar',
80
71
  type: typedoc_1.ParameterType.Mixed,
81
72
  });
82
- app.options.addDeclaration({
83
- name: 'frontmatter',
84
- type: typedoc_1.ParameterType.Mixed,
85
- });
86
73
  };
87
74
  function removeDir(path) {
88
75
  fs.rmSync(path, { recursive: true, force: true });
@@ -0,0 +1,11 @@
1
+ import { DeclarationReflection, PageEvent, Reflection } from 'typedoc';
2
+ import { MarkdownThemeRenderContext } from 'typedoc-plugin-markdown';
3
+ export declare class DocusaurusThemeRenderContext extends MarkdownThemeRenderContext {
4
+ baseFrontmatterVars: (page: PageEvent<Reflection>) => {
5
+ sidebar_position?: number | undefined;
6
+ sidebar_label?: string | undefined;
7
+ title: string;
8
+ };
9
+ getSidebarLabel(page: PageEvent<DeclarationReflection>): string | null | undefined;
10
+ getSidebarPosition(page: PageEvent<DeclarationReflection>): "0.5" | "0" | null;
11
+ }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DocusaurusThemeRenderContext = void 0;
4
+ const typedoc_plugin_markdown_1 = require("typedoc-plugin-markdown");
5
+ class DocusaurusThemeRenderContext extends typedoc_plugin_markdown_1.MarkdownThemeRenderContext {
6
+ constructor() {
7
+ super(...arguments);
8
+ this.baseFrontmatterVars = (page) => {
9
+ const sidebarPosition = parseFloat(this.getSidebarPosition(page));
10
+ const sidebarLabel = this.getSidebarLabel(page);
11
+ return {
12
+ ...this.getBaseFrontmatterVars(page),
13
+ ...(this.options.getValue('sidebar').autoConfiguration
14
+ ? {
15
+ ...(sidebarLabel && { sidebar_label: sidebarLabel }),
16
+ ...(sidebarPosition && {
17
+ sidebar_position: sidebarPosition,
18
+ }),
19
+ }
20
+ : {}),
21
+ };
22
+ };
23
+ }
24
+ getSidebarLabel(page) {
25
+ if (page.url === this.options.getValue('entryDocument')) {
26
+ return this.options.getValue('sidebar').indexLabel;
27
+ }
28
+ return null;
29
+ }
30
+ getSidebarPosition(page) {
31
+ if (page.url === this.options.getValue('entryDocument')) {
32
+ return page.url === page.project.url ? '0.5' : '0';
33
+ }
34
+ if (page.url === this.globalsFile) {
35
+ return '0.5';
36
+ }
37
+ if (page.model.getFullName().split('.').length === 1) {
38
+ return '0';
39
+ }
40
+ return null;
41
+ }
42
+ }
43
+ exports.DocusaurusThemeRenderContext = DocusaurusThemeRenderContext;
package/dist/theme.d.ts CHANGED
@@ -1,19 +1,13 @@
1
1
  import { DeclarationReflection, PageEvent, Renderer, RendererEvent } from 'typedoc';
2
2
  import { MarkdownTheme } from 'typedoc-plugin-markdown';
3
- import { FrontMatter, SidebarOptions } from './types';
3
+ import { SidebarOptions } from './types';
4
4
  export declare class DocusaurusTheme extends MarkdownTheme {
5
5
  sidebar: SidebarOptions;
6
- readmeTitle: string;
7
- indexSlug: string;
8
- includeExtension: string;
9
- frontmatter: FrontMatter;
6
+ private _contextCache?;
10
7
  constructor(renderer: Renderer);
8
+ getRenderContext(): any;
11
9
  onPageEnd(page: PageEvent<DeclarationReflection>): void;
12
10
  onRendererEnd(renderer: RendererEvent): void;
13
11
  loopAndWriteCategories(path: string): void;
14
12
  writeCategoryYaml: (categoryPath: string, label: string, position: number | null, collapsed: boolean) => void;
15
- getYamlItems(page: PageEvent<DeclarationReflection>): FrontMatter;
16
- getSidebarLabel(page: PageEvent<DeclarationReflection>): string | undefined;
17
- getSidebarPosition(page: PageEvent<DeclarationReflection>): "0.5" | "0" | null;
18
- get globalsFile(): string;
19
13
  }
package/dist/theme.js CHANGED
@@ -33,8 +33,8 @@ exports.DocusaurusTheme = void 0;
33
33
  const fs = __importStar(require("fs"));
34
34
  const typedoc_1 = require("typedoc");
35
35
  const typedoc_plugin_markdown_1 = require("typedoc-plugin-markdown");
36
- const front_matter_1 = require("./front-matter");
37
36
  const navigation_1 = require("./navigation");
37
+ const theme_context_1 = require("./theme-context");
38
38
  class DocusaurusTheme extends typedoc_plugin_markdown_1.MarkdownTheme {
39
39
  constructor(renderer) {
40
40
  super(renderer);
@@ -55,9 +55,13 @@ class DocusaurusTheme extends typedoc_plugin_markdown_1.MarkdownTheme {
55
55
  [typedoc_1.RendererEvent.END]: this.onRendererEnd,
56
56
  });
57
57
  }
58
+ getRenderContext() {
59
+ this._contextCache || (this._contextCache = new theme_context_1.DocusaurusThemeRenderContext(this, this.application.options));
60
+ return this._contextCache;
61
+ }
58
62
  onPageEnd(page) {
59
63
  if (page.contents) {
60
- page.contents = (0, front_matter_1.prependYAML)(page.contents.replace(/\\</g, '<'), this.getYamlItems(page));
64
+ page.contents = page.contents.replace(/\\</g, '<');
61
65
  }
62
66
  }
63
67
  onRendererEnd(renderer) {
@@ -77,81 +81,17 @@ class DocusaurusTheme extends typedoc_plugin_markdown_1.MarkdownTheme {
77
81
  return entry[1].directory === segment;
78
82
  })
79
83
  .map((entry) => entry[1])[0];
80
- if (mapping) {
84
+ const subdirectory = fs.readdirSync(fullPath);
85
+ const containsDir = subdirectory.some((item) => fs.lstatSync(`${fullPath}/${item}`).isDirectory());
86
+ if (mapping && !containsDir) {
81
87
  this.writeCategoryYaml(fullPath, (0, navigation_1.getKindPlural)(mapping.kind), navigation_1.CATEGORY_POSITION[mapping.kind], true);
82
88
  }
83
89
  this.loopAndWriteCategories(fullPath);
84
90
  }
85
91
  });
86
92
  }
87
- getYamlItems(page) {
88
- const sidebarLabel = this.getSidebarLabel(page);
89
- const sidebarPosition = this.getSidebarPosition(page);
90
- let items = {};
91
- if (page.url === this.entryDocument && this.indexSlug) {
92
- items = { ...items, slug: this.indexSlug };
93
- }
94
- if (this.sidebar.autoConfiguration) {
95
- if (sidebarLabel) {
96
- items = { ...items, sidebar_label: sidebarLabel };
97
- }
98
- if (sidebarPosition) {
99
- items = { ...items, sidebar_position: parseFloat(sidebarPosition) };
100
- }
101
- }
102
- if (page.url === page.project.url && this.entryPoints.length > 1) {
103
- items = { ...items, hide_table_of_contents: true };
104
- }
105
- items = { ...items, custom_edit_url: null };
106
- if (this.frontmatter) {
107
- items = { ...items, ...this.frontmatter };
108
- }
109
- return {
110
- ...items,
111
- };
112
- }
113
- getSidebarLabel(page) {
114
- const indexLabel = this.sidebar.indexLabel ||
115
- (this.entryPoints.length > 1 ? 'Table of Contents' : 'Exports');
116
- if (page.url === this.entryDocument) {
117
- return page.url === page.project.url
118
- ? indexLabel
119
- : this.sidebar.readmeLabel;
120
- }
121
- if (page.url === this.globalsFile) {
122
- return indexLabel;
123
- }
124
- return this.sidebar.fullNames ? page.model.getFullName() : page.model.name;
125
- }
126
- getSidebarPosition(page) {
127
- if (page.url === this.entryDocument) {
128
- return page.url === page.project.url ? '0.5' : '0';
129
- }
130
- if (page.url === this.globalsFile) {
131
- return '0.5';
132
- }
133
- if (page.model.getFullName().split('.').length === 1) {
134
- return '0';
135
- }
136
- return null;
137
- }
138
- get globalsFile() {
139
- return 'modules.md';
140
- }
141
93
  }
142
94
  __decorate([
143
95
  (0, typedoc_1.BindOption)('sidebar')
144
96
  ], DocusaurusTheme.prototype, "sidebar", void 0);
145
- __decorate([
146
- (0, typedoc_1.BindOption)('readmeTitle')
147
- ], DocusaurusTheme.prototype, "readmeTitle", void 0);
148
- __decorate([
149
- (0, typedoc_1.BindOption)('indexSlug')
150
- ], DocusaurusTheme.prototype, "indexSlug", void 0);
151
- __decorate([
152
- (0, typedoc_1.BindOption)('includeExtension')
153
- ], DocusaurusTheme.prototype, "includeExtension", void 0);
154
- __decorate([
155
- (0, typedoc_1.BindOption)('frontmatter')
156
- ], DocusaurusTheme.prototype, "frontmatter", void 0);
157
97
  exports.DocusaurusTheme = DocusaurusTheme;
package/dist/types.d.ts CHANGED
@@ -16,9 +16,8 @@ export interface PluginOptions {
16
16
  hidePageTitle: boolean;
17
17
  entryDocument: string;
18
18
  includeExtension?: boolean;
19
- indexSlug?: string;
20
19
  theme?: string;
21
- frontmatter: FrontMatter;
20
+ enableFrontmatter: boolean;
22
21
  }
23
22
  export type FrontMatter = Record<string, string | boolean | number | null> | undefined;
24
23
  export interface SidebarOptions {
@@ -26,7 +25,6 @@ export interface SidebarOptions {
26
25
  categoryLabel: string;
27
26
  collapsed: boolean;
28
27
  indexLabel?: string;
29
- readmeLabel?: string;
30
28
  position: number | null;
31
29
  autoConfiguration: boolean;
32
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docusaurus-plugin-typedoc",
3
- "version": "1.0.0-next.0",
3
+ "version": "1.0.0-next.2",
4
4
  "description": "A Docusaurus v2 plugin to build API documentation with TypeDoc.",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -17,7 +17,7 @@
17
17
  "homepage": "https://github.com/tgreyuk/typedoc-plugin-markdown/tree/master/packages/docusaurus-plugin-typedoc",
18
18
  "peerDependencies": {
19
19
  "typedoc": ">=0.23.0",
20
- "typedoc-plugin-markdown": ">=4.0.0-next.0"
20
+ "typedoc-plugin-markdown": ">=4.0.0-next.2"
21
21
  },
22
22
  "scripts": {
23
23
  "lint": "eslint ./src --ext .ts",
@@ -1,4 +0,0 @@
1
- export interface FrontMatterVars {
2
- [key: string]: string | number | boolean;
3
- }
4
- export declare const prependYAML: (contents: string, vars: FrontMatterVars) => string;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.prependYAML = void 0;
4
- const prependYAML = (contents, vars) => {
5
- return contents
6
- .replace(/^/, toYAML(vars) + '\n\n')
7
- .replace(/[\r\n]{3,}/g, '\n\n');
8
- };
9
- exports.prependYAML = prependYAML;
10
- const toYAML = (vars) => {
11
- const yaml = `---
12
- ${Object.entries(vars)
13
- .map(([key, value]) => `${key}: ${typeof value === 'string' ? `"${escapeString(value)}"` : value}`)
14
- .join('\n')}
15
- ---`;
16
- return yaml;
17
- };
18
- const escapeString = (str) => str.replace(/"/g, '\\"');