@docusaurus/plugin-content-docs 2.0.0-beta.18 → 2.0.0-beta.19

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 (76) hide show
  1. package/lib/categoryGeneratedIndex.d.ts +1 -1
  2. package/lib/categoryGeneratedIndex.js +4 -2
  3. package/lib/cli.d.ts +3 -2
  4. package/lib/cli.js +45 -35
  5. package/lib/client/docsClientUtils.d.ts +6 -5
  6. package/lib/client/docsClientUtils.js +8 -10
  7. package/lib/client/index.d.ts +9 -8
  8. package/lib/client/index.js +30 -33
  9. package/lib/constants.d.ts +4 -0
  10. package/lib/constants.js +4 -1
  11. package/lib/docs.d.ts +5 -3
  12. package/lib/docs.js +18 -13
  13. package/lib/frontMatter.d.ts +1 -1
  14. package/lib/frontMatter.js +3 -0
  15. package/lib/globalData.d.ts +2 -2
  16. package/lib/globalData.js +6 -6
  17. package/lib/index.d.ts +1 -2
  18. package/lib/index.js +31 -23
  19. package/lib/markdown/linkify.js +1 -2
  20. package/lib/props.d.ts +3 -3
  21. package/lib/props.js +7 -6
  22. package/lib/routes.d.ts +5 -4
  23. package/lib/routes.js +9 -23
  24. package/lib/server-export.d.ts +2 -1
  25. package/lib/server-export.js +3 -4
  26. package/lib/sidebars/generator.js +3 -3
  27. package/lib/sidebars/index.js +0 -2
  28. package/lib/sidebars/normalization.js +1 -1
  29. package/lib/sidebars/postProcessor.js +2 -2
  30. package/lib/sidebars/processor.js +14 -3
  31. package/lib/sidebars/types.d.ts +18 -14
  32. package/lib/sidebars/utils.d.ts +3 -3
  33. package/lib/slug.d.ts +1 -2
  34. package/lib/tags.d.ts +2 -1
  35. package/lib/tags.js +1 -1
  36. package/lib/translations.d.ts +3 -3
  37. package/lib/translations.js +3 -53
  38. package/lib/types.d.ts +8 -96
  39. package/lib/versions/files.d.ts +44 -0
  40. package/lib/versions/files.js +142 -0
  41. package/lib/versions/index.d.ts +36 -0
  42. package/lib/versions/index.js +155 -0
  43. package/lib/versions/validation.d.ts +17 -0
  44. package/lib/versions/validation.js +71 -0
  45. package/package.json +14 -12
  46. package/src/categoryGeneratedIndex.ts +8 -3
  47. package/src/cli.ts +62 -65
  48. package/src/client/docsClientUtils.ts +11 -13
  49. package/src/client/index.ts +41 -42
  50. package/src/constants.ts +4 -2
  51. package/src/docs.ts +41 -26
  52. package/src/frontMatter.ts +6 -3
  53. package/src/globalData.ts +10 -10
  54. package/src/index.ts +44 -38
  55. package/src/markdown/linkify.ts +2 -3
  56. package/src/plugin-content-docs.d.ts +447 -113
  57. package/src/props.ts +12 -9
  58. package/src/routes.ts +13 -39
  59. package/src/server-export.ts +1 -3
  60. package/src/sidebars/generator.ts +4 -4
  61. package/src/sidebars/index.ts +0 -2
  62. package/src/sidebars/normalization.ts +1 -1
  63. package/src/sidebars/postProcessor.ts +2 -2
  64. package/src/sidebars/processor.ts +24 -5
  65. package/src/sidebars/types.ts +20 -19
  66. package/src/sidebars/utils.ts +6 -3
  67. package/src/slug.ts +4 -2
  68. package/src/tags.ts +3 -2
  69. package/src/translations.ts +10 -61
  70. package/src/types.ts +13 -106
  71. package/src/versions/files.ts +220 -0
  72. package/src/versions/index.ts +247 -0
  73. package/src/versions/validation.ts +113 -0
  74. package/lib/versions.d.ts +0 -41
  75. package/lib/versions.js +0 -324
  76. package/src/versions.ts +0 -606
