@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/lib/index.js CHANGED
@@ -18,16 +18,19 @@ const cli_1 = require("./cli");
18
18
  const constants_1 = require("./constants");
19
19
  const globalData_1 = require("./globalData");
20
20
  const props_1 = require("./props");
21
+ const categoryGeneratedIndex_1 = require("./categoryGeneratedIndex");
21
22
  const translations_1 = require("./translations");
22
23
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
23
24
  const tags_1 = require("./tags");
24
25
  const routes_1 = require("./routes");
25
26
  const utils_2 = require("./sidebars/utils");
26
- const categoryGeneratedIndex_1 = require("./categoryGeneratedIndex");
27
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
27
28
  async function pluginContentDocs(context, options) {
28
29
  const { siteDir, generatedFilesDir, baseUrl, siteConfig } = context;
30
+ // Mutate options to resolve sidebar path according to siteDir
31
+ options.sidebarPath = (0, sidebars_1.resolveSidebarPathOption)(siteDir, options.sidebarPath);
29
32
  const versionsMetadata = await (0, versions_1.readVersionsMetadata)({ context, options });
30
- const pluginId = options.id ?? utils_1.DEFAULT_PLUGIN_ID;
33
+ const pluginId = options.id;
31
34
  const pluginDataDirRoot = path_1.default.join(generatedFilesDir, 'docusaurus-plugin-content-docs');
32
35
  const dataDir = path_1.default.join(pluginDataDirRoot, pluginId);
33
36
  const aliasedSource = (source) => `~docs/${(0, utils_1.posixPath)(path_1.default.relative(pluginDataDirRoot, source))}`;
@@ -48,21 +51,16 @@ async function pluginContentDocs(context, options) {
48
51
  .arguments('<version>')
49
52
  .description(commandDescription)
50
53
  .action((version) => {
51
- (0, cli_1.cliDocsVersionCommand)(version, siteDir, pluginId, {
52
- path: options.path,
53
- sidebarPath: options.sidebarPath,
54
- sidebarCollapsed: options.sidebarCollapsed,
55
- sidebarCollapsible: options.sidebarCollapsible,
56
- });
54
+ (0, cli_1.cliDocsVersionCommand)(version, options, context);
57
55
  });
58
56
  },
59
- async getTranslationFiles({ content }) {
57
+ getTranslationFiles({ content }) {
60
58
  return (0, translations_1.getLoadedContentTranslationFiles)(content);
61
59
  },
62
60
  getPathsToWatch() {
63
61
  function getVersionPathsToWatch(version) {
64
62
  const result = [
65
- ...options.include.flatMap((pattern) => (0, versions_1.getDocsDirPaths)(version).map((docsDirPath) => `${docsDirPath}/${pattern}`)),
63
+ ...options.include.flatMap((pattern) => (0, utils_1.getContentPathList)(version).map((docsDirPath) => `${docsDirPath}/${pattern}`)),
66
64
  `${version.contentPath}/**/${generator_1.CategoryMetadataFilenamePattern}`,
67
65
  ];
68
66
  if (typeof version.sidebarFilePath === 'string') {
@@ -84,16 +82,19 @@ async function pluginContentDocs(context, options) {
84
82
  versionMetadata,
85
83
  context,
86
84
  options,
85
+ env: process.env.NODE_ENV,
87
86
  });
88
87
  }
89
88
  return Promise.all(docFiles.map(processVersionDoc));
90
89
  }
91
90
  async function doLoadVersion(versionMetadata) {
92
- const docs = await loadVersionDocsBase(versionMetadata);
91
+ const docsBase = await loadVersionDocsBase(versionMetadata);
92
+ const [drafts, docs] = lodash_1.default.partition(docsBase, (doc) => doc.draft);
93
93
  const sidebars = await (0, sidebars_1.loadSidebars)(versionMetadata.sidebarFilePath, {
94
94
  sidebarItemsGenerator: options.sidebarItemsGenerator,
95
95
  numberPrefixParser: options.numberPrefixParser,
96
96
  docs,
97
+ drafts,
97
98
  version: versionMetadata,
98
99
  sidebarOptions: {
99
100
  sidebarCollapsed: options.sidebarCollapsed,
@@ -105,12 +106,8 @@ async function pluginContentDocs(context, options) {
105
106
  return {
106
107
  ...versionMetadata,
107
108
  docs: (0, docs_1.addDocNavigation)(docs, sidebarsUtils, versionMetadata.sidebarFilePath),
109
+ drafts,
108
110
  sidebars,
109
- mainDocId: (0, docs_1.getMainDocId)({ docs, sidebarsUtils }),
110
- categoryGeneratedIndices: (0, categoryGeneratedIndex_1.getCategoryGeneratedIndexMetadataList)({
111
- docs,
112
- sidebarsUtils,
113
- }),
114
111
  };
115
112
  }
116
113
  async function loadVersion(versionMetadata) {
@@ -133,17 +130,28 @@ async function pluginContentDocs(context, options) {
133
130
  const { loadedVersions } = content;
134
131
  const { docLayoutComponent, docItemComponent, docCategoryGeneratedIndexComponent, breadcrumbs, } = options;
135
132
  const { addRoute, createData, setGlobalData } = actions;
133
+ const versions = loadedVersions.map((version) => {
134
+ const sidebarsUtils = (0, utils_2.createSidebarsUtils)(version.sidebars);
135
+ return {
136
+ ...version,
137
+ sidebarsUtils,
138
+ categoryGeneratedIndices: (0, categoryGeneratedIndex_1.getCategoryGeneratedIndexMetadataList)({
139
+ docs: version.docs,
140
+ sidebarsUtils,
141
+ }),
142
+ };
143
+ });
136
144
  async function createVersionTagsRoutes(version) {
137
145
  const versionTags = (0, tags_1.getVersionTags)(version.docs);
138
146
  // TODO tags should be a sub route of the version route
139
147
  async function createTagsListPage() {
140
148
  const tagsProp = Object.values(versionTags).map((tagValue) => ({
141
- name: tagValue.name,
149
+ label: tagValue.label,
142
150
  permalink: tagValue.permalink,
143
151
  count: tagValue.docIds.length,
144
152
  }));
145
153
  // Only create /tags page if there are tags.
146
- if (Object.keys(tagsProp).length > 0) {
154
+ if (tagsProp.length > 0) {
147
155
  const tagsPropPath = await createData(`${(0, utils_1.docuHash)(`tags-list-${version.versionName}-prop`)}.json`, JSON.stringify(tagsProp, null, 2));
148
156
  addRoute({
149
157
  path: version.tagsPath,
@@ -175,8 +183,8 @@ async function pluginContentDocs(context, options) {
175
183
  await createTagsListPage();
176
184
  await Promise.all(Object.values(versionTags).map(createTagDocListPage));
177
185
  }
178
- await Promise.all(loadedVersions.map((loadedVersion) => (0, routes_1.createVersionRoutes)({
179
- loadedVersion,
186
+ await Promise.all(versions.map((version) => (0, routes_1.createVersionRoutes)({
187
+ version,
180
188
  docItemComponent,
181
189
  docLayoutComponent,
182
190
  docCategoryGeneratedIndexComponent,
@@ -185,10 +193,10 @@ async function pluginContentDocs(context, options) {
185
193
  actions,
186
194
  })));
187
195
  // TODO tags should be a sub route of the version route
188
- await Promise.all(loadedVersions.map(createVersionTagsRoutes));
196
+ await Promise.all(versions.map(createVersionTagsRoutes));
189
197
  setGlobalData({
190
198
  path: (0, utils_1.normalizeUrl)([baseUrl, options.routeBasePath]),
191
- versions: loadedVersions.map(globalData_1.toGlobalDataVersion),
199
+ versions: versions.map(globalData_1.toGlobalDataVersion),
192
200
  breadcrumbs,
193
201
  });
194
202
  },
@@ -211,7 +219,7 @@ async function pluginContentDocs(context, options) {
211
219
  },
212
220
  };
213
221
  function createMDXLoaderRule() {
214
- const contentDirs = versionsMetadata.flatMap(versions_1.getDocsDirPaths);
222
+ const contentDirs = versionsMetadata.flatMap(utils_1.getContentPathList);
215
223
  return {
216
224
  test: /\.mdx?$/i,
217
225
  include: contentDirs
@@ -7,10 +7,9 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.linkify = void 0;
10
- const versions_1 = require("../versions");
11
10
  const utils_1 = require("@docusaurus/utils");
12
11
  function getVersion(filePath, options) {
13
- const versionFound = options.versionsMetadata.find((version) => (0, versions_1.getDocsDirPaths)(version).some((docsDirPath) => filePath.startsWith(docsDirPath)));
12
+ const versionFound = options.versionsMetadata.find((version) => (0, utils_1.getContentPathList)(version).some((docsDirPath) => filePath.startsWith(docsDirPath)));
14
13
  // At this point, this should never happen, because the MDX loaders' paths are
15
14
  // literally using the version content paths; but if we allow sourcing content
16
15
  // from outside the docs directory (through the `include` option, for example;
package/lib/props.d.ts CHANGED
@@ -4,12 +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 { LoadedVersion, VersionTag, DocMetadata } from './types';
8
- import type { PropSidebars, PropVersionMetadata, PropTagDocList } from '@docusaurus/plugin-content-docs';
7
+ import type { VersionTag } from './types';
8
+ import type { PropSidebars, PropVersionMetadata, PropTagDocList, DocMetadata, LoadedVersion } from '@docusaurus/plugin-content-docs';
9
9
  export declare function toSidebarsProp(loadedVersion: LoadedVersion): PropSidebars;
10
10
  export declare function toVersionMetadataProp(pluginId: string, loadedVersion: LoadedVersion): PropVersionMetadata;
11
11
  export declare function toTagDocListProp({ allTagsPath, tag, docs, }: {
12
12
  allTagsPath: string;
13
13
  tag: VersionTag;
14
- docs: Pick<DocMetadata, 'id' | 'title' | 'description' | 'permalink'>[];
14
+ docs: DocMetadata[];
15
15
  }): PropTagDocList;
package/lib/props.js CHANGED
@@ -81,10 +81,10 @@ function toVersionMetadataProp(pluginId, loadedVersion) {
81
81
  return {
82
82
  pluginId,
83
83
  version: loadedVersion.versionName,
84
- label: loadedVersion.versionLabel,
85
- banner: loadedVersion.versionBanner,
86
- badge: loadedVersion.versionBadge,
87
- className: loadedVersion.versionClassName,
84
+ label: loadedVersion.label,
85
+ banner: loadedVersion.banner,
86
+ badge: loadedVersion.badge,
87
+ className: loadedVersion.className,
88
88
  isLast: loadedVersion.isLast,
89
89
  docsSidebars: toSidebarsProp(loadedVersion),
90
90
  docs: toVersionDocsProp(loadedVersion),
@@ -104,10 +104,11 @@ function toTagDocListProp({ allTagsPath, tag, docs, }) {
104
104
  }));
105
105
  }
106
106
  return {
107
- name: tag.name,
107
+ label: tag.label,
108
108
  permalink: tag.permalink,
109
- docs: toDocListProp(),
110
109
  allTagsPath,
110
+ count: tag.docIds.length,
111
+ items: toDocListProp(),
111
112
  };
112
113
  }
113
114
  exports.toTagDocListProp = toTagDocListProp;
package/lib/routes.d.ts CHANGED
@@ -5,9 +5,10 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { PluginContentLoadedActions, RouteConfig } from '@docusaurus/types';
8
- import type { DocMetadata, LoadedVersion } from './types';
8
+ import type { FullVersion } from './types';
9
+ import type { DocMetadata } from '@docusaurus/plugin-content-docs';
9
10
  export declare function createCategoryGeneratedIndexRoutes({ version, actions, docCategoryGeneratedIndexComponent, aliasedSource, }: {
10
- version: LoadedVersion;
11
+ version: FullVersion;
11
12
  actions: PluginContentLoadedActions;
12
13
  docCategoryGeneratedIndexComponent: string;
13
14
  aliasedSource: (str: string) => string;
@@ -17,8 +18,8 @@ export declare function createDocRoutes({ docs, actions, docItemComponent, }: {
17
18
  actions: PluginContentLoadedActions;
18
19
  docItemComponent: string;
19
20
  }): Promise<RouteConfig[]>;
20
- export declare function createVersionRoutes({ loadedVersion, actions, docItemComponent, docLayoutComponent, docCategoryGeneratedIndexComponent, pluginId, aliasedSource, }: {
21
- loadedVersion: LoadedVersion;
21
+ export declare function createVersionRoutes({ version, actions, docItemComponent, docLayoutComponent, docCategoryGeneratedIndexComponent, pluginId, aliasedSource, }: {
22
+ version: FullVersion;
22
23
  actions: PluginContentLoadedActions;
23
24
  docLayoutComponent: string;
24
25
  docItemComponent: string;
package/lib/routes.js CHANGED
@@ -14,23 +14,11 @@ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
14
14
  async function createCategoryGeneratedIndexRoutes({ version, actions, docCategoryGeneratedIndexComponent, aliasedSource, }) {
15
15
  const slugs = (0, utils_1.createSlugger)();
16
16
  async function createCategoryGeneratedIndexRoute(categoryGeneratedIndex) {
17
- const { sidebar, title, description, slug, permalink, previous, next, image, keywords, } = categoryGeneratedIndex;
18
- const propFileName = slugs.slug(`${version.versionPath}-${categoryGeneratedIndex.sidebar}-category-${categoryGeneratedIndex.title}`);
19
- const prop = {
20
- title,
21
- description,
22
- slug,
23
- permalink,
24
- image,
25
- keywords,
26
- navigation: {
27
- previous,
28
- next,
29
- },
30
- };
17
+ const { sidebar, ...prop } = categoryGeneratedIndex;
18
+ const propFileName = slugs.slug(`${version.path}-${categoryGeneratedIndex.sidebar}-category-${categoryGeneratedIndex.title}`);
31
19
  const propData = await actions.createData(`${(0, utils_1.docuHash)(`category/${propFileName}`)}.json`, JSON.stringify(prop, null, 2));
32
20
  return {
33
- path: permalink,
21
+ path: categoryGeneratedIndex.permalink,
34
22
  component: docCategoryGeneratedIndexComponent,
35
23
  exact: true,
36
24
  modules: {
@@ -68,8 +56,8 @@ async function createDocRoutes({ docs, actions, docItemComponent, }) {
68
56
  }));
69
57
  }
70
58
  exports.createDocRoutes = createDocRoutes;
71
- async function createVersionRoutes({ loadedVersion, actions, docItemComponent, docLayoutComponent, docCategoryGeneratedIndexComponent, pluginId, aliasedSource, }) {
72
- async function doCreateVersionRoutes(version) {
59
+ async function createVersionRoutes({ version, actions, docItemComponent, docLayoutComponent, docCategoryGeneratedIndexComponent, pluginId, aliasedSource, }) {
60
+ async function doCreateVersionRoutes() {
73
61
  const versionMetadata = (0, props_1.toVersionMetadataProp)(pluginId, version);
74
62
  const versionMetadataPropPath = await actions.createData(`${(0, utils_1.docuHash)(`version-${version.versionName}-metadata-prop`)}.json`, JSON.stringify(versionMetadata, null, 2));
75
63
  async function createVersionSubRoutes() {
@@ -86,12 +74,10 @@ async function createVersionRoutes({ loadedVersion, actions, docItemComponent, d
86
74
  return routes.sort((a, b) => a.path.localeCompare(b.path));
87
75
  }
88
76
  actions.addRoute({
89
- path: version.versionPath,
90
- // allow matching /docs/* as well
77
+ path: version.path,
78
+ // Allow matching /docs/* since this is the wrapping route
91
79
  exact: false,
92
- // main docs component (DocPage)
93
80
  component: docLayoutComponent,
94
- // sub-routes for each doc
95
81
  routes: await createVersionSubRoutes(),
96
82
  modules: {
97
83
  versionMetadata: aliasedSource(versionMetadataPropPath),
@@ -100,10 +86,10 @@ async function createVersionRoutes({ loadedVersion, actions, docItemComponent, d
100
86
  });
101
87
  }
102
88
  try {
103
- return await doCreateVersionRoutes(loadedVersion);
89
+ return await doCreateVersionRoutes();
104
90
  }
105
91
  catch (err) {
106
- logger_1.default.error `Can't create version routes for version name=${loadedVersion.versionName}`;
92
+ logger_1.default.error `Can't create version routes for version name=${version.versionName}`;
107
93
  throw err;
108
94
  }
109
95
  }
@@ -5,4 +5,5 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  export { CURRENT_VERSION_NAME, VERSIONED_DOCS_DIR, VERSIONED_SIDEBARS_DIR, VERSIONS_JSON_FILE, } from './constants';
8
- export { filterVersions, getDefaultVersionBanner, getVersionBadge, getVersionBanner, getVersionsFilePath, readVersionsFile, readVersionNames, } from './versions';
8
+ export { filterVersions, getDefaultVersionBanner, getVersionBadge, getVersionBanner, } from './versions';
9
+ export { readVersionNames } from './versions/files';
@@ -6,7 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.readVersionNames = exports.readVersionsFile = exports.getVersionsFilePath = exports.getVersionBanner = exports.getVersionBadge = exports.getDefaultVersionBanner = exports.filterVersions = exports.VERSIONS_JSON_FILE = exports.VERSIONED_SIDEBARS_DIR = exports.VERSIONED_DOCS_DIR = exports.CURRENT_VERSION_NAME = void 0;
9
+ exports.readVersionNames = exports.getVersionBanner = exports.getVersionBadge = exports.getDefaultVersionBanner = exports.filterVersions = exports.VERSIONS_JSON_FILE = exports.VERSIONED_SIDEBARS_DIR = exports.VERSIONED_DOCS_DIR = exports.CURRENT_VERSION_NAME = void 0;
10
10
  // APIs available to Node.js
11
11
  var constants_1 = require("./constants");
12
12
  Object.defineProperty(exports, "CURRENT_VERSION_NAME", { enumerable: true, get: function () { return constants_1.CURRENT_VERSION_NAME; } });
@@ -18,6 +18,5 @@ Object.defineProperty(exports, "filterVersions", { enumerable: true, get: functi
18
18
  Object.defineProperty(exports, "getDefaultVersionBanner", { enumerable: true, get: function () { return versions_1.getDefaultVersionBanner; } });
19
19
  Object.defineProperty(exports, "getVersionBadge", { enumerable: true, get: function () { return versions_1.getVersionBadge; } });
20
20
  Object.defineProperty(exports, "getVersionBanner", { enumerable: true, get: function () { return versions_1.getVersionBanner; } });
21
- Object.defineProperty(exports, "getVersionsFilePath", { enumerable: true, get: function () { return versions_1.getVersionsFilePath; } });
22
- Object.defineProperty(exports, "readVersionsFile", { enumerable: true, get: function () { return versions_1.readVersionsFile; } });
23
- Object.defineProperty(exports, "readVersionNames", { enumerable: true, get: function () { return versions_1.readVersionNames; } });
21
+ var files_1 = require("./versions/files");
22
+ Object.defineProperty(exports, "readVersionNames", { enumerable: true, get: function () { return files_1.readVersionNames; } });
@@ -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
  }
@@ -104,7 +104,7 @@ Available doc IDs:
104
104
  };
105
105
  }
106
106
  function createCategoryItem(dir, fullPath, folderName) {
107
- const categoryMetadata = categoriesMetadata[(0, utils_1.posixPath)(path_1.default.join(autogenDir, fullPath))];
107
+ const categoryMetadata = categoriesMetadata[path_1.default.posix.join(autogenDir, fullPath)];
108
108
  const allItems = Object.entries(dir).map(([key, content]) => dirToItem(content, key, `${fullPath}/${key}`));
109
109
  // Try to match a doc inside the category folder,
110
110
  // using the "local id" (myDoc) or "qualified id" (dirName/myDoc)
@@ -30,7 +30,6 @@ exports.DefaultSidebars = {
30
30
  };
31
31
  exports.DisabledSidebars = {};
32
32
  // If a path is provided, make it absolute
33
- // use this before loadSidebars()
34
33
  function resolveSidebarPathOption(siteDir, sidebarPathOption) {
35
34
  return sidebarPathOption
36
35
  ? path_1.default.resolve(siteDir, sidebarPathOption)
@@ -76,7 +75,6 @@ async function loadSidebarsFileUnsafe(sidebarFilePath) {
76
75
  return (0, import_fresh_1.default)(sidebarFilePath);
77
76
  }
78
77
  exports.loadSidebarsFileUnsafe = loadSidebarsFileUnsafe;
79
- // Note: sidebarFilePath must be absolute, use resolveSidebarPathOption
80
78
  async function loadSidebars(sidebarFilePath, options) {
81
79
  try {
82
80
  const sidebarsConfig = await loadSidebarsFileUnsafe(sidebarFilePath);
@@ -42,7 +42,7 @@ function normalizeItem(item) {
42
42
  exports.normalizeItem = normalizeItem;
43
43
  function normalizeSidebar(sidebar, place) {
44
44
  if (!Array.isArray(sidebar) && !(0, utils_1.isCategoriesShorthand)(sidebar)) {
45
- throw new Error(logger_1.default.interpolate `Invalid sidebar items collection code=${JSON.stringify(sidebar)} 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.`);
45
+ throw new Error(logger_1.default.interpolate `Invalid sidebar items collection code=${JSON.stringify(sidebar)} 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.`);
46
46
  }
47
47
  const normalizedSidebar = Array.isArray(sidebar)
48
48
  ? sidebar
@@ -12,10 +12,10 @@ 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
- const permalink = (0, utils_1.normalizeUrl)([params.version.versionPath, slug]);
18
+ const permalink = (0, utils_1.normalizeUrl)([params.version.path, slug]);
19
19
  return {
20
20
  ...category.link,
21
21
  slug,
@@ -30,7 +30,7 @@ function toSidebarItemsGeneratorVersion(version) {
30
30
  // Handle the generation of autogenerated sidebar items and other
31
31
  // post-processing checks
32
32
  async function processSidebar(unprocessedSidebar, categoriesMetadata, params) {
33
- const { sidebarItemsGenerator, numberPrefixParser, docs, version } = params;
33
+ const { sidebarItemsGenerator, numberPrefixParser, docs, drafts, version } = params;
34
34
  // Just a minor lazy transformation optimization
35
35
  const getSidebarItemsGeneratorDocsAndVersion = lodash_1.default.memoize(() => ({
36
36
  docs: docs.map(toSidebarItemsGeneratorDoc),
@@ -51,12 +51,23 @@ async function processSidebar(unprocessedSidebar, categoriesMetadata, params) {
51
51
  // more autogenerated items, or when loop count (e.g. 10) is reached
52
52
  return processItems(generatedItems);
53
53
  }
54
+ const draftIds = new Set(drafts.flatMap(docs_1.getDocIds));
55
+ const isDraftItem = (item) => {
56
+ if (item.type === 'doc' || item.type === 'ref') {
57
+ return draftIds.has(item.id);
58
+ }
59
+ // If a category only contains draft items, it should be filtered entirely.
60
+ if (item.type === 'category') {
61
+ return item.items.every(isDraftItem);
62
+ }
63
+ return false;
64
+ };
54
65
  async function processItem(item) {
55
66
  if (item.type === 'category') {
56
67
  return [
57
68
  {
58
69
  ...item,
59
- items: (await Promise.all(item.items.map(processItem))).flat(),
70
+ items: await processItems(item.items),
60
71
  },
61
72
  ];
62
73
  }
@@ -66,7 +77,7 @@ async function processSidebar(unprocessedSidebar, categoriesMetadata, params) {
66
77
  return [item];
67
78
  }
68
79
  async function processItems(items) {
69
- return (await Promise.all(items.map(processItem))).flat();
80
+ return (await Promise.all(items.filter((i) => !isDraftItem(i)).map(processItem))).flat();
70
81
  }
71
82
  const processedSidebar = await processItems(unprocessedSidebar);
72
83
  return processedSidebar;
@@ -5,8 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
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';
8
+ import type { NumberPrefixParser, SidebarOptions, CategoryIndexMatcher, DocMetadataBase, VersionMetadata } from '@docusaurus/plugin-content-docs';
10
9
  import type { Slugger } from '@docusaurus/utils';
11
10
  declare type Expand<T extends {
12
11
  [x: string]: unknown;
@@ -126,15 +125,6 @@ export declare type PropSidebars = {
126
125
  [sidebarId: string]: PropSidebar;
127
126
  };
128
127
  export declare type PropSidebarBreadcrumbsItem = PropSidebarItemLink | PropSidebarItemCategory;
129
- export declare type PropVersionDoc = {
130
- id: string;
131
- title: string;
132
- description?: string;
133
- sidebar?: string;
134
- };
135
- export declare type PropVersionDocs = {
136
- [docId: string]: PropVersionDoc;
137
- };
138
128
  export declare type CategoryMetadataFile = {
139
129
  label?: string;
140
130
  position?: number;
@@ -149,24 +139,38 @@ export declare type CategoryMetadataFile = {
149
139
  export declare type SidebarItemsGeneratorDoc = Pick<DocMetadataBase, 'id' | 'unversionedId' | 'title' | 'frontMatter' | 'source' | 'sourceDirName' | 'sidebarPosition'>;
150
140
  export declare type SidebarItemsGeneratorVersion = Pick<VersionMetadata, 'versionName' | 'contentPath'>;
151
141
  export declare type SidebarItemsGeneratorArgs = {
142
+ /** The sidebar item with type "autogenerated" to be transformed. */
152
143
  item: SidebarItemAutogenerated;
144
+ /** Useful metadata for the version this sidebar belongs to. */
153
145
  version: SidebarItemsGeneratorVersion;
146
+ /** All the docs of that version (unfiltered). */
154
147
  docs: SidebarItemsGeneratorDoc[];
148
+ /** Number prefix parser configured for this plugin. */
155
149
  numberPrefixParser: NumberPrefixParser;
150
+ /** The default category index matcher which you can override. */
156
151
  isCategoryIndex: CategoryIndexMatcher;
152
+ /**
153
+ * Key is the path relative to the doc content directory, value is the
154
+ * category metadata file's content.
155
+ */
157
156
  categoriesMetadata: {
158
157
  [filePath: string]: CategoryMetadataFile;
159
158
  };
160
159
  };
161
160
  export declare type SidebarItemsGenerator = (generatorArgs: SidebarItemsGeneratorArgs) => Promise<NormalizedSidebar>;
162
- export declare type SidebarItemsGeneratorOptionArgs = {
161
+ export declare type SidebarItemsGeneratorOption = (generatorArgs: {
162
+ /**
163
+ * Useful to re-use/enhance the default sidebar generation logic from
164
+ * Docusaurus.
165
+ * @see https://github.com/facebook/docusaurus/issues/4640#issuecomment-822292320
166
+ */
163
167
  defaultSidebarItemsGenerator: SidebarItemsGenerator;
164
- } & SidebarItemsGeneratorArgs;
165
- export declare type SidebarItemsGeneratorOption = (generatorArgs: SidebarItemsGeneratorOptionArgs) => Promise<NormalizedSidebarItem[]>;
168
+ } & SidebarItemsGeneratorArgs) => Promise<NormalizedSidebarItem[]>;
166
169
  export declare type SidebarProcessorParams = {
167
170
  sidebarItemsGenerator: SidebarItemsGeneratorOption;
168
171
  numberPrefixParser: NumberPrefixParser;
169
172
  docs: DocMetadataBase[];
173
+ drafts: DocMetadataBase[];
170
174
  version: VersionMetadata;
171
175
  categoryLabelSlugger: Slugger;
172
176
  sidebarOptions: SidebarOptions;
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { Sidebars, Sidebar, SidebarItem, SidebarItemCategory, SidebarItemLink, SidebarItemDoc, SidebarCategoriesShorthand, SidebarItemConfig, SidebarItemCategoryWithGeneratedIndex, SidebarNavigationItem } from './types';
8
- import type { DocMetadataBase, DocNavLink } from '../types';
8
+ import type { DocMetadataBase, PropNavigationLink } from '@docusaurus/plugin-content-docs';
9
9
  export declare function isCategoriesShorthand(item: SidebarItemConfig): item is SidebarCategoriesShorthand;
10
10
  export declare function transformSidebarItems(sidebar: Sidebar, updateFn: (item: SidebarItem) => SidebarItem): Sidebar;
11
11
  export declare function collectSidebarDocItems(sidebar: Sidebar): SidebarItemDoc[];
@@ -48,7 +48,7 @@ export declare type SidebarsUtils = {
48
48
  checkSidebarsDocIds: (validDocIds: string[], sidebarFilePath: string) => void;
49
49
  };
50
50
  export declare function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils;
51
- export declare function toDocNavigationLink(doc: DocMetadataBase): DocNavLink;
51
+ export declare function toDocNavigationLink(doc: DocMetadataBase): PropNavigationLink;
52
52
  export declare function toNavigationLink(navigationItem: SidebarNavigationItem | undefined, docsById: {
53
53
  [docId: string]: DocMetadataBase;
54
- }): DocNavLink | undefined;
54
+ }): PropNavigationLink | undefined;
package/lib/slug.d.ts CHANGED
@@ -4,8 +4,7 @@
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 } from './types';
8
- import type { NumberPrefixParser } from '@docusaurus/plugin-content-docs';
7
+ import type { NumberPrefixParser, DocMetadataBase } from '@docusaurus/plugin-content-docs';
9
8
  export default function getSlug({ baseID, frontMatterSlug, source, sourceDirName, stripDirNumberPrefixes, numberPrefixParser, }: {
10
9
  baseID: string;
11
10
  frontMatterSlug?: string;
package/lib/tags.d.ts CHANGED
@@ -4,5 +4,6 @@
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 { VersionTags, DocMetadata } from './types';
7
+ import type { VersionTags } from './types';
8
+ import type { DocMetadata } from '@docusaurus/plugin-content-docs';
8
9
  export declare function getVersionTags(docs: DocMetadata[]): VersionTags;
package/lib/tags.js CHANGED
@@ -13,7 +13,7 @@ const lodash_1 = tslib_1.__importDefault(require("lodash"));
13
13
  function getVersionTags(docs) {
14
14
  const groups = (0, utils_1.groupTaggedItems)(docs, (doc) => doc.tags);
15
15
  return lodash_1.default.mapValues(groups, (group) => ({
16
- name: group.tag.label,
16
+ label: group.tag.label,
17
17
  docIds: group.items.map((item) => item.id),
18
18
  permalink: group.tag.permalink,
19
19
  }));
@@ -4,7 +4,7 @@
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 { LoadedContent } from './types';
8
- import type { TranslationFile, TranslationFiles } from '@docusaurus/types';
9
- export declare function getLoadedContentTranslationFiles(loadedContent: LoadedContent): TranslationFiles;
7
+ import type { LoadedContent } from '@docusaurus/plugin-content-docs';
8
+ import type { TranslationFile } from '@docusaurus/types';
9
+ export declare function getLoadedContentTranslationFiles(loadedContent: LoadedContent): TranslationFile[];
10
10
  export declare function translateLoadedContent(loadedContent: LoadedContent, translationFiles: TranslationFile[]): LoadedContent;
@@ -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) => {
@@ -174,21 +131,15 @@ function translateSidebars(version, sidebarsTranslations) {
174
131
  function getVersionTranslationFiles(version) {
175
132
  const versionTranslations = {
176
133
  'version.label': {
177
- message: version.versionLabel,
134
+ message: version.label,
178
135
  description: `The label for version ${version.versionName}`,
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
  }
@@ -196,9 +147,8 @@ function translateVersion(version, translationFiles) {
196
147
  const versionTranslations = translationFiles[getVersionFileName(version.versionName)].content;
197
148
  return {
198
149
  ...version,
199
- versionLabel: versionTranslations['version.label']?.message ?? version.versionLabel,
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) {