@docusaurus/plugin-content-docs 2.0.0-beta.1 → 2.0.0-beta.10

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.
Files changed (140) hide show
  1. package/lib/.tsbuildinfo +1 -1
  2. package/lib/categoryGeneratedIndex.d.ts +12 -0
  3. package/lib/categoryGeneratedIndex.js +37 -0
  4. package/lib/cli.d.ts +2 -2
  5. package/lib/cli.js +12 -34
  6. package/lib/client/docsClientUtils.d.ts +1 -4
  7. package/lib/client/docsClientUtils.js +21 -31
  8. package/lib/docFrontMatter.d.ts +1 -1
  9. package/lib/docFrontMatter.js +10 -6
  10. package/lib/docs.d.ts +25 -3
  11. package/lib/docs.js +125 -38
  12. package/lib/globalData.d.ts +1 -1
  13. package/lib/index.d.ts +1 -1
  14. package/lib/index.js +104 -138
  15. package/lib/lastUpdate.js +9 -10
  16. package/lib/markdown/index.d.ts +3 -6
  17. package/lib/markdown/index.js +3 -3
  18. package/lib/markdown/linkify.js +2 -2
  19. package/lib/numberPrefix.d.ts +1 -1
  20. package/lib/options.d.ts +3 -3
  21. package/lib/options.js +49 -17
  22. package/lib/props.d.ts +7 -2
  23. package/lib/props.js +61 -9
  24. package/lib/routes.d.ts +27 -0
  25. package/lib/routes.js +105 -0
  26. package/lib/{sidebarItemsGenerator.d.ts → sidebars/generator.d.ts} +5 -2
  27. package/lib/sidebars/generator.js +216 -0
  28. package/lib/sidebars/index.d.ts +15 -0
  29. package/lib/sidebars/index.js +73 -0
  30. package/lib/sidebars/normalization.d.ts +14 -0
  31. package/lib/sidebars/normalization.js +77 -0
  32. package/lib/sidebars/processor.d.ts +18 -0
  33. package/lib/sidebars/processor.js +85 -0
  34. package/lib/sidebars/types.d.ts +127 -0
  35. package/lib/sidebars/types.js +8 -0
  36. package/lib/sidebars/utils.d.ts +35 -0
  37. package/lib/sidebars/utils.js +228 -0
  38. package/lib/sidebars/validation.d.ts +10 -0
  39. package/lib/sidebars/validation.js +138 -0
  40. package/lib/slug.d.ts +4 -3
  41. package/lib/slug.js +27 -15
  42. package/lib/tags.d.ts +8 -0
  43. package/lib/tags.js +20 -0
  44. package/lib/theme/hooks/useDocs.js +24 -21
  45. package/lib/translations.d.ts +2 -2
  46. package/lib/translations.js +71 -29
  47. package/lib/types.d.ts +52 -62
  48. package/lib/versions.d.ts +3 -3
  49. package/lib/versions.js +76 -24
  50. package/package.json +22 -20
  51. package/src/__tests__/__fixtures__/simple-site/docs/_partials/somePartial.md +3 -0
  52. package/src/__tests__/__fixtures__/simple-site/docs/_partials/subfolder/somePartial.md +3 -0
  53. package/src/__tests__/__fixtures__/simple-site/docs/_somePartial.md +3 -0
  54. package/src/__tests__/__fixtures__/simple-site/docs/foo/baz.md +5 -0
  55. package/src/__tests__/__fixtures__/simple-site/docs/hello.md +2 -0
  56. package/src/__tests__/__fixtures__/simple-site/docs/rootAbsoluteSlug.md +2 -0
  57. package/src/__tests__/__fixtures__/simple-site/docs/rootRelativeSlug.md +2 -0
  58. package/src/__tests__/__fixtures__/simple-site/docs/rootResolvedSlug.md +2 -0
  59. package/src/__tests__/__fixtures__/simple-site/docs/rootTryToEscapeSlug.md +2 -0
  60. package/src/__tests__/__fixtures__/simple-site/sidebars.json +15 -1
  61. package/src/__tests__/__fixtures__/site-with-doc-label/docs/hello-1.md +1 -0
  62. package/src/__tests__/__fixtures__/versioned-site/docs/foo/bar.md +6 -0
  63. package/src/__tests__/__fixtures__/versioned-site/docs/hello.md +3 -0
  64. package/src/__tests__/__fixtures__/versioned-site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md +3 -0
  65. package/src/__tests__/__fixtures__/versioned-site/i18n/fr/docusaurus-plugin-content-docs/version-1.0.0/hello.md +3 -0
  66. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/hello.md +3 -0
  67. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_partials/somePartial.md +3 -0
  68. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_partials/subfolder/somePartial.md +3 -0
  69. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_somePartial.md +3 -0
  70. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/hello.md +3 -0
  71. package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-1.0.1-sidebars.json +2 -2
  72. package/src/__tests__/__snapshots__/cli.test.ts.snap +48 -73
  73. package/src/__tests__/__snapshots__/docs.test.ts.snap +140 -0
  74. package/src/__tests__/__snapshots__/index.test.ts.snap +753 -112
  75. package/src/__tests__/__snapshots__/translations.test.ts.snap +45 -18
  76. package/src/__tests__/cli.test.ts +15 -11
  77. package/src/__tests__/docFrontMatter.test.ts +195 -40
  78. package/src/__tests__/docs.test.ts +311 -150
  79. package/src/__tests__/index.test.ts +112 -69
  80. package/src/__tests__/lastUpdate.test.ts +3 -2
  81. package/src/__tests__/options.test.ts +48 -4
  82. package/src/__tests__/props.test.ts +62 -0
  83. package/src/__tests__/slug.test.ts +127 -20
  84. package/src/__tests__/translations.test.ts +7 -2
  85. package/src/__tests__/versions.test.ts +93 -67
  86. package/src/categoryGeneratedIndex.ts +57 -0
  87. package/src/cli.ts +8 -41
  88. package/src/client/__tests__/docsClientUtils.test.ts +4 -5
  89. package/src/client/docsClientUtils.ts +19 -41
  90. package/{types.d.ts → src/deps.d.ts} +0 -0
  91. package/src/docFrontMatter.ts +13 -7
  92. package/src/docs.ts +158 -29
  93. package/src/globalData.ts +6 -1
  94. package/src/index.ts +134 -179
  95. package/src/lastUpdate.ts +10 -9
  96. package/src/markdown/index.ts +8 -12
  97. package/src/numberPrefix.ts +5 -3
  98. package/src/options.ts +59 -28
  99. package/src/plugin-content-docs.d.ts +179 -35
  100. package/src/props.ts +91 -16
  101. package/src/routes.ts +173 -0
  102. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-shorthand.js +0 -0
  103. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-wrong-items.json +0 -0
  104. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-wrong-label.json +0 -0
  105. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category.js +0 -0
  106. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-collapsed-first-level.json +0 -0
  107. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-collapsed.json +0 -0
  108. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-doc-id-not-string.json +0 -0
  109. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-first-level-not-category.js +0 -0
  110. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link-wrong-href.json +0 -0
  111. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link-wrong-label.json +0 -0
  112. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link.json +0 -0
  113. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-unknown-type.json +0 -0
  114. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-wrong-field.json +0 -0
  115. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars.json +0 -0
  116. package/src/{__tests__/__snapshots__/sidebars.test.ts.snap → sidebars/__tests__/__snapshots__/index.test.ts.snap} +36 -6
  117. package/src/{__tests__/sidebarItemsGenerator.test.ts → sidebars/__tests__/generator.test.ts} +143 -18
  118. package/src/sidebars/__tests__/index.test.ts +204 -0
  119. package/src/sidebars/__tests__/processor.test.ts +237 -0
  120. package/src/sidebars/__tests__/utils.test.ts +695 -0
  121. package/src/sidebars/__tests__/validation.test.ts +105 -0
  122. package/src/sidebars/generator.ts +310 -0
  123. package/src/sidebars/index.ts +94 -0
  124. package/src/sidebars/normalization.ts +112 -0
  125. package/src/sidebars/processor.ts +154 -0
  126. package/src/sidebars/types.ts +211 -0
  127. package/src/sidebars/utils.ts +329 -0
  128. package/src/sidebars/validation.ts +168 -0
  129. package/src/slug.ts +32 -17
  130. package/src/tags.ts +19 -0
  131. package/src/theme/hooks/useDocs.ts +5 -1
  132. package/src/translations.ts +103 -47
  133. package/src/types.ts +67 -105
  134. package/src/versions.ts +117 -21
  135. package/lib/sidebarItemsGenerator.js +0 -211
  136. package/lib/sidebars.d.ts +0 -43
  137. package/lib/sidebars.js +0 -319
  138. package/src/__tests__/sidebars.test.ts +0 -639
  139. package/src/sidebarItemsGenerator.ts +0 -307
  140. package/src/sidebars.ts +0 -506
