@docusaurus/plugin-content-docs 2.0.0-beta.16 → 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 (93) hide show
  1. package/lib/categoryGeneratedIndex.d.ts +1 -1
  2. package/lib/categoryGeneratedIndex.js +5 -7
  3. package/lib/cli.d.ts +3 -2
  4. package/lib/cli.js +49 -41
  5. package/lib/client/docsClientUtils.d.ts +8 -5
  6. package/lib/client/docsClientUtils.js +13 -15
  7. package/lib/client/index.d.ts +12 -9
  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 +8 -15
  12. package/lib/docs.js +34 -39
  13. package/lib/{docFrontMatter.d.ts → frontMatter.d.ts} +4 -2
  14. package/lib/{docFrontMatter.js → frontMatter.js} +3 -0
  15. package/lib/globalData.d.ts +3 -7
  16. package/lib/globalData.js +9 -13
  17. package/lib/index.d.ts +1 -2
  18. package/lib/index.js +33 -26
  19. package/lib/lastUpdate.d.ts +4 -6
  20. package/lib/lastUpdate.js +14 -5
  21. package/lib/markdown/index.js +1 -1
  22. package/lib/markdown/linkify.js +5 -2
  23. package/lib/numberPrefix.js +16 -22
  24. package/lib/options.d.ts +3 -5
  25. package/lib/options.js +6 -5
  26. package/lib/props.d.ts +3 -3
  27. package/lib/props.js +10 -10
  28. package/lib/routes.d.ts +5 -4
  29. package/lib/routes.js +10 -24
  30. package/lib/server-export.d.ts +2 -1
  31. package/lib/server-export.js +3 -4
  32. package/lib/sidebars/generator.js +63 -44
  33. package/lib/sidebars/index.js +20 -16
  34. package/lib/sidebars/normalization.js +3 -3
  35. package/lib/sidebars/postProcessor.js +18 -25
  36. package/lib/sidebars/processor.d.ts +3 -1
  37. package/lib/sidebars/processor.js +17 -6
  38. package/lib/sidebars/types.d.ts +31 -19
  39. package/lib/sidebars/utils.d.ts +17 -6
  40. package/lib/sidebars/utils.js +27 -37
  41. package/lib/sidebars/validation.d.ts +3 -1
  42. package/lib/sidebars/validation.js +1 -0
  43. package/lib/slug.d.ts +1 -2
  44. package/lib/slug.js +4 -5
  45. package/lib/tags.d.ts +2 -1
  46. package/lib/tags.js +2 -2
  47. package/lib/translations.d.ts +3 -3
  48. package/lib/translations.js +28 -81
  49. package/lib/types.d.ts +10 -95
  50. package/lib/versions/files.d.ts +44 -0
  51. package/lib/versions/files.js +142 -0
  52. package/lib/versions/index.d.ts +36 -0
  53. package/lib/versions/index.js +155 -0
  54. package/lib/versions/validation.d.ts +17 -0
  55. package/lib/versions/validation.js +71 -0
  56. package/package.json +14 -12
  57. package/src/categoryGeneratedIndex.ts +10 -9
  58. package/src/cli.ts +64 -69
  59. package/src/client/docsClientUtils.ts +14 -16
  60. package/src/client/index.ts +42 -43
  61. package/src/constants.ts +4 -2
  62. package/src/deps.d.ts +1 -1
  63. package/src/docs.ts +48 -51
  64. package/src/{docFrontMatter.ts → frontMatter.ts} +9 -6
  65. package/src/globalData.ts +15 -16
  66. package/src/index.ts +45 -40
  67. package/src/lastUpdate.ts +20 -8
  68. package/src/markdown/index.ts +1 -3
  69. package/src/markdown/linkify.ts +6 -3
  70. package/src/numberPrefix.ts +18 -28
  71. package/src/options.ts +6 -8
  72. package/src/plugin-content-docs.d.ts +457 -116
  73. package/src/props.ts +12 -9
  74. package/src/routes.ts +13 -39
  75. package/src/server-export.ts +1 -3
  76. package/src/sidebars/generator.ts +88 -59
  77. package/src/sidebars/index.ts +20 -15
  78. package/src/sidebars/normalization.ts +1 -1
  79. package/src/sidebars/postProcessor.ts +6 -11
  80. package/src/sidebars/processor.ts +27 -14
  81. package/src/sidebars/types.ts +25 -23
  82. package/src/sidebars/utils.ts +45 -46
  83. package/src/sidebars/validation.ts +4 -3
  84. package/src/slug.ts +7 -6
  85. package/src/tags.ts +3 -2
  86. package/src/translations.ts +32 -84
  87. package/src/types.ts +15 -107
  88. package/src/versions/files.ts +220 -0
  89. package/src/versions/index.ts +247 -0
  90. package/src/versions/validation.ts +113 -0
  91. package/lib/versions.d.ts +0 -41
  92. package/lib/versions.js +0 -329
  93. package/src/versions.ts +0 -606
@@ -8,43 +8,33 @@
8
8
  import type {NumberPrefixParser} from '@docusaurus/plugin-content-docs';
9
9
 
10
10
  // Best-effort to avoid parsing some patterns as number prefix
