@docusaurus/plugin-content-docs 2.0.0-beta.14 → 2.0.0-beta.15

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 (66) hide show
  1. package/lib/categoryGeneratedIndex.d.ts +2 -2
  2. package/lib/categoryGeneratedIndex.js +2 -0
  3. package/lib/cli.d.ts +1 -1
  4. package/lib/client/docsClientUtils.d.ts +3 -22
  5. package/lib/client/docsClientUtils.js +5 -1
  6. package/lib/{theme/hooks/useDocs.d.ts → client/globalDataHooks.d.ts} +1 -2
  7. package/lib/{theme/hooks/useDocs.js → client/globalDataHooks.js} +2 -1
  8. package/lib/client/index.d.ts +7 -0
  9. package/lib/client/index.js +10 -0
  10. package/lib/docFrontMatter.js +1 -0
  11. package/lib/docs.d.ts +19 -6
  12. package/lib/docs.js +37 -17
  13. package/lib/globalData.d.ts +5 -1
  14. package/lib/globalData.js +34 -2
  15. package/lib/index.d.ts +3 -2
  16. package/lib/index.js +2 -8
  17. package/lib/lastUpdate.js +2 -2
  18. package/lib/markdown/index.d.ts +1 -1
  19. package/lib/markdown/linkify.d.ts +1 -1
  20. package/lib/numberPrefix.d.ts +1 -1
  21. package/lib/options.d.ts +1 -1
  22. package/lib/routes.d.ts +4 -3
  23. package/lib/routes.js +6 -3
  24. package/lib/sidebars/generator.js +12 -14
  25. package/lib/sidebars/index.d.ts +3 -2
  26. package/lib/sidebars/processor.d.ts +3 -2
  27. package/lib/sidebars/processor.js +2 -0
  28. package/lib/sidebars/types.d.ts +8 -3
  29. package/lib/sidebars/utils.d.ts +12 -4
  30. package/lib/sidebars/utils.js +48 -3
  31. package/lib/sidebars/validation.d.ts +1 -1
  32. package/lib/sidebars/validation.js +4 -0
  33. package/lib/slug.d.ts +5 -4
  34. package/lib/slug.js +8 -7
  35. package/lib/translations.js +1 -1
  36. package/lib/types.d.ts +7 -78
  37. package/lib/versions.d.ts +3 -2
  38. package/lib/versions.js +27 -32
  39. package/package.json +14 -12
  40. package/src/categoryGeneratedIndex.ts +5 -3
  41. package/src/cli.ts +4 -1
  42. package/src/client/docsClientUtils.ts +22 -35
  43. package/src/{theme/hooks/useDocs.ts → client/globalDataHooks.ts} +6 -2
  44. package/src/client/index.ts +8 -0
  45. package/src/docFrontMatter.ts +2 -1
  46. package/src/docs.ts +62 -29
  47. package/src/globalData.ts +49 -3
  48. package/src/index.ts +9 -15
  49. package/src/lastUpdate.ts +2 -2
  50. package/src/markdown/index.ts +1 -1
  51. package/src/markdown/linkify.ts +1 -1
  52. package/src/numberPrefix.ts +1 -1
  53. package/src/options.ts +1 -1
  54. package/src/plugin-content-docs.d.ts +128 -18
  55. package/src/routes.ts +19 -5
  56. package/src/sidebars/generator.ts +25 -20
  57. package/src/sidebars/index.ts +3 -2
  58. package/src/sidebars/normalization.ts +2 -1
  59. package/src/sidebars/processor.ts +8 -7
  60. package/src/sidebars/types.ts +9 -5
  61. package/src/sidebars/utils.ts +76 -8
  62. package/src/sidebars/validation.ts +6 -1
  63. package/src/slug.ts +15 -11
  64. package/src/translations.ts +2 -2
  65. package/src/types.ts +12 -98
  66. package/src/versions.ts +51 -47
@@ -4,9 +4,9 @@
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 type { Optional } from 'utility-types';
8
- import type { DocMetadataBase, VersionMetadata, NumberPrefixParser, SidebarOptions } from '../types';
9
- import { Required } from 'utility-types';
7
+ import type { Optional, Required } from 'utility-types';
8
+ import type { DocMetadataBase, VersionMetadata } from '../types';
9
+ import type { NumberPrefixParser, SidebarOptions, CategoryIndexMatcher } from '@docusaurus/plugin-content-docs';
10
10
  declare type Expand<T extends Record<string, unknown>> = {
11
11
  [P in keyof T]: T[P];
12
12
  };
@@ -43,6 +43,8 @@ export declare type SidebarItemCategoryLinkGeneratedIndexConfig = {
43
43
  slug?: string;
44
44
  title?: string;
45
45
  description?: string;
46
+ image?: string;
47
+ keywords?: string | readonly string[];
46
48
  };