package/src/props.ts CHANGED
@@ -5,13 +5,12 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import type {LoadedVersion, VersionTag, DocMetadata} from './types';
8
+ import type {VersionTag} from './types';
9
9
  import type {
10
10
  SidebarItemDoc,
11
11
  SidebarItem,
12
12
  SidebarItemCategory,
13
13
  SidebarItemCategoryLink,
14
- PropVersionDocs,
15
14
  } from './sidebars/types';
16
15
  import type {
17
16
  PropSidebars,
@@ -21,6 +20,9 @@ import type {
21
20
  PropTagDocList,
22
21
  PropTagDocListDoc,
23
22
  PropSidebarItemLink,
23
+ PropVersionDocs,
24
+ DocMetadata,
25
+ LoadedVersion,
24
26
  } from '@docusaurus/plugin-content-docs';
25
27
  import _ from 'lodash';
26
28
  import {createDocsByIdIndex} from './docs';
@@ -119,10 +121,10 @@ export function toVersionMetadataProp(
119
121
  return {
120
122
  pluginId,
121
123
  version: loadedVersion.versionName,
122
- label: loadedVersion.versionLabel,
123
- banner: loadedVersion.versionBanner,
124
- badge: loadedVersion.versionBadge,
125
- className: loadedVersion.versionClassName,
124
+ label: loadedVersion.label,
125
+ banner: loadedVersion.banner,
126
+ badge: loadedVersion.badge,
127
+ className: loadedVersion.className,
126
128
  isLast: loadedVersion.isLast,
127
129
  docsSidebars: toSidebarsProp(loadedVersion),
128
130
  docs: toVersionDocsProp(loadedVersion),
@@ -136,7 +138,7 @@ export function toTagDocListProp({
136
138
  }: {
137
139
  allTagsPath: string;
138
140
  tag: VersionTag;
139
- docs: Pick<DocMetadata, 'id' | 'title' | 'description' | 'permalink'>[];
141
+ docs: DocMetadata[];
140
142
  }): PropTagDocList {
141
143
  function toDocListProp(): PropTagDocListDoc[] {
142
144
  const list = _.compact(
@@ -153,9 +155,10 @@ export function toTagDocListProp({
153
155
  }
154
156
 
155
157
  return {
156
- name: tag.name,
158
+ label: tag.label,
157
159
  permalink: tag.permalink,
158
- docs: toDocListProp(),
159
160
  allTagsPath,
161
+ count: tag.docIds.length,
162
+ items: toDocListProp(),
160
163
  };
161
164
  }
package/src/routes.ts CHANGED
@@ -7,12 +7,11 @@
7
7
 
8
8
  import type {PluginContentLoadedActions, RouteConfig} from '@docusaurus/types';
9
9
  import {docuHash, createSlugger} from '@docusaurus/utils';
10
+ import type {FullVersion} from './types';
10
11
  import type {
11
12
  CategoryGeneratedIndexMetadata,
12
13
  DocMetadata,
13
- LoadedVersion,
14
- } from './types';
15
- import type {PropCategoryGeneratedIndex} from '@docusaurus/plugin-content-docs';
14
+ } from '@docusaurus/plugin-content-docs';
16
15
  import {toVersionMetadataProp} from './props';
17
16
  import logger from '@docusaurus/logger';
18
17
 
@@ -22,7 +21,7 @@ export async function createCategoryGeneratedIndexRoutes({
22
21
  docCategoryGeneratedIndexComponent,
23
22
  aliasedSource,
24
23
  }: {
25
- version: LoadedVersion;
24
+ version: FullVersion;
26
25
  actions: PluginContentLoadedActions;
27
26
  docCategoryGeneratedIndexComponent: string;
28
27
  aliasedSource: (str: string) => string;
@@ -32,42 +31,19 @@ export async function createCategoryGeneratedIndexRoutes({
32
31
  async function createCategoryGeneratedIndexRoute(
33
32
  categoryGeneratedIndex: CategoryGeneratedIndexMetadata,
34
33
  ): Promise<RouteConfig> {
35
- const {
36
- sidebar,
37
- title,
38
- description,
39
- slug,
40
- permalink,
41
- previous,
42
- next,
43
- image,
44
- keywords,
45
- } = categoryGeneratedIndex;
34
+ const {sidebar, ...prop} = categoryGeneratedIndex;
46
35
 
47
36
  const propFileName = slugs.slug(
48
- `${version.versionPath}-${categoryGeneratedIndex.sidebar}-category-${categoryGeneratedIndex.title}`,
37
+ `${version.path}-${categoryGeneratedIndex.sidebar}-category-${categoryGeneratedIndex.title}`,
49
38
  );
50
39
 
51
- const prop: PropCategoryGeneratedIndex = {
52
- title,
53
- description,
54
- slug,
55
- permalink,
56
- image,
57
- keywords,
58
- navigation: {
59
- previous,
60
- next,
61
- },
62
- };
63
-
64
40
  const propData = await actions.createData(
65
41
  `${docuHash(`category/${propFileName}`)}.json`,
66
42
  JSON.stringify(prop, null, 2),
67
43
  );
68
44
 
69
45
  return {
70
- path: permalink,
46
+ path: categoryGeneratedIndex.permalink,
71
47
  component: docCategoryGeneratedIndexComponent,
72
48
  exact: true,
73
49
  modules: {
@@ -123,7 +99,7 @@ export async function createDocRoutes({
123
99
  }
124
100
 
125
101
  export async function createVersionRoutes({
126
- loadedVersion,
102
+ version,
127
103
  actions,
128
104
  docItemComponent,
129
105
  docLayoutComponent,
@@ -131,7 +107,7 @@ export async function createVersionRoutes({
131
107
  pluginId,
132
108
  aliasedSource,
133
109
  }: {
134
- loadedVersion: LoadedVersion;
110
+ version: FullVersion;
135
111
  actions: PluginContentLoadedActions;
136
112
  docLayoutComponent: string;
137
113
  docItemComponent: string;
@@ -139,7 +115,7 @@ export async function createVersionRoutes({
139
115
  pluginId: string;
140
116
  aliasedSource: (str: string) => string;
141
117
  }): Promise<void> {
142
- async function doCreateVersionRoutes(version: LoadedVersion): Promise<void> {
118
+ async function doCreateVersionRoutes(): Promise<void> {
143
119
  const versionMetadata = toVersionMetadataProp(pluginId, version);
144
120
  const versionMetadataPropPath = await actions.createData(
145
121
  `${docuHash(`version-${version.versionName}-metadata-prop`)}.json`,
@@ -162,12 +138,10 @@ export async function createVersionRoutes({
162
138
  }
163
139
 
164
140
  actions.addRoute({
165
- path: version.versionPath,
166
- // allow matching /docs/* as well
141
+ path: version.path,
142
+ // Allow matching /docs/* since this is the wrapping route
167
143
  exact: false,
168
- // main docs component (DocPage)
169
144
  component: docLayoutComponent,
170
- // sub-routes for each doc
171
145
  routes: await createVersionSubRoutes(),
172
146
  modules: {
173
147
  versionMetadata: aliasedSource(versionMetadataPropPath),
@@ -177,9 +151,9 @@ export async function createVersionRoutes({
177
151
  }
178
152
 
179
153
  try {
180
- return await doCreateVersionRoutes(loadedVersion);
154
+ return await doCreateVersionRoutes();
181
155
  } catch (err) {
182
- logger.error`Can't create version routes for version name=${loadedVersion.versionName}`;
156
+ logger.error`Can't create version routes for version name=${version.versionName}`;
183
157
  throw err;
184
158
  }
185
159
  }
@@ -18,7 +18,5 @@ export {
18
18
  getDefaultVersionBanner,
19
19
  getVersionBadge,
20
20
  getVersionBanner,
21
- getVersionsFilePath,
22
- readVersionsFile,
23
- readVersionNames,
24
21
  } from './versions';
22
+ export {readVersionNames} from './versions/files';
@@ -14,7 +14,7 @@ import type {
14
14
  SidebarItemCategoryLinkConfig,
15
15
  } from './types';
16
16
  import _ from 'lodash';
17
- import {addTrailingSlash, posixPath} from '@docusaurus/utils';
17
+ import {addTrailingSlash} from '@docusaurus/utils';
18
18
  import logger from '@docusaurus/logger';
19
19
  import path from 'path';
20
20
  import {createDocsByIdIndex, toCategoryIndexMatcherParam} from '../docs';
@@ -76,9 +76,9 @@ Available doc IDs:
76
76
  return (
77
77
  // Doc at the root of the autogenerated sidebar dir
78
78
  doc.sourceDirName === autogenDir ||
79
- // autogen dir is . and doc is in subfolder
79
+ // Autogen dir is . and doc is in subfolder
80
80
  autogenDir === '.' ||
81
- // autogen dir is not . and doc is in subfolder
81
+ // Autogen dir is not . and doc is in subfolder
82
82
  // "api/myDoc" startsWith "api/" (note "api2/myDoc" is not included)
83
83
  doc.sourceDirName.startsWith(addTrailingSlash(autogenDir))
84
84
  );
@@ -157,7 +157,7 @@ Available doc IDs:
157
157
  folderName: string,
158
158
  ): WithPosition<NormalizedSidebarItemCategory> {
159
159
  const categoryMetadata =
160
- categoriesMetadata[posixPath(path.join(autogenDir, fullPath))];
160
+ categoriesMetadata[path.posix.join(autogenDir, fullPath)];
161
161
  const allItems = Object.entries(dir).map(([key, content]) =>
162
162
  dirToItem(content, key, `${fullPath}/${key}`),
163
163
  );
@@ -32,7 +32,6 @@ export const DefaultSidebars: SidebarsConfig = {
32
32
  export const DisabledSidebars: SidebarsConfig = {};
33
33
 
34
34
  // If a path is provided, make it absolute
35
- // use this before loadSidebars()
36
35
  export function resolveSidebarPathOption(
37
36
  siteDir: string,
38
37
  sidebarPathOption: PluginOptions['sidebarPath'],
@@ -93,7 +92,6 @@ export async function loadSidebarsFileUnsafe(
93
92
  return importFresh(sidebarFilePath);
94
93
  }
95
94
 
96
- // Note: sidebarFilePath must be absolute, use resolveSidebarPathOption
97
95
  export async function loadSidebars(
98
96
  sidebarFilePath: string | false | undefined,
99
97
  options: SidebarProcessorParams,
@@ -65,7 +65,7 @@ function normalizeSidebar(
65
65
  throw new Error(
66
66
  logger.interpolate`Invalid sidebar items collection code=${JSON.stringify(
67
67
  sidebar,
68
- )} in ${place}: it must either be an array of sidebar items or a shorthand notation (which doesn't contain a code=${'type'} property). See path=${'https://docusaurus.io/docs/sidebar/items'} for all valid syntaxes.`,
68
+ )} in ${place}: it must either be an array of sidebar items or a shorthand notation (which doesn't contain a code=${'type'} property). See url=${'https://docusaurus.io/docs/sidebar/items'} for all valid syntaxes.`,
69
69
  );
70
70
  }
71
71
 
@@ -22,11 +22,11 @@ function normalizeCategoryLink(
22
22
  params: SidebarProcessorParams,
23
23
  ): SidebarItemCategoryLink | undefined {
24
24
  if (category.link?.type === 'generated-index') {
25
- // default slug logic can be improved
25
+ // Default slug logic can be improved
26
26
  const getDefaultSlug = () =>
27
27
  `/category/${params.categoryLabelSlugger.slug(category.label)}`;
28
28
  const slug = category.link.slug ?? getDefaultSlug();
29
- const permalink = normalizeUrl([params.version.versionPath, slug]);
29
+ const permalink = normalizeUrl([params.version.path, slug]);
30
30
  return {
31
31
  ...category.link,
32
32
  slug,
@@ -5,7 +5,10 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import type {DocMetadataBase, VersionMetadata} from '../types';
8
+ import type {
9
+ DocMetadataBase,
10
+ VersionMetadata,
11
+ } from '@docusaurus/plugin-content-docs';
9
12
  import type {
10
13
  NormalizedSidebarItem,
11
14
  NormalizedSidebar,
@@ -23,7 +26,7 @@ import {DefaultSidebarItemsGenerator} from './generator';
23
26
  import {validateSidebars} from './validation';
24
27
  import _ from 'lodash';
25
28
  import combinePromises from 'combine-promises';
26
- import {isCategoryIndex} from '../docs';
29
+ import {getDocIds, isCategoryIndex} from '../docs';
27
30
 
28
31
  function toSidebarItemsGeneratorDoc(
29
32
  doc: DocMetadataBase,
@@ -52,7 +55,8 @@ async function processSidebar(
52
55
  categoriesMetadata: {[filePath: string]: CategoryMetadataFile},
53
56
  params: SidebarProcessorParams,
54
57
  ): Promise<ProcessedSidebar> {
55
- const {sidebarItemsGenerator, numberPrefixParser, docs, version} = params;
58
+ const {sidebarItemsGenerator, numberPrefixParser, docs, drafts, version} =
59
+ params;
56
60
 
57
61
  // Just a minor lazy transformation optimization
58
62
  const getSidebarItemsGeneratorDocsAndVersion = _.memoize(() => ({
@@ -78,6 +82,19 @@ async function processSidebar(
78
82
  return processItems(generatedItems);
79
83
  }
80
84
 
85
+ const draftIds = new Set(drafts.flatMap(getDocIds));
86
+
87
+ const isDraftItem = (item: NormalizedSidebarItem): boolean => {
88
+ if (item.type === 'doc' || item.type === 'ref') {
89
+ return draftIds.has(item.id);
90
+ }
91
+ // If a category only contains draft items, it should be filtered entirely.
92
+ if (item.type === 'category') {
93
+ return item.items.every(isDraftItem);
94
+ }
95
+ return false;
96
+ };
97
+
81
98
  async function processItem(
82
99
  item: NormalizedSidebarItem,
83
100
  ): Promise<ProcessedSidebarItem[]> {
@@ -85,7 +102,7 @@ async function processSidebar(
85
102
  return [
86
103
  {
87
104
  ...item,
88
- items: (await Promise.all(item.items.map(processItem))).flat(),
105
+ items: await processItems(item.items),
89
106
  },
90
107
  ];
91
108
  }
@@ -98,7 +115,9 @@ async function processSidebar(
98
115
  async function processItems(
99
116
  items: NormalizedSidebarItem[],
100
117
  ): Promise<ProcessedSidebarItem[]> {
101
- return (await Promise.all(items.map(processItem))).flat();
118
+ return (
119
+ await Promise.all(items.filter((i) => !isDraftItem(i)).map(processItem))
120
+ ).flat();
102
121
  }
103
122
 
104
123
  const processedSidebar = await processItems(unprocessedSidebar);
@@ -6,11 +6,12 @@
6
6
  */
7
7
 
8
8
  import type {Optional, Required} from 'utility-types';
9
- import type {DocMetadataBase, VersionMetadata} from '../types';
10
9
  import type {
11
10
  NumberPrefixParser,
12
11
  SidebarOptions,
13
12
  CategoryIndexMatcher,
13
+ DocMetadataBase,
14
+ VersionMetadata,
14
15
  } from '@docusaurus/plugin-content-docs';
15
16
  import type {Slugger} from '@docusaurus/utils';
16
17
 
@@ -179,7 +180,6 @@ export type PropSidebarItemCategory = Expand<
179
180
  }
180
181
  >;
181
182
 
182
- // we may want to use a union type in props instead of this generic link?
183
183
  export type PropSidebarItemLink = SidebarItemLink & {
184
184
  docId?: string;
185
185
  };
@@ -199,16 +199,6 @@ export type PropSidebarBreadcrumbsItem =
199
199
  | PropSidebarItemLink
200
200
  | PropSidebarItemCategory;
201
201
 
202
- export type PropVersionDoc = {
203
- id: string;
204
- title: string;
205
- description?: string;
206
- sidebar?: string;
207
- };
208
- export type PropVersionDocs = {
209
- [docId: string]: PropVersionDoc;
210
- };
211
-
212
202
  export type CategoryMetadataFile = {
213
203
  label?: string;
214
204
  position?: number;
@@ -243,31 +233,42 @@ export type SidebarItemsGeneratorVersion = Pick<
243
233
  >;
244
234
 
245
235
  export type SidebarItemsGeneratorArgs = {
236
+ /** The sidebar item with type "autogenerated" to be transformed. */
246
237
  item: SidebarItemAutogenerated;
238
+ /** Useful metadata for the version this sidebar belongs to. */
247
239
  version: SidebarItemsGeneratorVersion;
240
+ /** All the docs of that version (unfiltered). */
248
241
  docs: SidebarItemsGeneratorDoc[];
242
+ /** Number prefix parser configured for this plugin. */
249
243
  numberPrefixParser: NumberPrefixParser;
244
+ /** The default category index matcher which you can override. */
250
245
  isCategoryIndex: CategoryIndexMatcher;
246
+ /**
247
+ * Key is the path relative to the doc content directory, value is the
248
+ * category metadata file's content.
249
+ */
251
250
  categoriesMetadata: {[filePath: string]: CategoryMetadataFile};
252
251
  };
253
252
  export type SidebarItemsGenerator = (
254
253
  generatorArgs: SidebarItemsGeneratorArgs,
255
254
  ) => Promise<NormalizedSidebar>;
256
255
 
257
- // Also inject the default generator to conveniently wrap/enhance/sort the
258
- // default sidebar gen logic
259
- // see https://github.com/facebook/docusaurus/issues/4640#issuecomment-822292320
260
- export type SidebarItemsGeneratorOptionArgs = {
261
- defaultSidebarItemsGenerator: SidebarItemsGenerator;
262
- } & SidebarItemsGeneratorArgs;
263
256
  export type SidebarItemsGeneratorOption = (
264
- generatorArgs: SidebarItemsGeneratorOptionArgs,
257
+ generatorArgs: {
258
+ /**
259
+ * Useful to re-use/enhance the default sidebar generation logic from
260
+ * Docusaurus.
261
+ * @see https://github.com/facebook/docusaurus/issues/4640#issuecomment-822292320
262
+ */
263
+ defaultSidebarItemsGenerator: SidebarItemsGenerator;
264
+ } & SidebarItemsGeneratorArgs,
265
265
  ) => Promise<NormalizedSidebarItem[]>;
266
266
 
267
267
  export type SidebarProcessorParams = {
268
268
  sidebarItemsGenerator: SidebarItemsGeneratorOption;
269
269
  numberPrefixParser: NumberPrefixParser;
270
270
  docs: DocMetadataBase[];
271
+ drafts: DocMetadataBase[];
271
272
  version: VersionMetadata;
272
273
  categoryLabelSlugger: Slugger;
273
274
  sidebarOptions: SidebarOptions;
@@ -21,7 +21,10 @@ import type {
21
21
 
22
22
  import _ from 'lodash';
23
23
  import {toMessageRelativeFilePath} from '@docusaurus/utils';
24
- import type {DocMetadataBase, DocNavLink} from '../types';
24
+ import type {
25
+ DocMetadataBase,
26
+ PropNavigationLink,
27
+ } from '@docusaurus/plugin-content-docs';
25
28
 
26
29
  export function isCategoriesShorthand(
27
30
  item: SidebarItemConfig,
@@ -346,7 +349,7 @@ Available document ids are:
346
349
  };
347
350
  }
348
351
 
349
- export function toDocNavigationLink(doc: DocMetadataBase): DocNavLink {
352
+ export function toDocNavigationLink(doc: DocMetadataBase): PropNavigationLink {
350
353
  const {
351
354
  title,
352
355
  permalink,
@@ -361,7 +364,7 @@ export function toDocNavigationLink(doc: DocMetadataBase): DocNavLink {
361
364
  export function toNavigationLink(
362
365
  navigationItem: SidebarNavigationItem | undefined,
363
366
  docsById: {[docId: string]: DocMetadataBase},
364
- ): DocNavLink | undefined {
367
+ ): PropNavigationLink | undefined {
365
368
  function getDocById(docId: string) {
366
369
  const doc = docsById[docId];
367
370
  if (!doc) {
package/src/slug.ts CHANGED
@@ -15,9 +15,11 @@ import {
15
15
  DefaultNumberPrefixParser,
16
16
  stripPathNumberPrefixes,
17
17
  } from './numberPrefix';
18
- import type {DocMetadataBase} from './types';
19
18
  import {isCategoryIndex, toCategoryIndexMatcherParam} from './docs';
20
- import type {NumberPrefixParser} from '@docusaurus/plugin-content-docs';
19
+ import type {
20
+ NumberPrefixParser,
21
+ DocMetadataBase,
22
+ } from '@docusaurus/plugin-content-docs';
21
23
 
22
24
  export default function getSlug({
23
25
  baseID,
package/src/tags.ts CHANGED
@@ -6,13 +6,14 @@
6
6
  */
7
7
 
8
8
  import {groupTaggedItems} from '@docusaurus/utils';
9
- import type {VersionTags, DocMetadata} from './types';
9
+ import type {VersionTags} from './types';
10
+ import type {DocMetadata} from '@docusaurus/plugin-content-docs';
10
11
  import _ from 'lodash';
11
12
 
12
13
  export function getVersionTags(docs: DocMetadata[]): VersionTags {
13
14
  const groups = groupTaggedItems(docs, (doc) => doc.tags);
14
15
  return _.mapValues(groups, (group) => ({
15
- name: group.tag.label,
16
+ label: group.tag.label,
16
17
  docIds: group.items.map((item) => item.id),
17
18
  permalink: group.tag.permalink,
18
19
  }));
@@ -5,7 +5,10 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import type {LoadedVersion, LoadedContent} from './types';
8
+ import type {
9
+ LoadedVersion,
10
+ LoadedContent,
11
+ } from '@docusaurus/plugin-content-docs';
9
12
  import type {
10
13
  Sidebar,
11
14
  SidebarItemCategory,
@@ -22,7 +25,6 @@ import {
22
25
  import type {
23
26
  TranslationFileContent,
24
27
  TranslationFile,
25
- TranslationFiles,
26
28
  TranslationMessage,
27
29
  } from '@docusaurus/types';
28
30
  import {mergeTranslations} from '@docusaurus/utils';
@@ -54,50 +56,6 @@ function getNormalizedSidebarName({
54
56
  return rest.join('/');
55
57
  }
56
58
 
57
- /*
58
- // Do we need to translate doc metadata?
59
- // It seems translating front matter labels is good enough
60
- function getDocTranslations(doc: DocMetadata): TranslationFileContent {
61
- return {
62
- [`${doc.unversionedId}.title`]: {
63
- message: doc.title,
64
- description: `The title for doc with id=${doc.unversionedId}`,
65
- },
66
- ...(doc.sidebar_label
67
- ? {
68
- [`${doc.unversionedId}.sidebar_label`]: {
69
- message: doc.sidebar_label,
70
- description:
71
- `The sidebar label for doc with id=${doc.unversionedId}`,
72
- },
73
- }
74
- : undefined),
75
- };
76
- }
77
- function translateDoc(
78
- doc: DocMetadata,
79
- docsTranslations: TranslationFileContent,
80
- ): DocMetadata {
81
- return {
82
- ...doc,
83
- title: docsTranslations[`${doc.unversionedId}.title`]?.message ?? doc.title,
84
- sidebar_label:
85
- docsTranslations[`${doc.unversionedId}.sidebar_label`]?.message ??
86
- doc.sidebar_label,
87
- };
88
- }
89
-
90
- function getDocsTranslations(version: LoadedVersion): TranslationFileContent {
91
- return mergeTranslations(version.docs.map(getDocTranslations));
92
- }
93
- function translateDocs(
94
- docs: DocMetadata[],
95
- docsTranslations: TranslationFileContent,
96
- ): DocMetadata[] {
97
- return docs.map((doc) => translateDoc(doc, docsTranslations));
98
- }
99
- */
100
-
101
59
  function getSidebarTranslationFileContent(
102
60
  sidebar: Sidebar,
103
61
  sidebarName: string,
@@ -242,10 +200,10 @@ function translateSidebars(
242
200
  );
243
201
  }
244
202
 
245
- function getVersionTranslationFiles(version: LoadedVersion): TranslationFiles {
203
+ function getVersionTranslationFiles(version: LoadedVersion): TranslationFile[] {
246
204
  const versionTranslations: TranslationFileContent = {
247
205
  'version.label': {
248
- message: version.versionLabel,
206
+ message: version.label,
249
207
  description: `The label for version ${version.versionName}`,
250
208
  },
251
209
  };
@@ -253,17 +211,10 @@ function getVersionTranslationFiles(version: LoadedVersion): TranslationFiles {
253
211
  const sidebarsTranslations: TranslationFileContent =
254
212
  getSidebarsTranslations(version);
255
213
 
256
- // const docsTranslations: TranslationFileContent =
257
- // getDocsTranslations(version);
258
-
259
214
  return [
260
215
  {
261
216
  path: getVersionFileName(version.versionName),
262
- content: mergeTranslations([
263
- versionTranslations,
264
- sidebarsTranslations,
265
- // docsTranslations,
266
- ]),
217
+ content: mergeTranslations([versionTranslations, sidebarsTranslations]),
267
218
  },
268
219
  ];
269
220
  }
@@ -275,16 +226,14 @@ function translateVersion(
275
226
  translationFiles[getVersionFileName(version.versionName)]!.content;
276
227
  return {
277
228
  ...version,
278
- versionLabel:
279
- versionTranslations['version.label']?.message ?? version.versionLabel,
229
+ label: versionTranslations['version.label']?.message ?? version.label,
280
230
  sidebars: translateSidebars(version, versionTranslations),
281
- // docs: translateDocs(version.docs, versionTranslations),
282
231
  };
283
232
  }
284
233
 
285
234
  function getVersionsTranslationFiles(
286
235
  versions: LoadedVersion[],
287
- ): TranslationFiles {
236
+ ): TranslationFile[] {
288
237
  return versions.flatMap(getVersionTranslationFiles);
289
238
  }
290
239
  function translateVersions(
@@ -296,7 +245,7 @@ function translateVersions(
296
245
 
297
246
  export function getLoadedContentTranslationFiles(
298
247
  loadedContent: LoadedContent,
299
- ): TranslationFiles {
248
+ ): TranslationFile[] {
300
249
  return getVersionsTranslationFiles(loadedContent.loadedVersions);
301
250
  }
302
251
  export function translateLoadedContent(