11
- const IgnoredPrefixPatterns = (() => {
12
- // ignore common date-like patterns: https://github.com/facebook/docusaurus/issues/4640
13
- const DateLikePrefixRegex =
14
- /^(?:\d{2}|\d{4})[-_.]\d{2}(?:[-_.](?:\d{2}|\d{4}))?.*$/;
15
-
16
- // ignore common versioning patterns: https://github.com/facebook/docusaurus/issues/4653
17
- // note: we could try to parse float numbers in filenames but that is
18
- // probably not worth it as a version such as "8.0" can be interpreted as both
19
- // a version and a float. User can configure her own NumberPrefixParser if
20
- // she wants 8.0 to be interpreted as a float
21
- const VersionLikePrefixRegex = /^\d+[-_.]\d+.*$/;
22
-
23
- return new RegExp(
24
- `${DateLikePrefixRegex.source}|${VersionLikePrefixRegex.source}`,
25
- );
26
- })();
27
-
28
- const NumberPrefixRegex =
29
- /^(?<numberPrefix>\d+)(?<separator>\s*[-_.]+\s*)(?<suffix>.*)$/;
11
+ // ignore common date-like patterns: https://github.com/facebook/docusaurus/issues/4640
12
+ // ignore common versioning patterns: https://github.com/facebook/docusaurus/issues/4653
13
+ // Both of them would look like 7.0-foo or 2021-11-foo
14
+ // note: we could try to parse float numbers in filenames, but that is probably
15
+ // not worth it, as a version such as "8.0" can be interpreted as either a
16
+ // version or a float. User can configure her own NumberPrefixParser if she
17
+ // wants 8.0 to be interpreted as a float
18
+ const ignoredPrefixPattern = /^\d+[-_.]\d+/;
19
+
20
+ const numberPrefixPattern =
21
+ /^(?<numberPrefix>\d+)\s*[-_.]+\s*(?<suffix>[^-_.\s].*)$/;
30
22
 
31
23
  // 0-myDoc => {filename: myDoc, numberPrefix: 0}
32
24
  // 003 - myDoc => {filename: myDoc, numberPrefix: 3}
33
25
  export const DefaultNumberPrefixParser: NumberPrefixParser = (
34
26
  filename: string,
35
27
  ) => {
36
- if (IgnoredPrefixPatterns.exec(filename)) {
28
+ if (ignoredPrefixPattern.test(filename)) {
29
+ return {filename, numberPrefix: undefined};
30
+ }
31
+ const match = numberPrefixPattern.exec(filename);
32
+ if (!match) {
37
33
  return {filename, numberPrefix: undefined};
38
34
  }
39
- const match = NumberPrefixRegex.exec(filename);
40
- const cleanFileName = match?.groups?.suffix ?? filename;
41
- const numberPrefixString = match?.groups?.numberPrefix;
42
- const numberPrefix = numberPrefixString
43
- ? parseInt(numberPrefixString, 10)
44
- : undefined;
45
35
  return {
46
- filename: cleanFileName,
47
- numberPrefix,
36
+ filename: match.groups!.suffix!,
37
+ numberPrefix: parseInt(match.groups!.numberPrefix!, 10),
48
38
  };
49
39
  };
50
40
 
package/src/options.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import type {PluginOptions} from '@docusaurus/plugin-content-docs';
8
+ import type {PluginOptions, Options} from '@docusaurus/plugin-content-docs';
9
9
  import {
10
10
  Joi,
11
11
  RemarkPluginsSchema,
@@ -15,10 +15,7 @@ import {
15
15
  } from '@docusaurus/utils-validation';
16
16
  import {GlobExcludeDefault} from '@docusaurus/utils';
17
17
 
18
- import type {
19
- OptionValidationContext,
20
- ValidationResult,
21
- } from '@docusaurus/types';
18
+ import type {OptionValidationContext} from '@docusaurus/types';
22
19
  import logger from '@docusaurus/logger';
23
20
  import admonitions from 'remark-admonitions';
24
21
  import {DefaultSidebarItemsGenerator} from './sidebars/generator';
@@ -70,7 +67,7 @@ const VersionsOptionsSchema = Joi.object()
70
67
  .pattern(Joi.string().required(), VersionOptionsSchema)
71
68
  .default(DEFAULT_OPTIONS.versions);
72
69
 
73
- export const OptionsSchema = Joi.object({
70
+ const OptionsSchema = Joi.object<PluginOptions>({
74
71
  path: Joi.string().default(DEFAULT_OPTIONS.path),
75
72
  editUrl: Joi.alternatives().try(URISchema, Joi.function()),
76
73
  editCurrentVersion: Joi.boolean().default(DEFAULT_OPTIONS.editCurrentVersion),
@@ -80,6 +77,7 @@ export const OptionsSchema = Joi.object({
80
77
  // .allow('') ""
81
78
  .default(DEFAULT_OPTIONS.routeBasePath),
82
79
  tagsBasePath: Joi.string().default(DEFAULT_OPTIONS.tagsBasePath),
80
+ // @ts-expect-error: deprecated
83
81
  homePageId: Joi.any().forbidden().messages({
84
82
  'any.unknown':
85
83
  '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',
@@ -146,7 +144,7 @@ export const OptionsSchema = Joi.object({
146
144
  export function validateOptions({
147
145
  validate,
148
146
  options: userOptions,
149
- }: OptionValidationContext<PluginOptions>): ValidationResult<PluginOptions> {
147
+ }: OptionValidationContext<Options, PluginOptions>): PluginOptions {
150
148
  let options = userOptions;
151
149
 
152
150
  if (options.sidebarCollapsible === false) {
@@ -168,7 +166,7 @@ export function validateOptions({
168
166
  }
169
167
  }
170
168
 
171
- const normalizedOptions = validate(OptionsSchema, options);
169
+ const normalizedOptions = validate(OptionsSchema, options) as PluginOptions;
172
170
 
173
171
  if (normalizedOptions.admonitions) {
174
172
  normalizedOptions.remarkPlugins = normalizedOptions.remarkPlugins.concat([