docusaurus-plugin-typedoc 1.0.0-next.3 → 1.0.0-next.5

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.
@@ -1,4 +1,3 @@
1
- import { ReflectionKind } from 'typedoc';
2
1
  export declare const CATEGORY_POSITION: {
3
2
  2: number;
4
3
  4: number;
@@ -10,4 +9,3 @@ export declare const CATEGORY_POSITION: {
10
9
  64: number;
11
10
  2097152: number;
12
11
  };
13
- export declare function getKindPlural(kind: ReflectionKind): string;
@@ -1,14 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getKindPlural = exports.CATEGORY_POSITION = void 0;
3
+ exports.CATEGORY_POSITION = void 0;
4
4
  const typedoc_1 = require("typedoc");
5
- const PLURALS = {
6
- [typedoc_1.ReflectionKind.Class]: 'Classes',
7
- [typedoc_1.ReflectionKind.Property]: 'Properties',
8
- [typedoc_1.ReflectionKind.Enum]: 'Enumerations',
9
- [typedoc_1.ReflectionKind.EnumMember]: 'Enumeration members',
10
- [typedoc_1.ReflectionKind.TypeAlias]: 'Type aliases',
11
- };
12
5
  exports.CATEGORY_POSITION = {
13
6
  [typedoc_1.ReflectionKind.Module]: 1,
14
7
  [typedoc_1.ReflectionKind.Namespace]: 1,
@@ -20,17 +13,3 @@ exports.CATEGORY_POSITION = {
20
13
  [typedoc_1.ReflectionKind.Function]: 7,
21
14
  [typedoc_1.ReflectionKind.ObjectLiteral]: 8,
22
15
  };
23
- function getKindPlural(kind) {
24
- if (kind in PLURALS) {
25
- return PLURALS[kind];
26
- }
27
- else {
28
- return getKindString(kind) + 's';
29
- }
30
- }
31
- exports.getKindPlural = getKindPlural;
32
- function getKindString(kind) {
33
- let str = typedoc_1.ReflectionKind[kind];
34
- str = str.replace(/(.)([A-Z])/g, (_m, a, b) => a + ' ' + b.toLowerCase());
35
- return str;
36
- }
package/dist/theme.d.ts CHANGED
@@ -3,11 +3,9 @@ import { MarkdownTheme } from 'typedoc-plugin-markdown';
3
3
  import { SidebarOptions } from './types';
4
4
  export declare class DocusaurusTheme extends MarkdownTheme {
5
5
  sidebar: SidebarOptions;
6
- private _contextCache?;
7
6
  constructor(renderer: Renderer);
8
- getRenderContext(): any;
9
7
  onPageEnd(page: PageEvent<DeclarationReflection>): void;
10
8
  onRendererEnd(renderer: RendererEvent): void;
11
- loopAndWriteCategories(path: string): void;
12
- writeCategoryYaml: (categoryPath: string, label: string, position: number | null, collapsed: boolean) => void;
9
+ loopAndWriteCategories(path: string, level?: number): void;
10
+ writeCategoryYaml: (categoryPath: string, label: string, position: number | null, collapsed: boolean, generatedIndex: boolean) => void;
13
11
  }
package/dist/theme.js CHANGED
@@ -34,11 +34,10 @@ const fs = __importStar(require("fs"));
34
34
  const typedoc_1 = require("typedoc");
35
35
  const typedoc_plugin_markdown_1 = require("typedoc-plugin-markdown");
36
36
  const navigation_1 = require("./navigation");
37
- const theme_context_1 = require("./theme-context");
38
37
  class DocusaurusTheme extends typedoc_plugin_markdown_1.MarkdownTheme {
39
38
  constructor(renderer) {
40
39
  super(renderer);
41
- this.writeCategoryYaml = (categoryPath, label, position, collapsed) => {
40
+ this.writeCategoryYaml = (categoryPath, label, position, collapsed, generatedIndex) => {
42
41
  const yaml = [`label: "${label}"`];
43
42
  if (position !== null) {
44
43
  yaml.push(`position: ${position}`);
@@ -46,6 +45,11 @@ class DocusaurusTheme extends typedoc_plugin_markdown_1.MarkdownTheme {
46
45
  if (!collapsed) {
47
46
  yaml.push(`collapsed: false`);
48
47
  }
48
+ if (generatedIndex) {
49
+ yaml.push(`link:
50
+ type: "generated-index"
51
+ title: "${label}"`);
52
+ }
49
53
  if (fs.existsSync(categoryPath)) {
50
54
  fs.writeFileSync(categoryPath + '/_category_.yml', yaml.join('\n'));
51
55
  }
@@ -55,10 +59,6 @@ class DocusaurusTheme extends typedoc_plugin_markdown_1.MarkdownTheme {
55
59
  [typedoc_1.RendererEvent.END]: this.onRendererEnd,
56
60
  });
57
61
  }
58
- getRenderContext() {
59
- this._contextCache || (this._contextCache = new theme_context_1.DocusaurusThemeRenderContext(this, this.application.options));
60
- return this._contextCache;
61
- }
62
62
  onPageEnd(page) {
63
63
  if (page.contents) {
64
64
  page.contents = page.contents.replace(/\\</g, '<');
@@ -66,11 +66,16 @@ class DocusaurusTheme extends typedoc_plugin_markdown_1.MarkdownTheme {
66
66
  }
67
67
  onRendererEnd(renderer) {
68
68
  if (this.sidebar.autoConfiguration) {
69
- this.writeCategoryYaml(renderer.outputDirectory, this.sidebar.categoryLabel, this.sidebar.position, this.sidebar.collapsed);
69
+ this.writeCategoryYaml(renderer.outputDirectory, this.sidebar.categoryLabel, this.sidebar.position, this.sidebar.collapsed, false);
70
70
  this.loopAndWriteCategories(renderer.outputDirectory);
71
+ const globalsFile = this.getRenderContext().globalsFile;
72
+ const globalsPath = `${renderer.outputDirectory}/${this.getRenderContext().globalsFile}`;
73
+ if (fs.existsSync(globalsPath)) {
74
+ fs.renameSync(globalsPath, `${renderer.outputDirectory}/01-${globalsFile}`);
75
+ }
71
76
  }
72
77
  }
73
- loopAndWriteCategories(path) {
78
+ loopAndWriteCategories(path, level = 0) {
74
79
  const directory = fs.readdirSync(path);
75
80
  directory.forEach((segment) => {
76
81
  const fullPath = `${path}/${segment}`;
@@ -83,8 +88,9 @@ class DocusaurusTheme extends typedoc_plugin_markdown_1.MarkdownTheme {
83
88
  .map((entry) => entry[1])[0];
84
89
  const subdirectory = fs.readdirSync(fullPath);
85
90
  const containsDir = subdirectory.some((item) => fs.lstatSync(`${fullPath}/${item}`).isDirectory());
86
- if (mapping && !containsDir) {
87
- this.writeCategoryYaml(fullPath, (0, navigation_1.getKindPlural)(mapping.kind), navigation_1.CATEGORY_POSITION[mapping.kind], true);
91
+ if ((mapping && !containsDir) ||
92
+ (mapping === null || mapping === void 0 ? void 0 : mapping.kind) === typedoc_1.ReflectionKind.Namespace) {
93
+ this.writeCategoryYaml(fullPath, typedoc_1.ReflectionKind.pluralString(mapping.kind), navigation_1.CATEGORY_POSITION[mapping.kind], true, true);
88
94
  }
89
95
  this.loopAndWriteCategories(fullPath);
90
96
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docusaurus-plugin-typedoc",
3
- "version": "1.0.0-next.3",
3
+ "version": "1.0.0-next.5",
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,7 @@
16
16
  },
17
17
  "homepage": "https://github.com/tgreyuk/typedoc-plugin-markdown/tree/master/packages/docusaurus-plugin-typedoc",
18
18
  "peerDependencies": {
19
- "typedoc": ">=0.23.0",
20
- "typedoc-plugin-markdown": ">=4.0.0-next.4"
19
+ "typedoc-plugin-markdown": ">=4.0.0-next.6"
21
20
  },
22
21
  "scripts": {
23
22
  "lint": "eslint ./src --ext .ts",
@@ -1,11 +0,0 @@
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
- }
@@ -1,43 +0,0 @@
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;