package/src/options.ts CHANGED
@@ -4,7 +4,8 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import {PluginOptions} from './types';
7
+
8
+ import type {PluginOptions} from './types';
8
9
  import {
9
10
  Joi,
10
11
  RemarkPluginsSchema,
@@ -12,10 +13,15 @@ import {
12
13
  AdmonitionsSchema,
13
14
  URISchema,
14
15
  } from '@docusaurus/utils-validation';
15
- import {OptionValidationContext, ValidationResult} from '@docusaurus/types';
16
+ import {GlobExcludeDefault} from '@docusaurus/utils';
17
+
18
+ import type {
19
+ OptionValidationContext,
20
+ ValidationResult,
21
+ } from '@docusaurus/types';
16
22
  import chalk from 'chalk';
17
23
  import admonitions from 'remark-admonitions';
18
- import {DefaultSidebarItemsGenerator} from './sidebarItemsGenerator';
24
+ import {DefaultSidebarItemsGenerator} from './sidebars/generator';
19
25
  import {
20
26
  DefaultNumberPrefixParser,
21
27
  DisabledNumberPrefixParser,
@@ -24,12 +30,16 @@ import {
24
30
  export const DEFAULT_OPTIONS: Omit<PluginOptions, 'id' | 'sidebarPath'> = {
25
31
  path: 'docs', // Path to data on filesystem, relative to site dir.
26
32
  routeBasePath: 'docs', // URL Route.
27
- homePageId: undefined, // TODO remove soon, deprecated
33
+ tagsBasePath: 'tags', // URL Tags Route.
28
34
  include: ['**/*.{md,mdx}'], // Extensions to include.
35
+ exclude: GlobExcludeDefault,
29
36
  sidebarItemsGenerator: DefaultSidebarItemsGenerator,
30
37
  numberPrefixParser: DefaultNumberPrefixParser,
31
38
  docLayoutComponent: '@theme/DocPage',
32
39
  docItemComponent: '@theme/DocItem',
40
+ docTagDocListComponent: '@theme/DocTagDocListPage',
41
+ docTagsListComponent: '@theme/DocTagsListPage',
42
+ docCategoryGeneratedIndexComponent: '@theme/DocCategoryGeneratedIndexPage',
33
43
  remarkPlugins: [],
34
44
  rehypePlugins: [],
35
45
  beforeDefaultRemarkPlugins: [],
@@ -37,18 +47,22 @@ export const DEFAULT_OPTIONS: Omit<PluginOptions, 'id' | 'sidebarPath'> = {
37
47
  showLastUpdateTime: false,
38
48
  showLastUpdateAuthor: false,
39
49
  admonitions: {},
40
- excludeNextVersionDocs: false,
41
50
  includeCurrentVersion: true,
42
51
  disableVersioning: false,
43
52
  lastVersion: undefined,
44
53
  versions: {},
45
54
  editCurrentVersion: false,
46
55
  editLocalizedFiles: false,
56
+ sidebarCollapsible: true,
57
+ sidebarCollapsed: true,
47
58
  };
48
59
 
49
60
  const VersionOptionsSchema = Joi.object({
50
61
  path: Joi.string().allow('').optional(),
51
62
  label: Joi.string().optional(),
63
+ banner: Joi.string().equal('none', 'unreleased', 'unmaintained').optional(),
64
+ badge: Joi.boolean().optional(),
65
+ className: Joi.string().optional(),
52
66
  });
53
67
 
54
68
  const VersionsOptionsSchema = Joi.object()
@@ -64,8 +78,14 @@ export const OptionsSchema = Joi.object({
64
78
  // '' not allowed, see https://github.com/facebook/docusaurus/issues/3374
65
79
  // .allow('') ""
66
80
  .default(DEFAULT_OPTIONS.routeBasePath),
67
- homePageId: Joi.string().optional(),
81
+ tagsBasePath: Joi.string().default(DEFAULT_OPTIONS.tagsBasePath),
82
+ homePageId: Joi.any().forbidden().messages({
83
+ 'any.unknown':
84
+ 'The docs plugin option homePageId is not supported anymore. To make a doc the "home", please add "slug: /" in its front matter. See: https://docusaurus.io/docs/next/docs-introduction#home-page-docs',
85
+ }),
86
+
68
87
  include: Joi.array().items(Joi.string()).default(DEFAULT_OPTIONS.include),
88
+ exclude: Joi.array().items(Joi.string()).default(DEFAULT_OPTIONS.exclude),
69
89
  sidebarPath: Joi.alternatives().try(
70
90
  Joi.boolean().invalid(true),
71
91
  Joi.string(),
@@ -73,6 +93,8 @@ export const OptionsSchema = Joi.object({
73
93
  sidebarItemsGenerator: Joi.function().default(
74
94
  () => DEFAULT_OPTIONS.sidebarItemsGenerator,
75
95
  ),
96
+ sidebarCollapsible: Joi.boolean().default(DEFAULT_OPTIONS.sidebarCollapsible),
97
+ sidebarCollapsed: Joi.boolean().default(DEFAULT_OPTIONS.sidebarCollapsed),
76
98
  numberPrefixParser: Joi.alternatives()
77
99
  .try(
78
100
  Joi.function(),
@@ -86,6 +108,15 @@ export const OptionsSchema = Joi.object({
86
108
  .default(() => DEFAULT_OPTIONS.numberPrefixParser),
87
109
  docLayoutComponent: Joi.string().default(DEFAULT_OPTIONS.docLayoutComponent),
88
110
  docItemComponent: Joi.string().default(DEFAULT_OPTIONS.docItemComponent),
111
+ docTagsListComponent: Joi.string().default(
112
+ DEFAULT_OPTIONS.docTagsListComponent,
113
+ ),
114
+ docTagDocListComponent: Joi.string().default(
115
+ DEFAULT_OPTIONS.docTagDocListComponent,
116
+ ),
117
+ docCategoryGeneratedIndexComponent: Joi.string().default(
118
+ DEFAULT_OPTIONS.docCategoryGeneratedIndexComponent,
119
+ ),
89
120
  remarkPlugins: RemarkPluginsSchema.default(DEFAULT_OPTIONS.remarkPlugins),
90
121
  rehypePlugins: RehypePluginsSchema.default(DEFAULT_OPTIONS.rehypePlugins),
91
122
  beforeDefaultRemarkPlugins: RemarkPluginsSchema.default(
@@ -101,9 +132,6 @@ export const OptionsSchema = Joi.object({
101
132
  showLastUpdateAuthor: Joi.bool().default(
102
133
  DEFAULT_OPTIONS.showLastUpdateAuthor,
103
134
  ),
104
- excludeNextVersionDocs: Joi.bool().default(
105
- DEFAULT_OPTIONS.excludeNextVersionDocs,
106
- ),
107
135
  includeCurrentVersion: Joi.bool().default(
108
136
  DEFAULT_OPTIONS.includeCurrentVersion,
109
137
  ),
@@ -115,27 +143,30 @@ export const OptionsSchema = Joi.object({
115
143
 
116
144
  export function validateOptions({
117
145
  validate,
118
- options,
146
+ options: userOptions,
119
147
  }: OptionValidationContext<PluginOptions>): ValidationResult<PluginOptions> {
120
- // TODO remove homePageId before end of 2020
121
- // "slug: /" is better because the home doc can be different across versions
122
- if (options.homePageId) {
123
- console.log(
124
- chalk.red(
125
- `The docs plugin option homePageId=${options.homePageId} is deprecated. To make a doc the "home", prefer frontmatter: "slug: /"`,
126
- ),
127
- );
128
- }
148
+ let options = userOptions;
129
149
 
130
- if (typeof options.excludeNextVersionDocs !== 'undefined') {
131
- console.log(
132
- chalk.red(
133
- `The docs plugin option "excludeNextVersionDocs=${
134
- options.excludeNextVersionDocs
135
- }" is deprecated. Use the "includeCurrentVersion=${!options.excludeNextVersionDocs}" option instead!"`,
136
- ),
137
- );
138
- options.includeCurrentVersion = !options.excludeNextVersionDocs;
150
+ if (options.sidebarCollapsible === false) {
151
+ // When sidebarCollapsible=false and sidebarCollapsed=undefined, we don't want to have the inconsistency warning
152
+ // We let options.sidebarCollapsible become the default value for options.sidebarCollapsed
153
+ if (typeof options.sidebarCollapsed === 'undefined') {
154
+ options = {
155
+ ...options,
156
+ sidebarCollapsed: false,
157
+ };
158
+ }
159
+ if (options.sidebarCollapsed) {
160
+ console.warn(
161
+ chalk.yellow(
162
+ 'The docs plugin config is inconsistent. It does not make sense to use sidebarCollapsible=false and sidebarCollapsed=true at the same time. sidebarCollapsed=false will be ignored.',
163
+ ),
164
+ );
165
+ options = {
166
+ ...options,
167
+ sidebarCollapsed: false,
168
+ };
169
+ }
139
170
  }
140
171
 
141
172
  const normalizedOptions = validate(OptionsSchema, options);
@@ -5,58 +5,90 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- /* eslint-disable camelcase */
8
+ declare module '@docusaurus/plugin-content-docs' {
9
+ export type Options = Partial<import('./types').PluginOptions>;
10
+ export type SidebarsConfig = import('./sidebars/types').SidebarsConfig;
11
+ export type VersionBanner = import('./types').VersionBanner;
12
+ type GlobalDataVersion = import('./types').GlobalVersion;
13
+ type GlobalDataDoc = import('./types').GlobalDoc;
14
+ type VersionTag = import('./types').VersionTag;
9
15
 
10
- declare module '@docusaurus/plugin-content-docs-types' {
11
- export type PermalinkToSidebar = {
12
- [permalink: string]: string;
16
+ export type {GlobalDataVersion, GlobalDataDoc};
17
+
18
+ export type PropNavigationLink = {
19
+ readonly title: string;
20
+ readonly permalink: string;
21
+ };
22
+ export type PropNavigation = {
23
+ readonly previous?: PropNavigationLink;
24
+ readonly next?: PropNavigationLink;
13
25
  };
14
26
 
27
+ export type PropVersionDoc = import('./sidebars/types').PropVersionDoc;
28
+ export type PropVersionDocs = import('./sidebars/types').PropVersionDocs;
29
+
15
30
  export type PropVersionMetadata = {
16
31
  pluginId: string;
17
32
  version: string;
18
33
  label: string;
34
+ banner: VersionBanner | null;
35
+ badge: boolean;
36
+ className: string;
19
37
  isLast: boolean;
20
38
  docsSidebars: PropSidebars;
21
- permalinkToSidebar: PermalinkToSidebar;
39
+ docs: PropVersionDocs;
22
40
  };
23
41
 
24
- type PropsSidebarItemBase = {
25
- customProps?: Record<string, unknown>;
42
+ export type PropCategoryGeneratedIndex = {
43
+ title: string;
44
+ description?: string;
45
+ slug: string;
46
+ permalink: string;
47
+ navigation: PropNavigation;
26
48
  };
27
49
 
28
- export type PropSidebarItemLink = PropsSidebarItemBase & {
29
- type: 'link';
30
- href: string;
31
- label: string;
32
- };
50
+ export type PropSidebarItemLink =
51
+ import('./sidebars/types').PropSidebarItemLink;
52
+ export type PropSidebarItemCategory =
53
+ import('./sidebars/types').PropSidebarItemCategory;
54
+ export type PropSidebarItem = import('./sidebars/types').PropSidebarItem;
55
+ export type PropSidebar = import('./sidebars/types').PropSidebar;
56
+ export type PropSidebars = import('./sidebars/types').PropSidebars;
33
57
 
34
- export type PropSidebarItemCategory = PropsSidebarItemBase & {
35
- type: 'category';
36
- label: string;
37
- items: PropSidebarItem[];
38
- collapsed?: boolean;
58
+ export type PropTagDocListDoc = {
59
+ id: string;
60
+ title: string;
61
+ description: string;
62
+ permalink: string;
39
63
  };
40
-
41
- export type PropSidebarItem = PropSidebarItemLink | PropSidebarItemCategory;
42
-
43
- export type PropSidebars = {
44
- [sidebarId: string]: PropSidebarItem[];
64
+ export type PropTagDocList = {
65
+ allTagsPath: string;
66
+ name: string; // normalized name/label of the tag
67
+ permalink: string; // pathname of the tag
68
+ docs: PropTagDocListDoc[];
45
69
  };
46
70
 
47
- export type {
48
- GlobalVersion as GlobalDataVersion,
49
- GlobalDoc as GlobalDataDoc,
50
- } from './types';
71
+ export type PropTagsListPage = {
72
+ tags: {
73
+ name: string;
74
+ permalink: string;
75
+ count: number;
76
+ }[];
77
+ };
51
78
  }
52
79
 
53
80
  declare module '@theme/DocItem' {
54
81
  import type {TOCItem} from '@docusaurus/types';
82
+ import type {
83
+ PropNavigationLink,
84
+ PropVersionMetadata,
85
+ } from '@docusaurus/plugin-content-docs';
55
86
 
56
87
  export type DocumentRoute = {
57
88
  readonly component: () => JSX.Element;
58
89
  readonly exact: boolean;
59
90
  readonly path: string;
91
+ readonly sidebar?: string;
60
92
  };
61
93
 
62
94
  export type FrontMatter = {
@@ -66,6 +98,8 @@ declare module '@theme/DocItem' {
66
98
  readonly keywords?: readonly string[];
67
99
  readonly hide_title?: boolean;
68
100
  readonly hide_table_of_contents?: boolean;
101
+ readonly toc_min_heading_level?: number;
102
+ readonly toc_max_heading_level?: number;
69
103
  };
70
104
 
71
105
  export type Metadata = {
@@ -77,12 +111,17 @@ declare module '@theme/DocItem' {
77
111
  readonly formattedLastUpdatedAt?: string;
78
112
  readonly lastUpdatedBy?: string;
79
113
  readonly version?: string;
80
- readonly previous?: {readonly permalink: string; readonly title: string};
81
- readonly next?: {readonly permalink: string; readonly title: string};
114
+ readonly previous?: PropNavigationLink;
115
+ readonly next?: PropNavigationLink;
116
+ readonly tags: readonly {
117
+ readonly label: string;
118
+ readonly permalink: string;
119
+ }[];
82
120
  };
83
121
 
84
- export type Props = {
122
+ export interface Props {
85
123
  readonly route: DocumentRoute;
124
+ readonly versionMetadata: PropVersionMetadata;
86
125
  readonly content: {
87
126
  readonly frontMatter: FrontMatter;
88
127
  readonly metadata: Metadata;
@@ -90,17 +129,87 @@ declare module '@theme/DocItem' {
90
129
  readonly contentTitle: string | undefined;
91
130
  (): JSX.Element;
92
131
  };
93
- };
132
+ }
94
133
 
95
134
  const DocItem: (props: Props) => JSX.Element;
96
135
  export default DocItem;
97
136
  }
98
137
 
138
+ declare module '@theme/DocCard' {
139
+ import type {PropSidebarItem} from '@docusaurus/plugin-content-docs';
140
+
141
+ export interface Props {
142
+ readonly item: PropSidebarItem;
143
+ }
144
+
145
+ export default function DocCard(props: Props): JSX.Element;
146
+ }
147
+
148
+ declare module '@theme/DocCardList' {
149
+ import type {PropSidebarItem} from '@docusaurus/plugin-content-docs';
150
+
151
+ export interface Props {
152
+ readonly items: PropSidebarItem[];
153
+ }
154
+
155
+ export default function DocCardList(props: Props): JSX.Element;
156
+ }
157
+
158
+ declare module '@theme/DocCategoryGeneratedIndexPage' {
159
+ import type {PropCategoryGeneratedIndex} from '@docusaurus/plugin-content-docs';
160
+
161
+ export interface Props {
162
+ readonly categoryGeneratedIndex: PropCategoryGeneratedIndex;
163
+ }
164
+
165
+ export default function DocCategoryGeneratedIndexPage(
166
+ props: Props,
167
+ ): JSX.Element;
168
+ }
169
+
170
+ declare module '@theme/DocItemFooter' {
171
+ import type {Props} from '@theme/DocItem';
172
+
173
+ export default function DocItemFooter(props: Props): JSX.Element;
174
+ }
175
+
176
+ declare module '@theme/DocTagsListPage' {
177
+ import type {PropTagsListPage} from '@docusaurus/plugin-content-docs';
178
+
179
+ export interface Props extends PropTagsListPage {}
180
+ export default function DocTagsListPage(props: Props): JSX.Element;
181
+ }
182
+
183
+ declare module '@theme/DocTagDocListPage' {
184
+ import type {PropTagDocList} from '@docusaurus/plugin-content-docs';
185
+
186
+ export interface Props {
187
+ readonly tag: PropTagDocList;
188
+ }
189
+ export default function DocTagDocListPage(props: Props): JSX.Element;
190
+ }
191
+
192
+ declare module '@theme/DocVersionBanner' {
193
+ export interface Props {
194
+ readonly className?: string;
195
+ }
196
+
197
+ export default function DocVersionBanner(props: Props): JSX.Element;
198
+ }
199
+
200
+ declare module '@theme/DocVersionBadge' {
201
+ export interface Props {
202
+ readonly className?: string;
203
+ }
204
+
205
+ export default function DocVersionBadge(props: Props): JSX.Element;
206
+ }
207
+
99
208
  declare module '@theme/DocPage' {
100
- import type {PropVersionMetadata} from '@docusaurus/plugin-content-docs-types';
209
+ import type {PropVersionMetadata} from '@docusaurus/plugin-content-docs';
101
210
  import type {DocumentRoute} from '@theme/DocItem';
102
211
 
103
- export type Props = {
212
+ export interface Props {
104
213
  readonly location: {readonly pathname: string};
105
214
  readonly versionMetadata: PropVersionMetadata;
106
215
  readonly route: {
@@ -108,20 +217,55 @@ declare module '@theme/DocPage' {
108
217
  readonly component: () => JSX.Element;
109
218
  readonly routes: DocumentRoute[];
110
219
  };
111
- };
220
+ }
112
221
 
113
222
  const DocPage: (props: Props) => JSX.Element;
114
223
  export default DocPage;
115
224
  }
116
225
 
117
226
  declare module '@theme/Seo' {
118
- export type Props = {
227
+ import type {ReactNode} from 'react';
228
+
229
+ export interface Props {
119
230
  readonly title?: string;
120
231
  readonly description?: string;
121
232
  readonly keywords?: readonly string[] | string;
122
233
  readonly image?: string;
123
- };
234
+ readonly children?: ReactNode;
235
+ }
124
236
 
125
237
  const Seo: (props: Props) => JSX.Element;
126
238
  export default Seo;
127
239
  }
240
+
241
+ declare module '@theme/hooks/useDocs' {
242
+ type GlobalPluginData = import('./types').GlobalPluginData;
243
+ type GlobalVersion = import('./types').GlobalVersion;
244
+ type ActivePlugin = import('./client/docsClientUtils').ActivePlugin;
245
+ type ActiveDocContext = import('./client/docsClientUtils').ActiveDocContext;
246
+ type DocVersionSuggestions =
247
+ import('./client/docsClientUtils').DocVersionSuggestions;
248
+ type GetActivePluginOptions =
249
+ import('./client/docsClientUtils').GetActivePluginOptions;
250
+
251
+ export type {GlobalPluginData, GlobalVersion};
252
+ export const useAllDocsData: () => Record<string, GlobalPluginData>;
253
+ export const useDocsData: (pluginId?: string) => GlobalPluginData;
254
+ export const useActivePlugin: (
255
+ options?: GetActivePluginOptions,
256
+ ) => ActivePlugin | undefined;
257
+ export const useActivePluginAndVersion: (
258
+ options?: GetActivePluginOptions,
259
+ ) =>
260
+ | {activePlugin: ActivePlugin; activeVersion: GlobalVersion | undefined}
261
+ | undefined;
262
+ export const useVersions: (pluginId?: string) => GlobalVersion[];
263
+ export const useLatestVersion: (pluginId?: string) => GlobalVersion;
264
+ export const useActiveVersion: (
265
+ pluginId?: string,
266
+ ) => GlobalVersion | undefined;
267
+ export const useActiveDocContext: (pluginId?: string) => ActiveDocContext;
268
+ export const useDocVersionSuggestions: (
269
+ pluginId?: string,
270
+ ) => DocVersionSuggestions;
271
+ }
package/src/props.ts CHANGED
@@ -5,26 +5,31 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import {
9
- LoadedVersion,
8
+ import type {LoadedVersion, VersionTag, DocMetadata} from './types';
9
+ import type {
10
10
  SidebarItemDoc,
11
- SidebarItemLink,
12
11
  SidebarItem,
13
- } from './types';
14
- import {
12
+ SidebarItemCategory,
13
+ SidebarItemCategoryLink,
14
+ PropVersionDocs,
15
+ } from './sidebars/types';
16
+ import type {
15
17
  PropSidebars,
16
18
  PropVersionMetadata,
17
19
  PropSidebarItem,
18
- } from '@docusaurus/plugin-content-docs-types';
19
- import {keyBy, mapValues} from 'lodash';
20
+ PropSidebarItemCategory,
21
+ PropTagDocList,
22
+ PropTagDocListDoc,
23
+ PropSidebarItemLink,
24
+ } from '@docusaurus/plugin-content-docs';
25
+ import {compact, keyBy, mapValues} from 'lodash';
26
+ import {createDocsByIdIndex} from './docs';
20
27
 
21
28
  export function toSidebarsProp(loadedVersion: LoadedVersion): PropSidebars {
22
- const docsById = keyBy(loadedVersion.docs, (doc) => doc.id);
29
+ const docsById = createDocsByIdIndex(loadedVersion.docs);
23
30
 
24
- const convertDocLink = (item: SidebarItemDoc): SidebarItemLink => {
25
- const docId = item.id;
31
+ function getDocById(docId: string): DocMetadata {
26
32
  const docMetadata = docsById[docId];
27
-
28
33
  if (!docMetadata) {
29
34
  throw new Error(
30
35
  `Invalid sidebars file. The document with id "${docId}" was used in the sidebar, but no document with this id could be found.
@@ -32,25 +37,49 @@ Available document ids are:
32
37
  - ${Object.keys(docsById).sort().join('\n- ')}`,
33
38
  );
34
39
  }
40
+ return docMetadata;
41
+ }
35
42
 
43
+ const convertDocLink = (item: SidebarItemDoc): PropSidebarItemLink => {
44
+ const docMetadata = getDocById(item.id);
36
45
  const {
37
46
  title,
38
47
  permalink,
39
48
  frontMatter: {sidebar_label: sidebarLabel},
40
49
  } = docMetadata;
41
-
42
50
  return {
43
51
  type: 'link',
44
52
  label: sidebarLabel || item.label || title,
45
53
  href: permalink,
54
+ className: item.className,
46
55
  customProps: item.customProps,
56
+ docId: docMetadata.unversionedId,
47
57
  };
48
58
  };
49
59
 
50
- const normalizeItem = (item: SidebarItem): PropSidebarItem => {
60
+ function getCategoryLinkHref(
61
+ link: SidebarItemCategoryLink | undefined,
62
+ ): string | undefined {
63
+ switch (link?.type) {
64
+ case 'doc':
65
+ return getDocById(link.id).permalink;
66
+ case 'generated-index':
67
+ return link.permalink;
68
+ default:
69
+ return undefined;
70
+ }
71
+ }
72
+
73
+ function convertCategory(item: SidebarItemCategory): PropSidebarItemCategory {
74
+ const {link, ...rest} = item;
75
+ const href = getCategoryLinkHref(link);
76
+ return {...rest, items: item.items.map(normalizeItem), ...(href && {href})};
77
+ }
78
+
79
+ function normalizeItem(item: SidebarItem): PropSidebarItem {
51
80
  switch (item.type) {
52
81
  case 'category':
53
- return {...item, items: item.items.map(normalizeItem)};
82
+ return convertCategory(item);
54
83
  case 'ref':
55
84
  case 'doc':
56
85
  return convertDocLink(item);
@@ -58,7 +87,7 @@ Available document ids are:
58
87
  default:
59
88
  return item;
60
89
  }
61
- };
90
+ }
62
91
 
63
92
  // Transform the sidebar so that all sidebar item will be in the
64
93
  // form of 'link' or 'category' only.
@@ -66,6 +95,18 @@ Available document ids are:
66
95
  return mapValues(loadedVersion.sidebars, (items) => items.map(normalizeItem));
67
96
  }
68
97
 
98
+ function toVersionDocsProp(loadedVersion: LoadedVersion): PropVersionDocs {
99
+ return mapValues(
100
+ keyBy(loadedVersion.docs, (doc) => doc.unversionedId),
101
+ (doc) => ({
102
+ id: doc.unversionedId,
103
+ title: doc.title,
104
+ description: doc.description,
105
+ sidebar: doc.sidebar,
106
+ }),
107
+ );
108
+ }
109
+
69
110
  export function toVersionMetadataProp(
70
111
  pluginId: string,
71
112
  loadedVersion: LoadedVersion,
@@ -74,8 +115,42 @@ export function toVersionMetadataProp(
74
115
  pluginId,
75
116
  version: loadedVersion.versionName,
76
117
  label: loadedVersion.versionLabel,
118
+ banner: loadedVersion.versionBanner,
119
+ badge: loadedVersion.versionBadge,
120
+ className: loadedVersion.versionClassName,
77
121
  isLast: loadedVersion.isLast,
78
122
  docsSidebars: toSidebarsProp(loadedVersion),
79
- permalinkToSidebar: loadedVersion.permalinkToSidebar,
123
+ docs: toVersionDocsProp(loadedVersion),
124
+ };
125
+ }
126
+
127
+ export function toTagDocListProp({
128
+ allTagsPath,
129
+ tag,
130
+ docs,
131
+ }: {
132
+ allTagsPath: string;
133
+ tag: VersionTag;
134
+ docs: Pick<DocMetadata, 'id' | 'title' | 'description' | 'permalink'>[];
135
+ }): PropTagDocList {
136
+ function toDocListProp(): PropTagDocListDoc[] {
137
+ const list = compact(
138
+ tag.docIds.map((id) => docs.find((doc) => doc.id === id)),
139
+ );
140
+ // Sort docs by title
141
+ list.sort((doc1, doc2) => doc1.title.localeCompare(doc2.title));
142
+ return list.map((doc) => ({
143
+ id: doc.id,
144
+ title: doc.title,
145
+ description: doc.description,
146
+ permalink: doc.permalink,
147
+ }));
148
+ }
149
+
150
+ return {
151
+ name: tag.name,
152
+ permalink: tag.permalink,
153
+ docs: toDocListProp(),
154
+ allTagsPath,
80
155
  };
81
156
  }