47
49
  export declare type SidebarItemCategoryLinkGeneratedIndex = {
48
50
  type: 'generated-index';
@@ -50,6 +52,8 @@ export declare type SidebarItemCategoryLinkGeneratedIndex = {
50
52
  permalink: string;
51
53
  title?: string;
52
54
  description?: string;
55
+ image?: string;
56
+ keywords?: string | readonly string[];
53
57
  };
54
58
  export declare type SidebarItemCategoryLinkConfig = SidebarItemCategoryLinkDoc | SidebarItemCategoryLinkGeneratedIndexConfig;
55
59
  export declare type SidebarItemCategoryLink = SidebarItemCategoryLinkDoc | SidebarItemCategoryLinkGeneratedIndex;
@@ -117,6 +121,7 @@ export declare type SidebarItemsGeneratorArgs = {
117
121
  version: SidebarItemsGeneratorVersion;
118
122
  docs: SidebarItemsGeneratorDoc[];
119
123
  numberPrefixParser: NumberPrefixParser;
124
+ isCategoryIndex: CategoryIndexMatcher;
120
125
  options: SidebarOptions;
121
126
  };
122
127
  export declare type SidebarItemsGenerator = (generatorArgs: SidebarItemsGeneratorArgs) => Promise<SidebarItem[]>;
@@ -4,9 +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 type { Sidebars, Sidebar, SidebarItem, SidebarItemCategory, SidebarItemLink, SidebarItemDoc, SidebarCategoriesShorthand, SidebarItemConfig } from './types';
8
- import { DocMetadataBase, DocNavLink } from '../types';
9
- import { SidebarItemCategoryWithGeneratedIndex, SidebarNavigationItem } from './types';
7
+ import type { Sidebars, Sidebar, SidebarItem, SidebarItemCategory, SidebarItemLink, SidebarItemDoc, SidebarCategoriesShorthand, SidebarItemConfig, SidebarItemCategoryWithGeneratedIndex, SidebarNavigationItem } from './types';
8
+ import type { DocMetadataBase, DocNavLink } from '../types';
10
9
  export declare function isCategoriesShorthand(item: SidebarItemConfig): item is SidebarCategoriesShorthand;
11
10
  export declare function transformSidebarItems(sidebar: Sidebar, updateFn: (item: SidebarItem) => SidebarItem): Sidebar;
12
11
  export declare function collectSidebarDocItems(sidebar: Sidebar): SidebarItemDoc[];
@@ -25,9 +24,18 @@ export declare type SidebarsUtils = {
25
24
  sidebars: Sidebars;
26
25
  getFirstDocIdOfFirstSidebar: () => string | undefined;
27
26
  getSidebarNameByDocId: (docId: string) => string | undefined;
28
- getDocNavigation: (unversionedId: string, versionedId: string) => SidebarNavigation;
27
+ getDocNavigation: (unversionedId: string, versionedId: string, displayedSidebar: string | null | undefined) => SidebarNavigation;
29
28
  getCategoryGeneratedIndexList: () => SidebarItemCategoryWithGeneratedIndex[];
30
29
  getCategoryGeneratedIndexNavigation: (categoryGeneratedIndexPermalink: string) => SidebarNavigation;
30
+ getFirstLink: (sidebarId: string) => {
31
+ type: 'doc';
32
+ id: string;
33
+ label: string;
34
+ } | {
35
+ type: 'generated-index';
36
+ slug: string;
37
+ label: string;
38
+ } | undefined;
31
39
  checkSidebarsDocIds: (validDocIds: string[], sidebarFilePath: string) => void;
32
40
  };
33
41
  export declare function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils;
@@ -104,15 +104,20 @@ function createSidebarsUtils(sidebars) {
104
104
  next: undefined,
105
105
  };
106
106
  }
