@docusaurus/plugin-content-docs 2.4.1 → 3.0.0-beta.0

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.
@@ -5,18 +5,18 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { UseDataOptions } from '@docusaurus/types';
8
- export declare type ActivePlugin = {
8
+ export type ActivePlugin = {
9
9
  pluginId: string;
10
10
  pluginData: GlobalPluginData;
11
11
  };
12
- export declare type ActiveDocContext = {
12
+ export type ActiveDocContext = {
13
13
  activeVersion?: GlobalVersion;
14
14
  activeDoc?: GlobalDoc;
15
15
  alternateDocVersions: {
16
16
  [versionName: string]: GlobalDoc;
17
17
  };
18
18
  };
19
- export declare type GlobalDoc = {
19
+ export type GlobalDoc = {
20
20
  /**
21
21
  * For generated index pages, this is the `slug`, **not** `permalink`
22
22
  * (without base URL). Because slugs have leading slashes but IDs don't,
@@ -24,9 +24,10 @@ export declare type GlobalDoc = {
24
24
  */
25
25
  id: string;
26
26
  path: string;
27
- sidebar: string | undefined;
27
+ sidebar?: string;
28
+ unlisted?: boolean;
28
29
  };
29
- export declare type GlobalVersion = {
30
+ export type GlobalVersion = {
30
31
  name: string;
31
32
  label: string;
32
33
  isLast: boolean;
@@ -40,18 +41,18 @@ export declare type GlobalVersion = {
40
41
  [sidebarId: string]: GlobalSidebar;
41
42
  };
42
43
  };
43
- export declare type GlobalSidebar = {
44
+ export type GlobalSidebar = {
44
45
  link?: {
45
46
  label: string;
46
47
  path: string;
47
48
  };
48
49
  };
49
- export declare type GlobalPluginData = {
50
+ export type GlobalPluginData = {
50
51
  path: string;
51
52
  versions: GlobalVersion[];
52
53
  breadcrumbs: boolean;
53
54
  };
54
- export declare type DocVersionSuggestions = {
55
+ export type DocVersionSuggestions = {
55
56
  /** Suggest the latest version */
56
57
  latestVersionSuggestion: GlobalVersion;
57
58
  /** Suggest the same doc, in latest version (if one exists) */
package/lib/docs.d.ts CHANGED
@@ -10,7 +10,7 @@ import type { SidebarsUtils } from './sidebars/utils';
10
10
  import type { DocFile } from './types';
11
11
  export declare function readDocFile(versionMetadata: Pick<VersionMetadata, 'contentPath' | 'contentPathLocalized'>, source: string): Promise<DocFile>;
12
12
  export declare function readVersionDocs(versionMetadata: VersionMetadata, options: Pick<PluginOptions, 'include' | 'exclude' | 'showLastUpdateAuthor' | 'showLastUpdateTime'>): Promise<DocFile[]>;
13
- export declare type DocEnv = 'production' | 'development';
13
+ export type DocEnv = 'production' | 'development';
14
14
  export declare function processDocMetadata(args: {
15
15
  docFile: DocFile;
16
16
  versionMetadata: VersionMetadata;
@@ -18,7 +18,10 @@ export declare function processDocMetadata(args: {
18
18
  options: MetadataOptions;
19
19
  env: DocEnv;
20
20
  }): Promise<DocMetadataBase>;
21
- export declare function addDocNavigation(docsBase: DocMetadataBase[], sidebarsUtils: SidebarsUtils, sidebarFilePath: string): LoadedVersion['docs'];
21
+ export declare function addDocNavigation({ docs, sidebarsUtils, }: {
22
+ docs: DocMetadataBase[];
23
+ sidebarsUtils: SidebarsUtils;
24
+ }): LoadedVersion['docs'];
22
25
  /**
23
26
  * The "main doc" is the "version entry point"
24
27
  * We browse this doc by clicking on a version:
@@ -36,10 +39,8 @@ export declare const isCategoryIndex: CategoryIndexMatcher;
36
39
  * `'autogenerated', '.md', ['sidebar', 'guides']`
37
40
  */
38
41
  export declare function toCategoryIndexMatcherParam({ source, sourceDirName, }: Pick<DocMetadataBase, 'source' | 'sourceDirName'>): Parameters<CategoryIndexMatcher>[0];
39
- export declare function getDocIds(doc: DocMetadataBase): [string, string];
40
42
  export declare function createDocsByIdIndex<Doc extends {
41
43
  id: string;
42
- unversionedId: string;
43
44
  }>(docs: Doc[]): {
44
45
  [docId: string]: Doc;
45
46
  };
package/lib/docs.js CHANGED
@@ -6,15 +6,15 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.createDocsByIdIndex = exports.getDocIds = exports.toCategoryIndexMatcherParam = exports.isCategoryIndex = exports.getMainDocId = exports.addDocNavigation = exports.processDocMetadata = exports.readVersionDocs = exports.readDocFile = void 0;
9
+ exports.createDocsByIdIndex = exports.toCategoryIndexMatcherParam = exports.isCategoryIndex = exports.getMainDocId = exports.addDocNavigation = exports.processDocMetadata = exports.readVersionDocs = exports.readDocFile = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const path_1 = tslib_1.__importDefault(require("path"));
12
12
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
13
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
13
14
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
14
15
  const utils_1 = require("@docusaurus/utils");
15
16
  const lastUpdate_1 = require("./lastUpdate");
16
17
  const slug_1 = tslib_1.__importDefault(require("./slug"));
17
- const constants_1 = require("./constants");
18
18
  const numberPrefix_1 = require("./numberPrefix");
19
19
  const frontMatter_1 = require("./frontMatter");
20
20
  const utils_2 = require("./sidebars/utils");
@@ -64,10 +64,6 @@ async function readVersionDocs(versionMetadata, options) {
64
64
  return Promise.all(sources.map((source) => readDocFile(versionMetadata, source)));
65
65
  }
66
66
  exports.readVersionDocs = readVersionDocs;
67
- /** Docs with draft front matter are only considered draft in production. */
68
- function isDraftForEnvironment({ env, frontMatter, }) {
69
- return (env === 'production' && frontMatter.draft) ?? false;
70
- }
71
67
  async function doProcessDocMetadata({ docFile, versionMetadata, context, options, env, }) {
72
68
  const { source, content, contentPath, filePath } = docFile;
73
69
  const { siteDir, i18n } = context;
@@ -94,12 +90,6 @@ async function doProcessDocMetadata({ docFile, versionMetadata, context, options
94
90
  // prefix or front matter
95
91
  const sidebarPosition = frontMatter.sidebar_position ?? numberPrefix;
96
92
  // TODO legacy retrocompatibility
97
- // The same doc in 2 distinct version could keep the same id,
98
- // we just need to namespace the data by version
99
- const versionIdPrefix = versionMetadata.versionName === constants_1.CURRENT_VERSION_NAME
100
- ? undefined
101
- : `version-${versionMetadata.versionName}`;
102
- // TODO legacy retrocompatibility
103
93
  // I think it's bad to affect the front matter id with the dirname?
104
94
  function computeDirNameIdPrefix() {
105
95
  if (sourceDirName === '.') {
@@ -110,12 +100,7 @@ async function doProcessDocMetadata({ docFile, versionMetadata, context, options
110
100
  ? (0, numberPrefix_1.stripPathNumberPrefixes)(sourceDirName, options.numberPrefixParser)
111
101
  : sourceDirName;
112
102
  }
113
- const unversionedId = [computeDirNameIdPrefix(), baseID]
114
- .filter(Boolean)
115
- .join('/');
116
- // TODO is versioning the id very useful in practice?
117
- // legacy versioned id, requires a breaking change to modify this
118
- const id = [versionIdPrefix, unversionedId].filter(Boolean).join('/');
103
+ const id = [computeDirNameIdPrefix(), baseID].filter(Boolean).join('/');
119
104
  const docSlug = (0, slug_1.default)({
120
105
  baseID,
121
106
  source,
@@ -150,7 +135,8 @@ async function doProcessDocMetadata({ docFile, versionMetadata, context, options
150
135
  }
151
136
  return undefined;
152
137
  }
153
- const draft = isDraftForEnvironment({ env, frontMatter });
138
+ const draft = (0, utils_1.isDraft)({ env, frontMatter });
139
+ const unlisted = (0, utils_1.isUnlisted)({ env, frontMatter });
154
140
  const formatDate = (locale, date, calendar) => {
155
141
  try {
156
142
  return new Intl.DateTimeFormat(locale, {
@@ -171,7 +157,6 @@ async function doProcessDocMetadata({ docFile, versionMetadata, context, options
171
157
  // Adding properties to object after instantiation will cause hidden
172
158
  // class transitions.
173
159
  return {
174
- unversionedId,
175
160
  id,
176
161
  title,
177
162
  description,
@@ -180,6 +165,7 @@ async function doProcessDocMetadata({ docFile, versionMetadata, context, options
180
165
  slug: docSlug,
181
166
  permalink,
182
167
  draft,
168
+ unlisted,
183
169
  editUrl: customEditURL !== undefined ? customEditURL : getDocEditUrl(),
184
170
  tags: (0, utils_1.normalizeFrontMatterTags)(versionMetadata.tagsPath, frontMatter.tags),
185
171
  version: versionMetadata.versionName,
@@ -201,12 +187,19 @@ async function processDocMetadata(args) {
201
187
  }
202
188
  }
203
189
  exports.processDocMetadata = processDocMetadata;
204
- function addDocNavigation(docsBase, sidebarsUtils, sidebarFilePath) {
205
- const docsById = createDocsByIdIndex(docsBase);
206
- sidebarsUtils.checkSidebarsDocIds(docsBase.flatMap(getDocIds), sidebarFilePath);
190
+ function getUnlistedIds(docs) {
191
+ return new Set(docs.filter((doc) => doc.unlisted).map((doc) => doc.id));
192
+ }
193
+ function addDocNavigation({ docs, sidebarsUtils, }) {
194
+ const docsById = createDocsByIdIndex(docs);
195
+ const unlistedIds = getUnlistedIds(docs);
207
196
  // Add sidebar/next/previous to the docs
208
197
  function addNavData(doc) {
209
- const navigation = sidebarsUtils.getDocNavigation(doc.unversionedId, doc.id, doc.frontMatter.displayed_sidebar);
198
+ const navigation = sidebarsUtils.getDocNavigation({
199
+ docId: doc.id,
200
+ displayedSidebar: doc.frontMatter.displayed_sidebar,
201
+ unlistedIds,
202
+ });
210
203
  const toNavigationLinkByDocId = (docId, type) => {
211
204
  if (!docId) {
212
205
  return undefined;
@@ -216,6 +209,10 @@ function addDocNavigation(docsBase, sidebarsUtils, sidebarFilePath) {
216
209
  // This could only happen if user provided the ID through front matter
217
210
  throw new Error(`Error when loading ${doc.id} in ${doc.sourceDirName}: the pagination_${type} front matter points to a non-existent ID ${docId}.`);
218
211
  }
212
+ // Gracefully handle explicitly providing an unlisted doc ID in production
213
+ if (navDoc.unlisted) {
214
+ return undefined;
215
+ }
219
216
  return (0, utils_2.toDocNavigationLink)(navDoc);
220
217
  };
221
218
  const previous = doc.frontMatter.pagination_prev !== undefined
@@ -226,7 +223,7 @@ function addDocNavigation(docsBase, sidebarsUtils, sidebarFilePath) {
226
223
  : (0, utils_2.toNavigationLink)(navigation.next, docsById);
227
224
  return { ...doc, sidebar: navigation.sidebarName, previous, next };
228
225
  }
229
- const docsWithNavigation = docsBase.map(addNavData);
226
+ const docsWithNavigation = docs.map(addNavData);
230
227
  // Sort to ensure consistent output for tests
231
228
  docsWithNavigation.sort((a, b) => a.id.localeCompare(b.id));
232
229
  return docsWithNavigation;
@@ -247,12 +244,11 @@ function getMainDocId({ docs, sidebarsUtils, }) {
247
244
  return versionHomeDoc;
248
245
  }
249
246
  else if (firstDocIdOfFirstSidebar) {
250
- return docs.find((doc) => doc.id === firstDocIdOfFirstSidebar ||
251
- doc.unversionedId === firstDocIdOfFirstSidebar);
247
+ return docs.find((doc) => doc.id === firstDocIdOfFirstSidebar);
252
248
  }
253
249
  return docs[0];
254
250
  }
255
- return getMainDoc().unversionedId;
251
+ return getMainDoc().id;
256
252
  }
257
253
  exports.getMainDocId = getMainDocId;
258
254
  // By convention, Docusaurus considers some docs are "indexes":
@@ -287,22 +283,8 @@ function toCategoryIndexMatcherParam({ source, sourceDirName, }) {
287
283
  };
288
284
  }
289
285
  exports.toCategoryIndexMatcherParam = toCategoryIndexMatcherParam;
290
- // Return both doc ids
291
- // TODO legacy retro-compatibility due to old versioned sidebars using
292
- // versioned doc ids ("id" should be removed & "versionedId" should be renamed
293
- // to "id")
294
- function getDocIds(doc) {
295
- return [doc.unversionedId, doc.id];
296
- }
297
- exports.getDocIds = getDocIds;
298
- // Docs are indexed by both versioned and unversioned ids at the same time
299
- // TODO legacy retro-compatibility due to old versioned sidebars using
300
- // versioned doc ids ("id" should be removed & "versionedId" should be renamed
301
- // to "id")
286
+ // Docs are indexed by their id
302
287
  function createDocsByIdIndex(docs) {
303
- return Object.fromEntries(docs.flatMap((doc) => [
304
- [doc.unversionedId, doc],
305
- [doc.id, doc],
306
- ]));
288
+ return lodash_1.default.keyBy(docs, (d) => d.id);
307
289
  }
308
290
  exports.createDocsByIdIndex = createDocsByIdIndex;
@@ -35,7 +35,6 @@ const DocFrontMatterSchema = utils_validation_1.JoiFrontMatter.object({
35
35
  parse_number_prefixes: utils_validation_1.JoiFrontMatter.boolean(),
36
36
  pagination_next: utils_validation_1.JoiFrontMatter.string().allow(null),
37
37
  pagination_prev: utils_validation_1.JoiFrontMatter.string().allow(null),
38
- draft: utils_validation_1.JoiFrontMatter.boolean(),
39
38
  ...utils_validation_1.FrontMatterTOCHeadingLevels,
40
39
  last_update: utils_validation_1.JoiFrontMatter.object({
41
40
  author: utils_validation_1.JoiFrontMatter.string(),
@@ -46,7 +45,9 @@ const DocFrontMatterSchema = utils_validation_1.JoiFrontMatter.object({
46
45
  'object.missing': FrontMatterLastUpdateErrorMessage,
47
46
  'object.base': FrontMatterLastUpdateErrorMessage,
48
47
  }),
49
- }).unknown();
48
+ })
49
+ .unknown()
50
+ .concat(utils_validation_1.ContentVisibilitySchema);
50
51
  function validateDocFrontMatter(frontMatter) {
51
52
  return (0, utils_validation_1.validateFrontMatter)(frontMatter, DocFrontMatterSchema);
52
53
  }
package/lib/globalData.js CHANGED
@@ -12,8 +12,11 @@ const lodash_1 = tslib_1.__importDefault(require("lodash"));
12
12
  const docs_1 = require("./docs");
13
13
  function toGlobalDataDoc(doc) {
14
14
  return {
15
- id: doc.unversionedId,
15
+ id: doc.id,
16
16
  path: doc.permalink,
17
+ // optimize global data size: do not add unlisted: false/undefined
18
+ ...(doc.unlisted && { unlisted: doc.unlisted }),
19
+ // TODO optimize size? remove attribute when no sidebar (breaking change?)
17
20
  sidebar: doc.sidebar,
18
21
  };
19
22
  }
@@ -34,7 +37,7 @@ function toGlobalSidebars(sidebars, version) {
34
37
  link: {
35
38
  path: firstLink.type === 'generated-index'
36
39
  ? firstLink.permalink
37
- : version.docs.find((doc) => doc.id === firstLink.id || doc.unversionedId === firstLink.id).permalink,
40
+ : version.docs.find((doc) => doc.id === firstLink.id).permalink,
38
41
  label: firstLink.label,
39
42
  },
40
43
  };
@@ -50,7 +53,7 @@ function toGlobalDataVersion(version) {
50
53
  docs: version.docs
51
54
  .map(toGlobalDataDoc)
52
55
  .concat(version.categoryGeneratedIndices.map(toGlobalDataGeneratedIndex)),
53
- draftIds: version.drafts.map((doc) => doc.unversionedId),
56
+ draftIds: version.drafts.map((doc) => doc.id),
54
57
  sidebars: toGlobalSidebars(version.sidebars, version),
55
58
  };
56
59
  }
package/lib/index.js CHANGED
@@ -19,10 +19,7 @@ const versions_1 = require("./versions");
19
19
  const cli_1 = require("./cli");
20
20
  const constants_1 = require("./constants");
21
21
  const globalData_1 = require("./globalData");
22
- const props_1 = require("./props");
23
- const categoryGeneratedIndex_1 = require("./categoryGeneratedIndex");
24
22
  const translations_1 = require("./translations");
25
- const tags_1 = require("./tags");
26
23
  const routes_1 = require("./routes");
27
24
  const utils_2 = require("./sidebars/utils");
28
25
  async function pluginContentDocs(context, options) {
@@ -34,6 +31,8 @@ async function pluginContentDocs(context, options) {
34
31
  const pluginDataDirRoot = path_1.default.join(generatedFilesDir, 'docusaurus-plugin-content-docs');
35
32
  const dataDir = path_1.default.join(pluginDataDirRoot, pluginId);
36
33
  const aliasedSource = (source) => `~docs/${(0, utils_1.posixPath)(path_1.default.relative(pluginDataDirRoot, source))}`;
34
+ // TODO env should be injected into all plugins
35
+ const env = process.env.NODE_ENV;
37
36
  return {
38
37
  name: 'docusaurus-plugin-content-docs',
39
38
  extendCli(cli) {
@@ -80,13 +79,16 @@ async function pluginContentDocs(context, options) {
80
79
  versionMetadata,
81
80
  context,
82
81
  options,
83
- env: process.env.NODE_ENV,
82
+ env,
84
83
  });
85
84
  }
86
85
  return Promise.all(docFiles.map(processVersionDoc));
87
86
  }
88
87
  async function doLoadVersion(versionMetadata) {
89
88
  const docsBase = await loadVersionDocsBase(versionMetadata);
89
+ // TODO we only ever need draftIds in further code, not full draft items
90
+ // To simplify and prevent mistakes, avoid exposing draft
91
+ // replace draft=>draftIds in content loaded
90
92
  const [drafts, docs] = lodash_1.default.partition(docsBase, (doc) => doc.draft);
91
93
  const sidebars = await (0, sidebars_1.loadSidebars)(versionMetadata.sidebarFilePath, {
92
94
  sidebarItemsGenerator: options.sidebarItemsGenerator,
@@ -101,9 +103,23 @@ async function pluginContentDocs(context, options) {
101
103
  categoryLabelSlugger: (0, utils_1.createSlugger)(),
102
104
  });
103
105
  const sidebarsUtils = (0, utils_2.createSidebarsUtils)(sidebars);
106
+ const docsById = (0, docs_1.createDocsByIdIndex)(docs);
107
+ const allDocIds = Object.keys(docsById);
108
+ sidebarsUtils.checkLegacyVersionedSidebarNames({
109
+ sidebarFilePath: versionMetadata.sidebarFilePath,
110
+ versionMetadata,
111
+ });
112
+ sidebarsUtils.checkSidebarsDocIds({
113
+ allDocIds,
114
+ sidebarFilePath: versionMetadata.sidebarFilePath,
115
+ versionMetadata,
116
+ });
104
117
  return {
105
118
  ...versionMetadata,
106
- docs: (0, docs_1.addDocNavigation)(docs, sidebarsUtils, versionMetadata.sidebarFilePath),
119
+ docs: (0, docs_1.addDocNavigation)({
120
+ docs,
121
+ sidebarsUtils,
122
+ }),
107
123
  drafts,
108
124
  sidebars,
109
125
  };
@@ -125,81 +141,21 @@ async function pluginContentDocs(context, options) {
125
141
  return (0, translations_1.translateLoadedContent)(content, translationFiles);
126
142
  },
127
143
  async contentLoaded({ content, actions }) {
128
- const { loadedVersions } = content;
129
- const { docLayoutComponent, docItemComponent, docCategoryGeneratedIndexComponent, breadcrumbs, } = options;
130
- const { addRoute, createData, setGlobalData } = actions;
131
- const versions = loadedVersions.map((version) => {
132
- const sidebarsUtils = (0, utils_2.createSidebarsUtils)(version.sidebars);
133
- return {
134
- ...version,
135
- sidebarsUtils,
136
- categoryGeneratedIndices: (0, categoryGeneratedIndex_1.getCategoryGeneratedIndexMetadataList)({
137
- docs: version.docs,
138
- sidebarsUtils,
139
- }),
140
- };
141
- });
142
- async function createVersionTagsRoutes(version) {
143
- const versionTags = (0, tags_1.getVersionTags)(version.docs);
144
- // TODO tags should be a sub route of the version route
145
- async function createTagsListPage() {
146
- const tagsProp = Object.values(versionTags).map((tagValue) => ({
147
- label: tagValue.label,
148
- permalink: tagValue.permalink,
149
- count: tagValue.docIds.length,
150
- }));
151
- // Only create /tags page if there are tags.
152
- if (tagsProp.length > 0) {
153
- const tagsPropPath = await createData(`${(0, utils_1.docuHash)(`tags-list-${version.versionName}-prop`)}.json`, JSON.stringify(tagsProp, null, 2));
154
- addRoute({
155
- path: version.tagsPath,
156
- exact: true,
157
- component: options.docTagsListComponent,
158
- modules: {
159
- tags: aliasedSource(tagsPropPath),
160
- },
161
- });
162
- }
163
- }
164
- // TODO tags should be a sub route of the version route
165
- async function createTagDocListPage(tag) {
166
- const tagProps = (0, props_1.toTagDocListProp)({
167
- allTagsPath: version.tagsPath,
168
- tag,
169
- docs: version.docs,
170
- });
171
- const tagPropPath = await createData(`${(0, utils_1.docuHash)(`tag-${tag.permalink}`)}.json`, JSON.stringify(tagProps, null, 2));
172
- addRoute({
173
- path: tag.permalink,
174
- component: options.docTagDocListComponent,
175
- exact: true,
176
- modules: {
177
- tag: aliasedSource(tagPropPath),
178
- },
179
- });
180
- }
181
- await createTagsListPage();
182
- await Promise.all(Object.values(versionTags).map(createTagDocListPage));
183
- }
184
- await Promise.all(versions.map((version) => (0, routes_1.createVersionRoutes)({
185
- version,
186
- docItemComponent,
187
- docLayoutComponent,
188
- docCategoryGeneratedIndexComponent,
189
- pluginId,
190
- aliasedSource,
144
+ const versions = content.loadedVersions.map(versions_1.toFullVersion);
145
+ await (0, routes_1.createAllRoutes)({
146
+ baseUrl,
147
+ versions,
148
+ options,
191
149
  actions,
192
- })));
193
- // TODO tags should be a sub route of the version route
194
- await Promise.all(versions.map(createVersionTagsRoutes));
195
- setGlobalData({
150
+ aliasedSource,
151
+ });
152
+ actions.setGlobalData({
196
153
  path: (0, utils_1.normalizeUrl)([baseUrl, options.routeBasePath]),
197
154
  versions: versions.map(globalData_1.toGlobalDataVersion),
198
- breadcrumbs,
155
+ breadcrumbs: options.breadcrumbs,
199
156
  });
200
157
  },
201
158
  configureWebpack(_config, isServer, utils, content) {
202
- const { getJSLoader } = utils;
203
159
  const { rehypePlugins, remarkPlugins, beforeDefaultRehypePlugins, beforeDefaultRemarkPlugins, } = options;
204
160
  function getSourceToPermalink() {
205
161
  const allDocs = content.loadedVersions.flatMap((v) => v.docs);
@@ -222,7 +178,6 @@ async function pluginContentDocs(context, options) {
222
178
  test: /\.mdx?$/i,
223
179
  include: contentDirs,
224
180
  use: [
225
- getJSLoader({ isServer }),
226
181
  {
227
182
  loader: require.resolve('@docusaurus/mdx-loader'),
228
183
  options: {
package/lib/options.js CHANGED
@@ -21,7 +21,9 @@ exports.DEFAULT_OPTIONS = {
21
21
  exclude: utils_1.GlobExcludeDefault,
22
22
  sidebarItemsGenerator: generator_1.DefaultSidebarItemsGenerator,
23
23
  numberPrefixParser: numberPrefix_1.DefaultNumberPrefixParser,
24
- docLayoutComponent: '@theme/DocPage',
24
+ docsRootComponent: '@theme/DocsRoot',
25
+ docVersionRootComponent: '@theme/DocVersionRoot',
26
+ docRootComponent: '@theme/DocRoot',
25
27
  docItemComponent: '@theme/DocItem',
26
28
  docTagDocListComponent: '@theme/DocTagDocListPage',
27
29
  docTagsListComponent: '@theme/DocTagsListPage',
@@ -59,10 +61,7 @@ const OptionsSchema = utils_validation_1.Joi.object({
59
61
  editUrl: utils_validation_1.Joi.alternatives().try(utils_validation_1.URISchema, utils_validation_1.Joi.function()),
60
62
  editCurrentVersion: utils_validation_1.Joi.boolean().default(exports.DEFAULT_OPTIONS.editCurrentVersion),
61
63
  editLocalizedFiles: utils_validation_1.Joi.boolean().default(exports.DEFAULT_OPTIONS.editLocalizedFiles),
62
- routeBasePath: utils_validation_1.Joi.string()
63
- // '' not allowed, see https://github.com/facebook/docusaurus/issues/3374
64
- // .allow('') ""
65
- .default(exports.DEFAULT_OPTIONS.routeBasePath),
64
+ routeBasePath: utils_validation_1.RouteBasePathSchema.default(exports.DEFAULT_OPTIONS.routeBasePath),
66
65
  tagsBasePath: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.tagsBasePath),
67
66
  // @ts-expect-error: deprecated
68
67
  homePageId: utils_validation_1.Joi.any().forbidden().messages({
@@ -81,7 +80,9 @@ const OptionsSchema = utils_validation_1.Joi.object({
81
80
  then: utils_validation_1.Joi.custom((val) => val ? numberPrefix_1.DefaultNumberPrefixParser : numberPrefix_1.DisabledNumberPrefixParser),
82
81
  }))
83
82
  .default(() => exports.DEFAULT_OPTIONS.numberPrefixParser),
84
- docLayoutComponent: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.docLayoutComponent),
83
+ docsRootComponent: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.docsRootComponent),
84
+ docVersionRootComponent: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.docVersionRootComponent),
85
+ docRootComponent: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.docRootComponent),
85
86
  docItemComponent: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.docItemComponent),
86
87
  docTagsListComponent: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.docTagsListComponent),
87
88
  docTagDocListComponent: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.docTagDocListComponent),
package/lib/props.d.ts CHANGED
@@ -4,8 +4,13 @@
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 { VersionTag } from './types';
8
- import type { PropSidebars, PropVersionMetadata, PropTagDocList, DocMetadata, LoadedVersion } from '@docusaurus/plugin-content-docs';
7
+ import type { VersionTag, VersionTags } from './types';
8
+ import type { SidebarItemDoc } from './sidebars/types';
9
+ import type { PropSidebars, PropVersionMetadata, PropTagDocList, PropTagsListPage, PropSidebarItemLink, DocMetadata, LoadedVersion } from '@docusaurus/plugin-content-docs';
10
+ export declare function toSidebarDocItemLinkProp({ item, doc, }: {
11
+ item: SidebarItemDoc;
12
+ doc: Pick<DocMetadata, 'id' | 'title' | 'permalink' | 'unlisted' | 'frontMatter'>;
13
+ }): PropSidebarItemLink;
9
14
  export declare function toSidebarsProp(loadedVersion: LoadedVersion): PropSidebars;
10
15
  export declare function toVersionMetadataProp(pluginId: string, loadedVersion: LoadedVersion): PropVersionMetadata;
11
16
  export declare function toTagDocListProp({ allTagsPath, tag, docs, }: {
@@ -13,3 +18,4 @@ export declare function toTagDocListProp({ allTagsPath, tag, docs, }: {
13
18
  tag: VersionTag;
14
19
  docs: DocMetadata[];
15
20
  }): PropTagDocList;
21
+ export declare function toTagsListTagsProp(versionTags: VersionTags): PropTagsListPage['tags'];
package/lib/props.js CHANGED
@@ -6,10 +6,23 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.toTagDocListProp = exports.toVersionMetadataProp = exports.toSidebarsProp = void 0;
9
+ exports.toTagsListTagsProp = exports.toTagDocListProp = exports.toVersionMetadataProp = exports.toSidebarsProp = exports.toSidebarDocItemLinkProp = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
12
12
  const docs_1 = require("./docs");
13
+ function toSidebarDocItemLinkProp({ item, doc, }) {
14
+ const { id, title, permalink, frontMatter: { sidebar_label: sidebarLabel, sidebar_custom_props: customProps, }, unlisted, } = doc;
15
+ return {
16
+ type: 'link',
17
+ label: sidebarLabel ?? item.label ?? title,
18
+ href: permalink,
19
+ className: item.className,
20
+ customProps: item.customProps ?? customProps,
21
+ docId: id,
22
+ unlisted,
23
+ };
24
+ }
25
+ exports.toSidebarDocItemLinkProp = toSidebarDocItemLinkProp;
13
26
  function toSidebarsProp(loadedVersion) {
14
27
  const docsById = (0, docs_1.createDocsByIdIndex)(loadedVersion.docs);
15
28
  function getDocById(docId) {
@@ -22,16 +35,8 @@ Available document ids are:
22
35
  return docMetadata;
23
36
  }
24
37
  const convertDocLink = (item) => {
25
- const docMetadata = getDocById(item.id);
26
- const { title, permalink, frontMatter: { sidebar_label: sidebarLabel }, } = docMetadata;
27
- return {
28
- type: 'link',
29
- label: sidebarLabel ?? item.label ?? title,
30
- href: permalink,
31
- className: item.className,
32
- customProps: item.customProps ?? docMetadata.frontMatter.sidebar_custom_props,
33
- docId: docMetadata.unversionedId,
34
- };
38
+ const doc = getDocById(item.id);
39
+ return toSidebarDocItemLinkProp({ item, doc });
35
40
  };
36
41
  function getCategoryLinkHref(link) {
37
42
  switch (link?.type) {
@@ -43,6 +48,12 @@ Available document ids are:
43
48
  return undefined;
44
49
  }
45
50
  }
51
+ function getCategoryLinkUnlisted(link) {
52
+ if (link?.type === 'doc') {
53
+ return getDocById(link.id).unlisted;
54
+ }
55
+ return false;
56
+ }
46
57
  function getCategoryLinkCustomProps(link) {
47
58
  switch (link?.type) {
48
59
  case 'doc':
@@ -54,11 +65,13 @@ Available document ids are:
54
65
  function convertCategory(item) {
55
66
  const { link, ...rest } = item;
56
67
  const href = getCategoryLinkHref(link);
68
+ const linkUnlisted = getCategoryLinkUnlisted(link);
57
69
  const customProps = item.customProps ?? getCategoryLinkCustomProps(link);
58
70
  return {
59
71
  ...rest,
60
72
  items: item.items.map(normalizeItem),
61
73
  ...(href && { href }),
74
+ ...(linkUnlisted && { linkUnlisted }),
62
75
  ...(customProps && { customProps }),
63
76
  };
64
77
  }
@@ -82,9 +95,9 @@ Available document ids are:
82
95
  exports.toSidebarsProp = toSidebarsProp;
83
96
  function toVersionDocsProp(loadedVersion) {
84
97
  return Object.fromEntries(loadedVersion.docs.map((doc) => [
85
- doc.unversionedId,
98
+ doc.id,
86
99
  {
87
- id: doc.unversionedId,
100
+ id: doc.id,
88
101
  title: doc.title,
89
102
  description: doc.description,
90
103
  sidebar: doc.sidebar,
@@ -124,6 +137,17 @@ function toTagDocListProp({ allTagsPath, tag, docs, }) {
124
137
  allTagsPath,
125
138
  count: tag.docIds.length,
126
139
  items: toDocListProp(),
140
+ unlisted: tag.unlisted,
127
141
  };
128
142
  }
129
143
  exports.toTagDocListProp = toTagDocListProp;
144
+ function toTagsListTagsProp(versionTags) {
145
+ return Object.values(versionTags)
146
+ .filter((tagValue) => !tagValue.unlisted)
147
+ .map((tagValue) => ({
148
+ label: tagValue.label,
149
+ permalink: tagValue.permalink,
150
+ count: tagValue.docIds.length,
151
+ }));
152
+ }
153
+ exports.toTagsListTagsProp = toTagsListTagsProp;
package/lib/routes.d.ts CHANGED
@@ -6,24 +6,17 @@
6
6
  */
7
7
  import type { PluginContentLoadedActions, RouteConfig } from '@docusaurus/types';
8
8
  import type { FullVersion } from './types';
9
- import type { DocMetadata } from '@docusaurus/plugin-content-docs';
10
- export declare function createCategoryGeneratedIndexRoutes({ version, actions, docCategoryGeneratedIndexComponent, aliasedSource, }: {
11
- version: FullVersion;
9
+ import type { PluginOptions } from '@docusaurus/plugin-content-docs';
10
+ type BuildAllRoutesParam = Omit<CreateAllRoutesParam, 'actions'> & {
11
+ actions: Omit<PluginContentLoadedActions, 'addRoute' | 'setGlobalData'>;
12
+ };
13
+ export declare function buildAllRoutes(param: BuildAllRoutesParam): Promise<RouteConfig[]>;
14
+ type CreateAllRoutesParam = {
15
+ baseUrl: string;
16
+ versions: FullVersion[];
17
+ options: PluginOptions;
12
18
  actions: PluginContentLoadedActions;
13
- docCategoryGeneratedIndexComponent: string;
14
19
  aliasedSource: (str: string) => string;
15
- }): Promise<RouteConfig[]>;
16
- export declare function createDocRoutes({ docs, actions, docItemComponent, }: {
17
- docs: DocMetadata[];
18
- actions: PluginContentLoadedActions;
19
- docItemComponent: string;
20
- }): Promise<RouteConfig[]>;
21
- export declare function createVersionRoutes({ version, actions, docItemComponent, docLayoutComponent, docCategoryGeneratedIndexComponent, pluginId, aliasedSource, }: {
22
- version: FullVersion;
23
- actions: PluginContentLoadedActions;
24
- docLayoutComponent: string;
25
- docItemComponent: string;
26
- docCategoryGeneratedIndexComponent: string;
27
- pluginId: string;
28
- aliasedSource: (str: string) => string;
29
- }): Promise<void>;
20
+ };
21
+ export declare function createAllRoutes(param: CreateAllRoutesParam): Promise<void>;
22
+ export {};