@docusaurus/plugin-content-docs 0.0.0-4875 → 0.0.0-4876

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/lib/docs.js CHANGED
@@ -70,11 +70,9 @@ function doProcessDocMetadata({ docFile, versionMetadata, context, options, env,
70
70
  // (01-MyFolder/01-MyDoc.md => MyFolder/MyDoc)
71
71
  // but allow to disable this behavior with front matter
72
72
  parse_number_prefixes: parseNumberPrefixes = true, } = frontMatter;
73
- // ex: api/plugins/myDoc -> myDoc
74
- // ex: myDoc -> myDoc
73
+ // E.g. api/plugins/myDoc -> myDoc; myDoc -> myDoc
75
74
  const sourceFileNameWithoutExtension = path_1.default.basename(source, path_1.default.extname(source));
76
- // ex: api/plugins/myDoc -> api/plugins
77
- // ex: myDoc -> .
75
+ // E.g. api/plugins/myDoc -> api/plugins; myDoc -> .
78
76
  const sourceDirName = path_1.default.dirname(source);
79
77
  const { filename: unprefixedFileName, numberPrefix } = parseNumberPrefixes
80
78
  ? options.numberPrefixParser(sourceFileNameWithoutExtension)
@@ -208,7 +206,7 @@ function addDocNavigation(docsBase, sidebarsUtils, sidebarFilePath) {
208
206
  return { ...doc, sidebar: navigation.sidebarName, previous, next };
209
207
  }
210
208
  const docsWithNavigation = docsBase.map(addNavData);
211
- // sort to ensure consistent output for tests
209
+ // Sort to ensure consistent output for tests
212
210
  docsWithNavigation.sort((a, b) => a.id.localeCompare(b.id));
213
211
  return docsWithNavigation;
214
212
  }
@@ -276,7 +274,7 @@ function getDocIds(doc) {
276
274
  return [doc.unversionedId, doc.id];
277
275
  }
278
276
  exports.getDocIds = getDocIds;
279
- // docs are indexed by both versioned and unversioned ids at the same time
277
+ // Docs are indexed by both versioned and unversioned ids at the same time
280
278
  // TODO legacy retro-compatibility due to old versioned sidebars using
281
279
  // versioned doc ids ("id" should be removed & "versionedId" should be renamed
282
280
  // to "id")
@@ -14,11 +14,13 @@ const utils_validation_1 = require("@docusaurus/utils-validation");
14
14
  // We use default values in code instead