107
- function getDocNavigation(unversionedId, versionedId) {
107
+ function getDocNavigation(unversionedId, versionedId, displayedSidebar) {
108
108
  // TODO legacy id retro-compatibility!
109
109
  let docId = unversionedId;
110
- let sidebarName = getSidebarNameByDocId(docId);
111
- if (!sidebarName) {
110
+ let sidebarName = displayedSidebar === undefined
111
+ ? getSidebarNameByDocId(docId)
112
+ : displayedSidebar;
113
+ if (sidebarName === undefined) {
112
114
  docId = versionedId;
113
115
  sidebarName = getSidebarNameByDocId(docId);
114
116
  }
115
117
  if (sidebarName) {
118
+ if (!sidebarNameToNavigationItems[sidebarName]) {
119
+ throw new Error(`Doc with ID ${docId} wants to display sidebar ${sidebarName} but a sidebar with this name doesn't exist`);
120
+ }
116
121
  const navigationItems = sidebarNameToNavigationItems[sidebarName];
117
122
  const currentItemIndex = navigationItems.findIndex((item) => {
118
123
  if (item.type === 'doc') {
@@ -123,6 +128,9 @@ function createSidebarsUtils(sidebars) {
123
128
  }
124
129
  return false;
125
130
  });
131
+ if (currentItemIndex === -1) {
132
+ return { sidebarName, next: undefined, previous: undefined };
133
+ }
126
134
  const { previous, next } = (0, utils_1.getElementsAround)(navigationItems, currentItemIndex);
127
135
  return { sidebarName, previous, next };
128
136
  }
@@ -173,6 +181,42 @@ Available document ids are:
173
181
  - ${(0, lodash_1.uniq)(validDocIds).sort().join('\n- ')}`);
174
182
  }
175
183
  }
184
+ function getFirstLink(sidebar) {
185
+ var _a, _b, _c;
186
+ // eslint-disable-next-line no-restricted-syntax
187
+ for (const item of sidebar) {
188
+ if (item.type === 'doc') {
189
+ return {
190
+ type: 'doc',
191
+ id: item.id,
192
+ label: (_a = item.label) !== null && _a !== void 0 ? _a : item.id,
193
+ };
194
+ }
195
+ else if (item.type === 'category') {
196
+ if (((_b = item.link) === null || _b === void 0 ? void 0 : _b.type) === 'doc') {
197
+ return {
198
+ type: 'doc',
199
+ id: item.link.id,
200
+ label: item.label,
201
+ };
202
+ }
203
+ else if (((_c = item.link) === null || _c === void 0 ? void 0 : _c.type) === 'generated-index') {
204
+ return {
205
+ type: 'generated-index',
206
+ slug: item.link.slug,
207
+ label: item.label,
208
+ };
209
+ }
210
+ else {
211
+ const firstSubItem = getFirstLink(item.items);
212
+ if (firstSubItem) {
213
+ return firstSubItem;
214
+ }
215
+ }
216
+ }
217
+ }
218
+ return undefined;
219
+ }
176
220
  return {
177
221
  sidebars,
178
222
  getFirstDocIdOfFirstSidebar,
@@ -181,6 +225,7 @@ Available document ids are:
181
225
  getCategoryGeneratedIndexList,
182
226
  getCategoryGeneratedIndexNavigation,
183
227
  checkSidebarsDocIds,
228
+ getFirstLink: (id) => getFirstLink(sidebars[id]),
184
229
  };
185
230
  }
186
231
  exports.createSidebarsUtils = createSidebarsUtils;
@@ -5,6 +5,6 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { SidebarsConfig } from './types';
8
- import { CategoryMetadataFile } from './generator';
8
+ import type { CategoryMetadataFile } from './generator';
9
9
  export declare function validateSidebars(sidebars: unknown): asserts sidebars is SidebarsConfig;
10
10
  export declare function validateCategoryMetadataFile(unsafeContent: unknown): CategoryMetadataFile;
@@ -9,6 +9,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.validateCategoryMetadataFile = exports.validateSidebars = void 0;
10
10
  const utils_validation_1 = require("@docusaurus/utils-validation");
11
11
  const utils_1 = require("./utils");
12
+ // NOTE: we don't add any default values during validation on purpose!
13
+ // Config types are exposed to users for typechecking and we use the same type in normalization
12
14
  const sidebarItemBaseSchema = utils_validation_1.Joi.object({
13
15
  className: utils_validation_1.Joi.string(),
14
16
  customProps: utils_validation_1.Joi.object().unknown(),
@@ -50,6 +52,8 @@ const sidebarItemCategoryLinkSchema = utils_validation_1.Joi.object()
50
52
  // permalink: Joi.string().optional(), // No, this one is not in the user config, only in the normalized version
51
53
  title: utils_validation_1.Joi.string().optional(),
52
54
  description: utils_validation_1.Joi.string().optional(),
55
+ image: utils_validation_1.Joi.string().optional(),
56
+ keywords: [utils_validation_1.Joi.string(), utils_validation_1.Joi.array().items(utils_validation_1.Joi.string())],
53
57
  }),
54
58
  },
55
59
  {
package/lib/slug.d.ts CHANGED
@@ -4,11 +4,12 @@
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 type { DocMetadataBase, NumberPrefixParser } from './types';
8
- export default function getSlug({ baseID, frontmatterSlug, source, sourceDirName, stripDirNumberPrefixes, numberPrefixParser, }: {
7
+ import type { DocMetadataBase } from './types';
8
+ import type { NumberPrefixParser } from '@docusaurus/plugin-content-docs';
9
+ export default function getSlug({ baseID, frontMatterSlug, source, sourceDirName, stripDirNumberPrefixes, numberPrefixParser, }: {
9
10
  baseID: string;
10
- frontmatterSlug?: string;
11
- source: DocMetadataBase['slug'];
11
+ frontMatterSlug?: string;
12
+ source: DocMetadataBase['source'];
12
13
  sourceDirName: DocMetadataBase['sourceDirName'];
13
14
  stripDirNumberPrefixes?: boolean;
14
15
  numberPrefixParser?: NumberPrefixParser;
package/lib/slug.js CHANGED
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const utils_1 = require("@docusaurus/utils");
10
10
  const numberPrefix_1 = require("./numberPrefix");
11
11
  const docs_1 = require("./docs");
12
- function getSlug({ baseID, frontmatterSlug, source, sourceDirName, stripDirNumberPrefixes = true, numberPrefixParser = numberPrefix_1.DefaultNumberPrefixParser, }) {
12
+ function getSlug({ baseID, frontMatterSlug, source, sourceDirName, stripDirNumberPrefixes = true, numberPrefixParser = numberPrefix_1.DefaultNumberPrefixParser, }) {
13
13
  function getDirNameSlug() {
14
14
  const dirNameStripped = stripDirNumberPrefixes
15
15
  ? (0, numberPrefix_1.stripPathNumberPrefixes)(sourceDirName, numberPrefixParser)
@@ -20,15 +20,16 @@ function getSlug({ baseID, frontmatterSlug, source, sourceDirName, stripDirNumbe
20
20
  return resolveDirname;
21
21
  }
22
22
  function computeSlug() {
23
- if (frontmatterSlug === null || frontmatterSlug === void 0 ? void 0 : frontmatterSlug.startsWith('/')) {
24
- return frontmatterSlug;
23
+ if (frontMatterSlug === null || frontMatterSlug === void 0 ? void 0 : frontMatterSlug.startsWith('/')) {
24
+ return frontMatterSlug;
25
25
  }
26
26
  else {
27
27
  const dirNameSlug = getDirNameSlug();
28
- if (!frontmatterSlug && (0, docs_1.isConventionalDocIndex)({ source, sourceDirName })) {
28
+ if (!frontMatterSlug &&
29
+ (0, docs_1.isCategoryIndex)((0, docs_1.toCategoryIndexMatcherParam)({ source, sourceDirName }))) {
29
30
  return dirNameSlug;
30
31
  }
31
- const baseSlug = frontmatterSlug || baseID;
32
+ const baseSlug = frontMatterSlug || baseID;
32
33
  return (0, utils_1.resolvePathname)(baseSlug, getDirNameSlug());
33
34
  }
34
35
  }
@@ -36,8 +37,8 @@ function getSlug({ baseID, frontmatterSlug, source, sourceDirName, stripDirNumbe
36
37
  if (!(0, utils_1.isValidPathname)(slug)) {
37
38
  throw new Error(`We couldn't compute a valid slug for document with id "${baseID}" in "${sourceDirName}" directory.
38
39
  The slug we computed looks invalid: ${slug}.
39
- Maybe your slug frontmatter is incorrect or you use weird chars in the file path?
40
- By using the slug frontmatter, you should be able to fix this error, by using the slug of your choice:
40
+ Maybe your slug front matter is incorrect or you use weird chars in the file path?
41
+ By using the slug front matter, you should be able to fix this error, by using the slug of your choice:
41
42
 
42
43
  Example =>
43
44
  ---
@@ -33,7 +33,7 @@ function getNormalizedSidebarName({ versionName, sidebarName, }) {
33
33
  }
34
34
  /*
35
35
  // Do we need to translate doc metadata?
36
- // It seems translating frontmatter labels is good enough
36
+ // It seems translating front matter labels is good enough
37
37
  function getDocTranslations(doc: DocMetadata): TranslationFileContent {
38
38
  return {
39
39
  [`${doc.unversionedId}.title`]: {
package/lib/types.d.ts CHANGED
@@ -4,10 +4,10 @@
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 type { RemarkAndRehypePluginOptions } from '@docusaurus/mdx-loader';
7
+ import type { Sidebars } from './sidebars/types';
8
8
  import type { Tag, FrontMatterTag, Slugger } from '@docusaurus/utils';
9
9
  import type { BrokenMarkdownLink as IBrokenMarkdownLink, ContentPaths } from '@docusaurus/utils/lib/markdownLinks';
10
- import type { SidebarItemsGeneratorOption, Sidebars } from './sidebars/types';
10
+ import type { VersionBanner, SidebarOptions } from '@docusaurus/plugin-content-docs';
11
11
  export declare type DocFile = {
12
12
  contentPath: string;
13
13
  filePath: string;
@@ -15,9 +15,8 @@ export declare type DocFile = {
15
15
  content: string;
16
16
  lastUpdate: LastUpdateData;
17
17
  };
18
- export declare type VersionName = string;
19
18
  export declare type VersionMetadata = ContentPaths & {
20
- versionName: VersionName;
19
+ versionName: string;
21
20
  versionLabel: string;
22
21
  versionPath: string;
23
22
  tagsPath: string;
@@ -30,62 +29,10 @@ export declare type VersionMetadata = ContentPaths & {
30
29
  sidebarFilePath: string | false | undefined;
31
30
  routePriority: number | undefined;
32
31
  };
33
- export declare type EditUrlFunction = (editUrlParams: {
34
- version: string;
35
- versionDocsDirPath: string;
36
- docPath: string;
37
- permalink: string;
38
- locale: string;
39
- }) => string | undefined;
40
- export declare type MetadataOptions = {
41
- routeBasePath: string;
42
- editUrl?: string | EditUrlFunction;
43
- editCurrentVersion: boolean;
44
- editLocalizedFiles: boolean;
45
- showLastUpdateTime?: boolean;
46
- showLastUpdateAuthor?: boolean;
47
- numberPrefixParser: NumberPrefixParser;
48
- };
49
- export declare type PathOptions = {
50
- path: string;
51
- sidebarPath?: string | false | undefined;
52
- };
53
- export declare type VersionBanner = 'unreleased' | 'unmaintained';
54
- export declare type VersionOptions = {
55
- path?: string;
56
- label?: string;
57
- banner?: 'none' | VersionBanner;
58
- badge?: boolean;
59
- className?: string;
60
- };
61
- export declare type VersionsOptions = {
62
- lastVersion?: string;
63
- versions: Record<string, VersionOptions>;
64
- onlyIncludeVersions?: string[];
65
- };
66
- export declare type SidebarOptions = {
67
- sidebarCollapsible: boolean;
68
- sidebarCollapsed: boolean;
69
- };
70
32
  export declare type NormalizeSidebarsParams = SidebarOptions & {
71
33
  version: VersionMetadata;
72
34
  categoryLabelSlugger: Slugger;
73
35
  };
74
- export declare type PluginOptions = MetadataOptions & PathOptions & VersionsOptions & RemarkAndRehypePluginOptions & SidebarOptions & {
75
- id: string;
76
- include: string[];
77
- exclude: string[];
78
- docLayoutComponent: string;
79
- docItemComponent: string;
80
- docTagDocListComponent: string;
81
- docTagsListComponent: string;
82
- docCategoryGeneratedIndexComponent: string;
83
- admonitions: Record<string, unknown>;
84
- disableVersioning: boolean;
85
- includeCurrentVersion: boolean;
86
- sidebarItemsGenerator: SidebarItemsGeneratorOption;
87
- tagsBasePath: string;
88
- };
89
36
  export declare type LastUpdateData = {
90
37
  lastUpdatedAt?: number;
91
38
  formattedLastUpdatedAt?: string;
@@ -104,6 +51,7 @@ export declare type DocFrontMatter = {
104
51
  sidebar_label?: string;
105
52
  sidebar_position?: number;
106
53
  sidebar_class_name?: string;
54
+ displayed_sidebar?: string | null;
107
55
  pagination_label?: string;
108
56
  custom_edit_url?: string | null;
109
57
  parse_number_prefixes?: boolean;
@@ -115,7 +63,7 @@ export declare type DocFrontMatter = {
115
63
  export declare type DocMetadataBase = LastUpdateData & {
116
64
  id: string;
117
65
  unversionedId: string;
118
- version: VersionName;
66
+ version: string;
119
67
  title: string;
120
68
  description: string;
121
69
  source: string;
@@ -144,6 +92,8 @@ export declare type CategoryGeneratedIndexMetadata = {
144
92
  sidebar: string;
145
93
  previous?: DocNavLink;
146
94
  next?: DocNavLink;
95
+ image?: string;
96
+ keywords?: string | readonly string[];
147
97
  };
148
98
  export declare type SourceToPermalink = {
149
99
  [source: string]: string;
@@ -166,23 +116,6 @@ export declare type LoadedVersion = VersionMetadata & {
166
116
  export declare type LoadedContent = {
167
117
  loadedVersions: LoadedVersion[];
168
118
  };
169
- export declare type GlobalDoc = {
170
- id: string;
171
- path: string;
172
- sidebar: string | undefined;
173
- };
174
- export declare type GlobalVersion = {
175
- name: VersionName;
176
- label: string;
177
- isLast: boolean;
178
- path: string;
179
- mainDocId: string;
180
- docs: GlobalDoc[];
181
- };
182
- export declare type GlobalPluginData = {
183
- path: string;
184
- versions: GlobalVersion[];
185
- };
186
119
  export declare type BrokenMarkdownLink = IBrokenMarkdownLink<VersionMetadata>;
187
120
  export declare type DocsMarkdownOption = {
188
121
  versionsMetadata: VersionMetadata[];
@@ -190,7 +123,3 @@ export declare type DocsMarkdownOption = {
190
123
  sourceToPermalink: SourceToPermalink;
191
124
  onBrokenMarkdownLink: (brokenMarkdownLink: BrokenMarkdownLink) => void;
192
125
  };
193
- export declare type NumberPrefixParser = (filename: string) => {
194
- filename: string;
195
- numberPrefix?: number;
196
- };
package/lib/versions.d.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 type { PluginOptions, VersionMetadata } from './types';
7
+ import type { VersionMetadata } from './types';
8
+ import type { PluginOptions } from '@docusaurus/plugin-content-docs';
8
9
  import type { LoadContext } from '@docusaurus/types';
9
10
  export declare function getVersionedDocsDirPath(siteDir: string, pluginId: string): string;
10
11
  export declare function getVersionedSidebarsDirPath(siteDir: string, pluginId: string): string;
@@ -12,5 +13,5 @@ export declare function getVersionsFilePath(siteDir: string, pluginId: string):
12
13
  export declare function readVersionsMetadata({ context, options, }: {
13
14
  context: Pick<LoadContext, 'siteDir' | 'baseUrl' | 'i18n'>;
14
15
  options: Pick<PluginOptions, 'id' | 'path' | 'sidebarPath' | 'routeBasePath' | 'tagsBasePath' | 'includeCurrentVersion' | 'disableVersioning' | 'lastVersion' | 'versions' | 'onlyIncludeVersions' | 'editUrl' | 'editCurrentVersion'>;
15
- }): VersionMetadata[];
16
+ }): Promise<VersionMetadata[]>;
16
17
  export declare function getDocsDirPaths(versionMetadata: Pick<VersionMetadata, 'contentPath' | 'contentPathLocalized'>): [string, string];
package/lib/versions.js CHANGED
@@ -50,11 +50,10 @@ function ensureValidVersionArray(versionArray) {
50
50
  }
51
51
  versionArray.forEach(ensureValidVersionString);
52
52
  }
53
- // TODO not easy to make async due to many deps
54
- function readVersionsFile(siteDir, pluginId) {
53
+ async function readVersionsFile(siteDir, pluginId) {
55
54
  const versionsFilePath = getVersionsFilePath(siteDir, pluginId);
56
- if (fs_extra_1.default.existsSync(versionsFilePath)) {
57
- const content = JSON.parse(fs_extra_1.default.readFileSync(versionsFilePath, 'utf8'));
55
+ if (await fs_extra_1.default.pathExists(versionsFilePath)) {
56
+ const content = JSON.parse(await fs_extra_1.default.readFile(versionsFilePath, 'utf8'));
58
57
  ensureValidVersionArray(content);
59
58
  return content;
60
59
  }
@@ -62,22 +61,21 @@ function readVersionsFile(siteDir, pluginId) {
62
61
  return null;
63
62
  }
64
63
  }
65
- // TODO not easy to make async due to many deps
66
- function readVersionNames(siteDir, options) {
67
- const versionFileContent = readVersionsFile(siteDir, options.id);
64
+ async function readVersionNames(siteDir, options) {
65
+ const versionFileContent = await readVersionsFile(siteDir, options.id);
68
66
  if (!versionFileContent && options.disableVersioning) {
69
- throw new Error(`Docs: using "disableVersioning=${options.disableVersioning}" option on a non-versioned site does not make sense.`);
67
+ throw new Error(`Docs: using "disableVersioning: ${options.disableVersioning}" option on a non-versioned site does not make sense.`);
70
68
  }
71
69
  const versions = options.disableVersioning ? [] : versionFileContent !== null && versionFileContent !== void 0 ? versionFileContent : [];
72
- // We add the current version at the beginning, unless
73
- // - user don't want to
74
- // - it's been explicitly added to versions.json
70
+ // We add the current version at the beginning, unless:
71
+ // - user don't want to; or
72
+ // - it's already been explicitly added to versions.json
75
73
  if (options.includeCurrentVersion &&
76
74
  !versions.includes(constants_1.CURRENT_VERSION_NAME)) {
77
75
  versions.unshift(constants_1.CURRENT_VERSION_NAME);
78
76
  }
79
77
  if (versions.length === 0) {
80
- throw new Error(`It is not possible to use docs without any version. Please check the configuration of these options: "includeCurrentVersion=${options.includeCurrentVersion}", "disableVersioning=${options.disableVersioning}".`);
78
+ throw new Error(`It is not possible to use docs without any version. Please check the configuration of these options: "includeCurrentVersion: ${options.includeCurrentVersion}", "disableVersioning: ${options.disableVersioning}".`);
81
79
  }
82
80
  return versions;
83
81
  }
@@ -96,27 +94,23 @@ function getDocsDirPathLocalized({ siteDir, locale, pluginId, versionName, }) {
96
94
  }
97
95
  function getVersionMetadataPaths({ versionName, context, options, }) {
98
96
  const isCurrentVersion = versionName === constants_1.CURRENT_VERSION_NAME;
99
- const contentPath = isCurrentVersion
100
- ? path_1.default.resolve(context.siteDir, options.path)
101
- : path_1.default.join(getVersionedDocsDirPath(context.siteDir, options.id), `version-${versionName}`);
102
97
  const contentPathLocalized = getDocsDirPathLocalized({
103
98
  siteDir: context.siteDir,
104
99
  locale: context.i18n.currentLocale,
105
100
  pluginId: options.id,
106
101
  versionName,
107
102
  });
108
- function getSidebarFilePath() {
109
- if (isCurrentVersion) {
110
- return (0, sidebars_1.resolveSidebarPathOption)(context.siteDir, options.sidebarPath);
111
- }
112
- else {
113
- return path_1.default.join(getVersionedSidebarsDirPath(context.siteDir, options.id), `version-${versionName}-sidebars.json`);
114
- }
103
+ if (isCurrentVersion) {
104
+ return {
105
+ contentPath: path_1.default.resolve(context.siteDir, options.path),
106
+ contentPathLocalized,
107
+ sidebarFilePath: (0, sidebars_1.resolveSidebarPathOption)(context.siteDir, options.sidebarPath),
108
+ };
115
109
  }
116
110
  return {
117
- contentPath,
111
+ contentPath: path_1.default.join(getVersionedDocsDirPath(context.siteDir, options.id), `version-${versionName}`),
118
112
  contentPathLocalized,
119
- sidebarFilePath: getSidebarFilePath(),
113
+ sidebarFilePath: path_1.default.join(getVersionedSidebarsDirPath(context.siteDir, options.id), `version-${versionName}-sidebars.json`),
120
114
  };
121
115
  }
122
116
  function getVersionEditUrls({ contentPath, contentPathLocalized, context: { siteDir, i18n }, options: { id, path: currentVersionPath, editUrl, editCurrentVersion }, }) {
@@ -262,7 +256,7 @@ function checkVersionMetadataPaths({ versionMetadata, context, }) {
262
256
  Please set the docs "sidebarPath" field in your config file to:
263
257
  - a sidebars path that exists
264
258
  - false: to disable the sidebar
265
- - undefined: for Docusaurus generates it automatically`);
259
+ - undefined: for Docusaurus to generate it automatically`);
266
260
  }
267
261
  }
268
262
  // TODO for retrocompatibility with existing behavior
@@ -280,7 +274,7 @@ function checkVersionsOptions(availableVersionNames, options) {
280
274
  const availableVersionNamesMsg = `Available version names are: ${availableVersionNames.join(', ')}`;
281
275
  if (options.lastVersion &&
282
276
  !availableVersionNames.includes(options.lastVersion)) {
283
- throw new Error(`Docs option lastVersion=${options.lastVersion} is invalid. ${availableVersionNamesMsg}`);
277
+ throw new Error(`Docs option lastVersion: ${options.lastVersion} is invalid. ${availableVersionNamesMsg}`);
284
278
  }
285
279
  const unknownVersionConfigNames = (0, lodash_1.difference)(Object.keys(options.versions), availableVersionNames);
286
280
  if (unknownVersionConfigNames.length > 0) {
@@ -300,9 +294,11 @@ function checkVersionsOptions(availableVersionNames, options) {
300
294
  }
301
295
  }
302
296
  }
303
- // Filter versions according to provided options
304
- // Note: we preserve the order in which versions are provided
305
- // the order of the onlyIncludeVersions array does not matter
297
+ /**
298
+ * Filter versions according to provided options.
299
+ * Note: we preserve the order in which versions are provided;
300
+ * the order of the onlyIncludeVersions array does not matter
301
+ */
306
302
  function filterVersions(versionNamesUnfiltered, options) {
307
303
  if (options.onlyIncludeVersions) {
308
304
  return versionNamesUnfiltered.filter((name) => (options.onlyIncludeVersions || []).includes(name));
@@ -311,10 +307,9 @@ function filterVersions(versionNamesUnfiltered, options) {
311
307
  return versionNamesUnfiltered;
312
308
  }
313
309
  }
314
- // TODO make this async (requires plugin init to be async)
315
- function readVersionsMetadata({ context, options, }) {
310
+ async function readVersionsMetadata({ context, options, }) {
316
311
  var _a;
317
- const versionNamesUnfiltered = readVersionNames(context.siteDir, options);
312
+ const versionNamesUnfiltered = await readVersionNames(context.siteDir, options);
318
313
  checkVersionsOptions(versionNamesUnfiltered, options);
319
314
  const versionNames = filterVersions(versionNamesUnfiltered, options);
320
315
  const lastVersionName = (_a = options.lastVersion) !== null && _a !== void 0 ? _a : getDefaultLastVersionName(versionNames);
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-docs",
3
- "version": "2.0.0-beta.14",
3
+ "version": "2.0.0-beta.15",
4
4
  "description": "Docs plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
+ "exports": {
7
+ "./client": "./lib/client/index.js",
8
+ ".": "./lib/index.js"
9
+ },
6
10
  "types": "src/plugin-content-docs.d.ts",
7
11
  "scripts": {
8
12
  "build": "tsc",
@@ -18,18 +22,15 @@
18
22
  },
19
23
  "license": "MIT",
20
24
  "dependencies": {
21
- "@docusaurus/core": "2.0.0-beta.14",
22
- "@docusaurus/logger": "2.0.0-beta.14",
23
- "@docusaurus/mdx-loader": "2.0.0-beta.14",
24
- "@docusaurus/utils": "2.0.0-beta.14",
25
- "@docusaurus/utils-validation": "2.0.0-beta.14",
25
+ "@docusaurus/core": "2.0.0-beta.15",
26
+ "@docusaurus/logger": "2.0.0-beta.15",
27
+ "@docusaurus/mdx-loader": "2.0.0-beta.15",
28
+ "@docusaurus/utils": "2.0.0-beta.15",
29
+ "@docusaurus/utils-validation": "2.0.0-beta.15",
26
30
  "combine-promises": "^1.1.0",
27
- "escape-string-regexp": "^4.0.0",
28
31
  "fs-extra": "^10.0.0",
29
- "globby": "^11.0.2",
30
32
  "import-fresh": "^3.2.2",
31
33
  "js-yaml": "^4.0.0",
32
- "loader-utils": "^2.0.0",
33
34
  "lodash": "^4.17.20",
34
35
  "remark-admonitions": "^1.2.1",
35
36
  "shelljs": "^0.8.4",
@@ -38,11 +39,12 @@
38
39
  "webpack": "^5.61.0"
39
40
  },
40
41
  "devDependencies": {
41
- "@docusaurus/module-type-aliases": "2.0.0-beta.14",
42
- "@docusaurus/types": "2.0.0-beta.14",
42
+ "@docusaurus/module-type-aliases": "2.0.0-beta.15",
43
+ "@docusaurus/types": "2.0.0-beta.15",
43
44
  "@types/js-yaml": "^4.0.0",
44
45
  "@types/picomatch": "^2.2.1",
45
46
  "commander": "^5.1.0",
47
+ "escape-string-regexp": "^4.0.0",
46
48
  "picomatch": "^2.1.1",
47
49
  "utility-types": "^3.10.0"
48
50
  },
@@ -53,5 +55,5 @@
53
55
  "engines": {
54
56
  "node": ">=14"
55
57
  },
56
- "gitHead": "c4824a8937d8f1aa0806667749cbc74058e2b294"
58
+ "gitHead": "6cfad16436c07d8d11e5c2e1486dc59afd483e33"
57
59
  }
@@ -5,9 +5,9 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import {CategoryGeneratedIndexMetadata, DocMetadataBase} from './types';
9
- import {SidebarItemCategoryWithGeneratedIndex} from './sidebars/types';
10
- import {SidebarsUtils, toNavigationLink} from './sidebars/utils';
8
+ import type {CategoryGeneratedIndexMetadata, DocMetadataBase} from './types';
9
+ import type {SidebarItemCategoryWithGeneratedIndex} from './sidebars/types';
10
+ import {type SidebarsUtils, toNavigationLink} from './sidebars/utils';
11
11
  import {createDocsByIdIndex} from './docs';
12
12
 
13
13
  function getCategoryGeneratedIndexMetadata({
@@ -28,6 +28,8 @@ function getCategoryGeneratedIndexMetadata({
28
28
  return {
29
29
  title: category.link.title ?? category.label,
30
30
  description: category.link.description,
31
+ image: category.link.image,
32
+ keywords: category.link.keywords,
31
33
  slug: category.link.slug,
32
34
  permalink: category.link.permalink,
33
35
  sidebar: sidebarName,
package/src/cli.ts CHANGED
@@ -12,7 +12,10 @@ import {
12
12
  } from './versions';
13
13
  import fs from 'fs-extra';
14
14
  import path from 'path';
15
- import type {PathOptions, SidebarOptions} from './types';
15
+ import type {
16
+ PathOptions,
17
+ SidebarOptions,
18
+ } from '@docusaurus/plugin-content-docs';
16
19
  import {loadSidebarsFile, resolveSidebarPathOption} from './sidebars';
17
20
  import {DEFAULT_PLUGIN_ID} from '@docusaurus/utils';
18
21
  import logger from '@docusaurus/logger';