15
15
  const DocFrontMatterSchema = utils_validation_1.JoiFrontMatter.object({
16
16
  id: utils_validation_1.JoiFrontMatter.string(),
17
+ // See https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
17
18
  title: utils_validation_1.JoiFrontMatter.string().allow(''),
18
19
  hide_title: utils_validation_1.JoiFrontMatter.boolean(),
19
20
  hide_table_of_contents: utils_validation_1.JoiFrontMatter.boolean(),
20
21
  keywords: utils_validation_1.JoiFrontMatter.array().items(utils_validation_1.JoiFrontMatter.string().required()),
21
22
  image: utils_validation_1.URISchema,
23
+ // See https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
22
24
  description: utils_validation_1.JoiFrontMatter.string().allow(''),
23
25
  slug: utils_validation_1.JoiFrontMatter.string(),
24
26
  sidebar_label: utils_validation_1.JoiFrontMatter.string(),
package/lib/routes.js CHANGED
@@ -75,11 +75,9 @@ async function createVersionRoutes({ loadedVersion, actions, docItemComponent, d
75
75
  }
76
76
  actions.addRoute({
77
77
  path: version.path,
78
- // allow matching /docs/* as well
78
+ // Allow matching /docs/* since this is the wrapping route
79
79
  exact: false,
80
- // main docs component (DocPage)
81
80
  component: docLayoutComponent,
82
- // sub-routes for each doc
83
81
  routes: await createVersionSubRoutes(),
84
82
  modules: {
85
83
  versionMetadata: aliasedSource(versionMetadataPropPath),
@@ -41,9 +41,9 @@ Available doc IDs:
41
41
  return (
42
42
  // Doc at the root of the autogenerated sidebar dir
43
43
  doc.sourceDirName === autogenDir ||
44
- // autogen dir is . and doc is in subfolder
44
+ // Autogen dir is . and doc is in subfolder
45
45
  autogenDir === '.' ||
46
- // autogen dir is not . and doc is in subfolder
46
+ // Autogen dir is not . and doc is in subfolder
47
47
  // "api/myDoc" startsWith "api/" (note "api2/myDoc" is not included)
48
48
  doc.sourceDirName.startsWith((0, utils_1.addTrailingSlash)(autogenDir)));
49
49
  }
@@ -12,7 +12,7 @@ const utils_1 = require("@docusaurus/utils");
12
12
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
13
13
  function normalizeCategoryLink(category, params) {
14
14
  if (category.link?.type === 'generated-index') {
15
- // default slug logic can be improved
15
+ // Default slug logic can be improved
16
16
  const getDefaultSlug = () => `/category/${params.categoryLabelSlugger.slug(category.label)}`;
17
17
  const slug = category.link.slug ?? getDefaultSlug();
18
18
  const permalink = (0, utils_1.normalizeUrl)([params.version.path, slug]);
@@ -150,7 +150,7 @@ export declare type SidebarItemsGeneratorArgs = {
150
150
  /** The default category index matcher which you can override. */
151
151
  isCategoryIndex: CategoryIndexMatcher;
152
152
  /**
153
- * key is the path relative to the doc content directory, value is the
153
+ * Key is the path relative to the doc content directory, value is the
154
154
  * category metadata file's content.
155
155
  */
156
156
  categoriesMetadata: {
@@ -30,49 +30,6 @@ function getNormalizedSidebarName({ versionName, sidebarName, }) {
30
30
  const [, ...rest] = sidebarName.split('/');
31
31
  return rest.join('/');
32
32
  }
33
- /*
34
- // Do we need to translate doc metadata?
35
- // It seems translating front matter labels is good enough
36
- function getDocTranslations(doc: DocMetadata): TranslationFileContent {
37
- return {
38
- [`${doc.unversionedId}.title`]: {
39
- message: doc.title,
40
- description: `The title for doc with id=${doc.unversionedId}`,
41
- },
42
- ...(doc.sidebar_label
43
- ? {
44
- [`${doc.unversionedId}.sidebar_label`]: {
45
- message: doc.sidebar_label,
46
- description:
47
- `The sidebar label for doc with id=${doc.unversionedId}`,
48
- },
49
- }
50
- : undefined),
51
- };
52
- }
53
- function translateDoc(
54
- doc: DocMetadata,
55
- docsTranslations: TranslationFileContent,
56
- ): DocMetadata {
57
- return {
58
- ...doc,
59
- title: docsTranslations[`${doc.unversionedId}.title`]?.message ?? doc.title,
60
- sidebar_label:
61
- docsTranslations[`${doc.unversionedId}.sidebar_label`]?.message ??
62
- doc.sidebar_label,
63
- };
64
- }
65
-
66
- function getDocsTranslations(version: LoadedVersion): TranslationFileContent {
67
- return mergeTranslations(version.docs.map(getDocTranslations));
68
- }
69
- function translateDocs(
70
- docs: DocMetadata[],
71
- docsTranslations: TranslationFileContent,
72
- ): DocMetadata[] {
73
- return docs.map((doc) => translateDoc(doc, docsTranslations));
74
- }
75
- */
76
33
  function getSidebarTranslationFileContent(sidebar, sidebarName) {
77
34
  const categories = (0, utils_1.collectSidebarCategories)(sidebar);
78
35
  const categoryContent = Object.fromEntries(categories.flatMap((category) => {
@@ -179,16 +136,10 @@ function getVersionTranslationFiles(version) {
179
136
  },
180
137
  };
181
138
  const sidebarsTranslations = getSidebarsTranslations(version);
182
- // const docsTranslations: TranslationFileContent =
183
- // getDocsTranslations(version);
184
139
  return [
185
140
  {
186
141
  path: getVersionFileName(version.versionName),
187
- content: (0, utils_2.mergeTranslations)([
188
- versionTranslations,
189
- sidebarsTranslations,
190
- // docsTranslations,
191
- ]),
142
+ content: (0, utils_2.mergeTranslations)([versionTranslations, sidebarsTranslations]),
192
143
  },
193
144
  ];
194
145
  }
@@ -198,7 +149,6 @@ function translateVersion(version, translationFiles) {
198
149
  ...version,
199
150
  label: versionTranslations['version.label']?.message ?? version.label,
200
151
  sidebars: translateSidebars(version, versionTranslations),
201
- // docs: translateDocs(version.docs, versionTranslations),
202
152
  };
203
153
  }
204
154
  function getVersionsTranslationFiles(versions) {
package/lib/types.d.ts CHANGED
@@ -19,7 +19,7 @@ export declare type SourceToPermalink = {
19
19
  [source: string]: string;
20
20
  };
21
21
  export declare type VersionTag = Tag & {
22
- /** all doc ids having this tag. */
22
+ /** All doc ids having this tag. */
23
23
  docIds: string[];
24
24
  };
25
25
  export declare type VersionTags = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-docs",
3
- "version": "0.0.0-4875",
3
+ "version": "0.0.0-4876",
4
4
  "description": "Docs plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "sideEffects": false,
@@ -24,11 +24,11 @@
24
24
  },
25
25
  "license": "MIT",
26
26
  "dependencies": {
27
- "@docusaurus/core": "0.0.0-4875",
28
- "@docusaurus/logger": "0.0.0-4875",
29
- "@docusaurus/mdx-loader": "0.0.0-4875",
30
- "@docusaurus/utils": "0.0.0-4875",
31
- "@docusaurus/utils-validation": "0.0.0-4875",
27
+ "@docusaurus/core": "0.0.0-4876",
28
+ "@docusaurus/logger": "0.0.0-4876",
29
+ "@docusaurus/mdx-loader": "0.0.0-4876",
30
+ "@docusaurus/utils": "0.0.0-4876",
31
+ "@docusaurus/utils-validation": "0.0.0-4876",
32
32
  "combine-promises": "^1.1.0",
33
33
  "fs-extra": "^10.0.1",
34
34
  "import-fresh": "^3.3.0",
@@ -40,8 +40,8 @@
40
40
  "webpack": "^5.72.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@docusaurus/module-type-aliases": "0.0.0-4875",
44
- "@docusaurus/types": "0.0.0-4875",
43
+ "@docusaurus/module-type-aliases": "0.0.0-4876",
44
+ "@docusaurus/types": "0.0.0-4876",
45
45
  "@types/js-yaml": "^4.0.5",
46
46
  "@types/picomatch": "^2.3.0",
47
47
  "commander": "^5.1.0",
@@ -57,5 +57,5 @@
57
57
  "engines": {
58
58
  "node": ">=14"
59
59
  },
60
- "gitHead": "ee48d072632c7eb6d03da4acf5800f8d42eee680"
60
+ "gitHead": "ed43a09bc7cd70a5035d8ec19eb53393fd83dc4f"
61
61
  }
package/src/docs.ts CHANGED
@@ -156,15 +156,13 @@ function doProcessDocMetadata({
156
156
  parse_number_prefixes: parseNumberPrefixes = true,
157
157
  } = frontMatter;
158
158
 
159
- // ex: api/plugins/myDoc -> myDoc
160
- // ex: myDoc -> myDoc
159
+ // E.g. api/plugins/myDoc -> myDoc; myDoc -> myDoc
161
160
  const sourceFileNameWithoutExtension = path.basename(
162
161
  source,
163
162
  path.extname(source),
164
163
  );
165
164
 
166
- // ex: api/plugins/myDoc -> api/plugins
167
- // ex: myDoc -> .
165
+ // E.g. api/plugins/myDoc -> api/plugins; myDoc -> .
168
166
  const sourceDirName = path.dirname(source);
169
167
 
170
168
  const {filename: unprefixedFileName, numberPrefix} = parseNumberPrefixes
@@ -347,7 +345,7 @@ export function addDocNavigation(
347
345
  }
348
346
 
349
347
  const docsWithNavigation = docsBase.map(addNavData);
350
- // sort to ensure consistent output for tests
348
+ // Sort to ensure consistent output for tests
351
349
  docsWithNavigation.sort((a, b) => a.id.localeCompare(b.id));
352
350
  return docsWithNavigation;
353
351
  }
@@ -434,7 +432,7 @@ export function getDocIds(doc: DocMetadataBase): [string, string] {
434
432
  return [doc.unversionedId, doc.id];
435
433
  }
436
434
 
437
- // docs are indexed by both versioned and unversioned ids at the same time
435
+ // Docs are indexed by both versioned and unversioned ids at the same time
438
436
  // TODO legacy retro-compatibility due to old versioned sidebars using
439
437
  // versioned doc ids ("id" should be removed & "versionedId" should be renamed
440
438
  // to "id")
@@ -20,12 +20,14 @@ import type {DocFrontMatter} from '@docusaurus/plugin-content-docs';
20
20
  // We use default values in code instead
21
21
  const DocFrontMatterSchema = Joi.object<DocFrontMatter>({
22
22
  id: Joi.string(),
23
- title: Joi.string().allow(''), // see https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
23
+ // See https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
24
+ title: Joi.string().allow(''),
24
25
  hide_title: Joi.boolean(),
25
26
  hide_table_of_contents: Joi.boolean(),
26
27
  keywords: Joi.array().items(Joi.string().required()),
27
28
  image: URISchema,
28
- description: Joi.string().allow(''), // see https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
29
+ // See https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
30
+ description: Joi.string().allow(''),
29
31
  slug: Joi.string(),
30
32
  sidebar_label: Joi.string(),
31
33
  sidebar_position: Joi.number(),
@@ -19,7 +19,7 @@ declare module '@docusaurus/plugin-content-docs' {
19
19
  * Custom callback for parsing number prefixes from file/folder names.
20
20
  */
21
21
  export type NumberPrefixParser = (filename: string) => {
22
- /** file name without number prefix, without any other modification. */
22
+ /** File name without number prefix, without any other modification. */
23
23
  filename: string;
24
24
  /** The number prefix. Can be float, integer, negative, or anything. */
25
25
  numberPrefix?: number;
@@ -621,9 +621,9 @@ declare module '@docusaurus/plugin-content-docs/client' {
621
621
  breadcrumbs: boolean;
622
622
  };
623
623
  export type DocVersionSuggestions = {
624
- /** suggest the latest version */
624
+ /** Suggest the latest version */
625
625
  latestVersionSuggestion: GlobalVersion;
626
- /** suggest the same doc, in latest version (if exist) */
626
+ /** Suggest the same doc, in latest version (if one exists) */
627
627
  latestDocSuggestion?: GlobalDoc;
628
628
  };
629
629
 
package/src/routes.ts CHANGED
@@ -139,11 +139,9 @@ export async function createVersionRoutes({
139
139
 
140
140
  actions.addRoute({
141
141
  path: version.path,
142
- // allow matching /docs/* as well
142
+ // Allow matching /docs/* since this is the wrapping route
143
143
  exact: false,
144
- // main docs component (DocPage)
145
144
  component: docLayoutComponent,
146
- // sub-routes for each doc
147
145
  routes: await createVersionSubRoutes(),
148
146
  modules: {
149
147
  versionMetadata: aliasedSource(versionMetadataPropPath),
@@ -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
  );
@@ -22,7 +22,7 @@ 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();
@@ -180,7 +180,6 @@ export type PropSidebarItemCategory = Expand<
180
180
  }
181
181
  >;
182
182
 
183
- // we may want to use a union type in props instead of this generic link?
184
183
  export type PropSidebarItemLink = SidebarItemLink & {
185
184
  docId?: string;
186
185
  };
@@ -245,7 +244,7 @@ export type SidebarItemsGeneratorArgs = {
245
244
  /** The default category index matcher which you can override. */
246
245
  isCategoryIndex: CategoryIndexMatcher;
247
246
  /**
248
- * key is the path relative to the doc content directory, value is the
247
+ * Key is the path relative to the doc content directory, value is the
249
248
  * category metadata file's content.
250
249
  */
251
250
  categoriesMetadata: {[filePath: string]: CategoryMetadataFile};
@@ -53,50 +53,6 @@ function getNormalizedSidebarName({
53
53
  return rest.join('/');
54
54
  }
55
55
 
56
- /*
57
- // Do we need to translate doc metadata?
58
- // It seems translating front matter labels is good enough
59
- function getDocTranslations(doc: DocMetadata): TranslationFileContent {
60
- return {
61
- [`${doc.unversionedId}.title`]: {
62
- message: doc.title,
63
- description: `The title for doc with id=${doc.unversionedId}`,
64
- },
65
- ...(doc.sidebar_label
66
- ? {
67
- [`${doc.unversionedId}.sidebar_label`]: {
68
- message: doc.sidebar_label,
69
- description:
70
- `The sidebar label for doc with id=${doc.unversionedId}`,
71
- },
72
- }
73
- : undefined),
74
- };
75
- }
76
- function translateDoc(
77
- doc: DocMetadata,
78
- docsTranslations: TranslationFileContent,
79
- ): DocMetadata {
80
- return {
81
- ...doc,
82
- title: docsTranslations[`${doc.unversionedId}.title`]?.message ?? doc.title,
83
- sidebar_label:
84
- docsTranslations[`${doc.unversionedId}.sidebar_label`]?.message ??
85
- doc.sidebar_label,
86
- };
87
- }
88
-
89
- function getDocsTranslations(version: LoadedVersion): TranslationFileContent {
90
- return mergeTranslations(version.docs.map(getDocTranslations));
91
- }
92
- function translateDocs(
93
- docs: DocMetadata[],
94
- docsTranslations: TranslationFileContent,
95
- ): DocMetadata[] {
96
- return docs.map((doc) => translateDoc(doc, docsTranslations));
97
- }
98
- */
99
-
100
56
  function getSidebarTranslationFileContent(
101
57
  sidebar: Sidebar,
102
58
  sidebarName: string,
@@ -252,17 +208,10 @@ function getVersionTranslationFiles(version: LoadedVersion): TranslationFile[] {
252
208
  const sidebarsTranslations: TranslationFileContent =
253
209
  getSidebarsTranslations(version);
254
210
 
255
- // const docsTranslations: TranslationFileContent =
256
- // getDocsTranslations(version);
257
-
258
211
  return [
259
212
  {
260
213
  path: getVersionFileName(version.versionName),
261
- content: mergeTranslations([
262
- versionTranslations,
263
- sidebarsTranslations,
264
- // docsTranslations,
265
- ]),
214
+ content: mergeTranslations([versionTranslations, sidebarsTranslations]),
266
215
  },
267
216
  ];
268
217
  }
@@ -276,7 +225,6 @@ function translateVersion(
276
225
  ...version,
277
226
  label: versionTranslations['version.label']?.message ?? version.label,
278
227
  sidebars: translateSidebars(version, versionTranslations),
279
- // docs: translateDocs(version.docs, versionTranslations),
280
228
  };
281
229
  }
282
230
 
package/src/types.ts CHANGED
@@ -30,7 +30,7 @@ export type SourceToPermalink = {
30
30
  };
31
31
 
32
32
  export type VersionTag = Tag & {
33
- /** all doc ids having this tag. */
33
+ /** All doc ids having this tag. */
34
34
  docIds: string[];
35
35
  };
36
36
  export type VersionTags = {