@docusaurus/plugin-content-docs 2.4.0 → 3.0.0-alpha.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.
package/lib/routes.js CHANGED
@@ -6,20 +6,22 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.createVersionRoutes = exports.createDocRoutes = exports.createCategoryGeneratedIndexRoutes = void 0;
9
+ exports.createAllRoutes = exports.buildAllRoutes = void 0;
10
10
  const tslib_1 = require("tslib");
11
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
11
12
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
12
13
  const utils_1 = require("@docusaurus/utils");
13
14
  const props_1 = require("./props");
14
- async function createCategoryGeneratedIndexRoutes({ version, actions, docCategoryGeneratedIndexComponent, aliasedSource, }) {
15
+ const tags_1 = require("./tags");
16
+ async function buildVersionCategoryGeneratedIndexRoutes({ version, actions, options, aliasedSource, }) {
15
17
  const slugs = (0, utils_1.createSlugger)();
16
- async function createCategoryGeneratedIndexRoute(categoryGeneratedIndex) {
18
+ async function buildCategoryGeneratedIndexRoute(categoryGeneratedIndex) {
17
19
  const { sidebar, ...prop } = categoryGeneratedIndex;
18
20
  const propFileName = slugs.slug(`${version.path}-${categoryGeneratedIndex.sidebar}-category-${categoryGeneratedIndex.title}`);
19
21
  const propData = await actions.createData(`${(0, utils_1.docuHash)(`category/${propFileName}`)}.json`, JSON.stringify(prop, null, 2));
20
22
  return {
21
23
  path: categoryGeneratedIndex.permalink,
22
- component: docCategoryGeneratedIndexComponent,
24
+ component: options.docCategoryGeneratedIndexComponent,
23
25
  exact: true,
24
26
  modules: {
25
27
  categoryGeneratedIndex: aliasedSource(propData),
@@ -29,23 +31,22 @@ async function createCategoryGeneratedIndexRoutes({ version, actions, docCategor
29
31
  ...(sidebar && { sidebar }),
30
32
  };
31
33
  }
32
- return Promise.all(version.categoryGeneratedIndices.map(createCategoryGeneratedIndexRoute));
34
+ return Promise.all(version.categoryGeneratedIndices.map(buildCategoryGeneratedIndexRoute));
33
35
  }
34
- exports.createCategoryGeneratedIndexRoutes = createCategoryGeneratedIndexRoutes;
35
- async function createDocRoutes({ docs, actions, docItemComponent, }) {
36
- return Promise.all(docs.map(async (metadataItem) => {
36
+ async function buildVersionDocRoutes({ version, actions, options, }) {
37
+ return Promise.all(version.docs.map(async (metadataItem) => {
37
38
  await actions.createData(
38
39
  // Note that this created data path must be in sync with
39
40
  // metadataPath provided to mdx-loader.
40
41
  `${(0, utils_1.docuHash)(metadataItem.source)}.json`, JSON.stringify(metadataItem, null, 2));
41
42
  const docRoute = {
42
43
  path: metadataItem.permalink,
43
- component: docItemComponent,
44
+ component: options.docItemComponent,
44
45
  exact: true,
45
46
  modules: {
46
47
  content: metadataItem.source,
47
48
  },
48
- // Because the parent (DocPage) comp need to access it easily
49
+ // Because the parent (DocRoot) comp need to access it easily
49
50
  // This permits to render the sidebar once without unmount/remount when
50
51
  // navigating (and preserve sidebar state)
51
52
  ...(metadataItem.sidebar && {
@@ -55,42 +56,113 @@ async function createDocRoutes({ docs, actions, docItemComponent, }) {
55
56
  return docRoute;
56
57
  }));
57
58
  }
58
- exports.createDocRoutes = createDocRoutes;
59
- async function createVersionRoutes({ version, actions, docItemComponent, docLayoutComponent, docCategoryGeneratedIndexComponent, pluginId, aliasedSource, }) {
60
- async function doCreateVersionRoutes() {
61
- const versionMetadata = (0, props_1.toVersionMetadataProp)(pluginId, version);
62
- const versionMetadataPropPath = await actions.createData(`${(0, utils_1.docuHash)(`version-${version.versionName}-metadata-prop`)}.json`, JSON.stringify(versionMetadata, null, 2));
63
- async function createVersionSubRoutes() {
64
- const [docRoutes, sidebarsRoutes] = await Promise.all([
65
- createDocRoutes({ docs: version.docs, actions, docItemComponent }),
66
- createCategoryGeneratedIndexRoutes({
67
- version,
68
- actions,
69
- docCategoryGeneratedIndexComponent,
70
- aliasedSource,
71
- }),
72
- ]);
73
- const routes = [...docRoutes, ...sidebarsRoutes];
74
- return routes.sort((a, b) => a.path.localeCompare(b.path));
59
+ async function buildVersionSidebarRoute(param) {
60
+ const [docRoutes, categoryGeneratedIndexRoutes] = await Promise.all([
61
+ buildVersionDocRoutes(param),
62
+ buildVersionCategoryGeneratedIndexRoutes(param),
63
+ ]);
64
+ const subRoutes = [...docRoutes, ...categoryGeneratedIndexRoutes];
65
+ return {
66
+ path: param.version.path,
67
+ exact: false,
68
+ component: param.options.docRootComponent,
69
+ routes: subRoutes,
70
+ };
71
+ }
72
+ async function buildVersionTagsRoutes(param) {
73
+ const { version, options, actions, aliasedSource } = param;
74
+ const versionTags = (0, tags_1.getVersionTags)(version.docs);
75
+ async function buildTagsListRoute() {
76
+ // Don't create a tags list page if there's no tag
77
+ if (Object.keys(versionTags).length === 0) {
78
+ return null;
75
79
  }
76
- actions.addRoute({
80
+ const tagsProp = (0, props_1.toTagsListTagsProp)(versionTags);
81
+ const tagsPropPath = await actions.createData(`${(0, utils_1.docuHash)(`tags-list-${version.versionName}-prop`)}.json`, JSON.stringify(tagsProp, null, 2));
82
+ return {
83
+ path: version.tagsPath,
84
+ exact: true,
85
+ component: options.docTagsListComponent,
86
+ modules: {
87
+ tags: aliasedSource(tagsPropPath),
88
+ },
89
+ };
90
+ }
91
+ async function buildTagDocListRoute(tag) {
92
+ const tagProps = (0, props_1.toTagDocListProp)({
93
+ allTagsPath: version.tagsPath,
94
+ tag,
95
+ docs: version.docs,
96
+ });
97
+ const tagPropPath = await actions.createData(`${(0, utils_1.docuHash)(`tag-${tag.permalink}`)}.json`, JSON.stringify(tagProps, null, 2));
98
+ return {
99
+ path: tag.permalink,
100
+ component: options.docTagDocListComponent,
101
+ exact: true,
102
+ modules: {
103
+ tag: aliasedSource(tagPropPath),
104
+ },
105
+ };
106
+ }
107
+ const [tagsListRoute, allTagsDocListRoutes] = await Promise.all([
108
+ buildTagsListRoute(),
109
+ Promise.all(Object.values(versionTags).map(buildTagDocListRoute)),
110
+ ]);
111
+ return lodash_1.default.compact([tagsListRoute, ...allTagsDocListRoutes]);
112
+ }
113
+ async function buildVersionRoutes(param) {
114
+ const { version, actions, options, aliasedSource } = param;
115
+ async function buildVersionSubRoutes() {
116
+ const [sidebarRoute, tagsRoutes] = await Promise.all([
117
+ buildVersionSidebarRoute(param),
118
+ buildVersionTagsRoutes(param),
119
+ ]);
120
+ return [sidebarRoute, ...tagsRoutes];
121
+ }
122
+ async function doBuildVersionRoutes() {
123
+ const versionProp = (0, props_1.toVersionMetadataProp)(options.id, version);
124
+ const versionPropPath = await actions.createData(`${(0, utils_1.docuHash)(`version-${version.versionName}-metadata-prop`)}.json`, JSON.stringify(versionProp, null, 2));
125
+ const subRoutes = await buildVersionSubRoutes();
126
+ return {
77
127
  path: version.path,
78
- // Allow matching /docs/* since this is the wrapping route
79
128
  exact: false,
80
- component: docLayoutComponent,
81
- routes: await createVersionSubRoutes(),
129
+ component: options.docVersionRootComponent,
130
+ routes: subRoutes,
82
131
  modules: {
83
- versionMetadata: aliasedSource(versionMetadataPropPath),
132
+ version: aliasedSource(versionPropPath),
84
133
  },
85
134
  priority: version.routePriority,
86
- });
135
+ };
87
136
  }
88
137
  try {
89
- return await doCreateVersionRoutes();
138
+ return await doBuildVersionRoutes();
90
139
  }
91
140
  catch (err) {
92
141
  logger_1.default.error `Can't create version routes for version name=${version.versionName}`;
93
142
  throw err;
94
143
  }
95
144
  }
96
- exports.createVersionRoutes = createVersionRoutes;
145
+ // TODO we want this buildAllRoutes function to be easily testable
146
+ // Ideally, we should avoid side effects here (ie not injecting actions)
147
+ async function buildAllRoutes(param) {
148
+ const subRoutes = await Promise.all(param.versions.map((version) => buildVersionRoutes({
149
+ ...param,
150
+ version,
151
+ })));
152
+ // all docs routes are wrapped under a single parent route, this ensures
153
+ // the theme layout never unmounts/remounts when navigating between versions
154
+ return [
155
+ {
156
+ path: (0, utils_1.normalizeUrl)([param.baseUrl, param.options.routeBasePath]),
157
+ exact: false,
158
+ component: param.options.docsRootComponent,
159
+ routes: subRoutes,
160
+ },
161
+ ];
162
+ }
163
+ exports.buildAllRoutes = buildAllRoutes;
164
+ async function createAllRoutes(param) {
165
+ const routes = await buildAllRoutes(param);
166
+ routes.forEach(param.actions.addRoute);
167
+ }
168
+ exports.createAllRoutes = createAllRoutes;
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { Sidebars, SidebarProcessorParams, ProcessedSidebars } from './types';
8
- export declare type SidebarPostProcessorParams = SidebarProcessorParams & {
8
+ export type SidebarPostProcessorParams = SidebarProcessorParams & {
9
9
  draftIds: Set<string>;
10
10
  };
11
11
  export declare function postProcessSidebars(sidebars: ProcessedSidebars, params: SidebarProcessorParams): Sidebars;
@@ -7,18 +7,18 @@
7
7
  import type { Optional, Required } from 'utility-types';
8
8
  import type { NumberPrefixParser, SidebarOptions, CategoryIndexMatcher, DocMetadataBase, VersionMetadata } from '@docusaurus/plugin-content-docs';
9
9
  import type { Slugger } from '@docusaurus/utils';
10
- declare type Expand<T extends {
10
+ type Expand<T extends {
11
11
  [x: string]: unknown;
12
12
  }> = {
13
13
  [P in keyof T]: T[P];
14
14
  };
15
- export declare type SidebarItemBase = {
15
+ export type SidebarItemBase = {
16
16
  className?: string;
17
17
  customProps?: {
18
18
  [key: string]: unknown;
19
19
  };
20
20
  };
21
- export declare type SidebarItemDoc = SidebarItemBase & {
21
+ export type SidebarItemDoc = SidebarItemBase & {
22
22
  type: 'doc' | 'ref';
23
23
  label?: string;
24
24
  id: string;
@@ -28,34 +28,34 @@ export declare type SidebarItemDoc = SidebarItemBase & {
28
28
  */
29
29
  translatable?: true;
30
30
  };
31
- export declare type SidebarItemHtml = SidebarItemBase & {
31
+ export type SidebarItemHtml = SidebarItemBase & {
32
32
  type: 'html';
33
33
  value: string;
34
34
  defaultStyle?: boolean;
35
35
  };
36
- export declare type SidebarItemLink = SidebarItemBase & {
36
+ export type SidebarItemLink = SidebarItemBase & {
37
37
  type: 'link';
38
38
  href: string;
39
39
  label: string;
40
40
  autoAddBaseUrl?: boolean;
41
41
  description?: string;
42
42
  };
43
- export declare type SidebarItemAutogenerated = SidebarItemBase & {
43
+ export type SidebarItemAutogenerated = SidebarItemBase & {
44
44
  type: 'autogenerated';
45
45
  dirName: string;
46
46
  };
47
- declare type SidebarItemCategoryBase = SidebarItemBase & {
47
+ type SidebarItemCategoryBase = SidebarItemBase & {
48
48
  type: 'category';
49
49
  label: string;
50
50
  collapsed: boolean;
51
51
  collapsible: boolean;
52
52
  description?: string;
53
53
  };
54
- export declare type SidebarItemCategoryLinkDoc = {
54
+ export type SidebarItemCategoryLinkDoc = {
55
55
  type: 'doc';
56
56
  id: string;
57
57
  };
58
- export declare type SidebarItemCategoryLinkGeneratedIndexConfig = {
58
+ export type SidebarItemCategoryLinkGeneratedIndexConfig = {
59
59
  type: 'generated-index';
60
60
  slug?: string;
61
61
  title?: string;
@@ -63,7 +63,7 @@ export declare type SidebarItemCategoryLinkGeneratedIndexConfig = {
63
63
  image?: string;
64
64
  keywords?: string | readonly string[];
65
65
  };
66
- export declare type SidebarItemCategoryLinkGeneratedIndex = {
66
+ export type SidebarItemCategoryLinkGeneratedIndex = {
67
67
  type: 'generated-index';
68
68
  slug: string;
69
69
  permalink: string;
@@ -72,68 +72,70 @@ export declare type SidebarItemCategoryLinkGeneratedIndex = {
72
72
  image?: string;
73
73
  keywords?: string | readonly string[];
74
74
  };
75
- export declare type SidebarItemCategoryLinkConfig = SidebarItemCategoryLinkDoc | SidebarItemCategoryLinkGeneratedIndexConfig;
76
- export declare type SidebarItemCategoryLink = SidebarItemCategoryLinkDoc | SidebarItemCategoryLinkGeneratedIndex;
77
- export declare type SidebarItemCategoryConfig = Expand<Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
75
+ export type SidebarItemCategoryLinkConfig = SidebarItemCategoryLinkDoc | SidebarItemCategoryLinkGeneratedIndexConfig;
76
+ export type SidebarItemCategoryLink = SidebarItemCategoryLinkDoc | SidebarItemCategoryLinkGeneratedIndex;
77
+ export type SidebarItemCategoryConfig = Expand<Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
78
78
  items: SidebarCategoriesShorthand | SidebarItemConfig[];
79
79
  link?: SidebarItemCategoryLinkConfig;
80
80
  }>;
81
- export declare type SidebarCategoriesShorthand = {
81
+ export type SidebarCategoriesShorthand = {
82
82
  [sidebarCategory: string]: SidebarCategoriesShorthand | SidebarItemConfig[];
83
83
  };
84
- export declare type SidebarItemConfig = Omit<SidebarItemDoc, 'translatable'> | SidebarItemHtml | SidebarItemLink | SidebarItemAutogenerated | SidebarItemCategoryConfig | string | SidebarCategoriesShorthand;
85
- export declare type SidebarConfig = SidebarCategoriesShorthand | SidebarItemConfig[];
86
- export declare type SidebarsConfig = {
84
+ export type SidebarItemConfig = Omit<SidebarItemDoc, 'translatable'> | SidebarItemHtml | SidebarItemLink | SidebarItemAutogenerated | SidebarItemCategoryConfig | string | SidebarCategoriesShorthand;
85
+ export type SidebarConfig = SidebarCategoriesShorthand | SidebarItemConfig[];
86
+ export type SidebarsConfig = {
87
87
  [sidebarId: string]: SidebarConfig;
88
88
  };
89
- export declare type NormalizedSidebarItemCategory = Expand<Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
89
+ export type NormalizedSidebarItemCategory = Expand<Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
90
90
  items: NormalizedSidebarItem[];
91
91
  link?: SidebarItemCategoryLinkConfig;
92
92
  }>;
93
- export declare type NormalizedSidebarItem = SidebarItemDoc | SidebarItemHtml | SidebarItemLink | NormalizedSidebarItemCategory | SidebarItemAutogenerated;
94
- export declare type NormalizedSidebar = NormalizedSidebarItem[];
95
- export declare type NormalizedSidebars = {
93
+ export type NormalizedSidebarItem = SidebarItemDoc | SidebarItemHtml | SidebarItemLink | NormalizedSidebarItemCategory | SidebarItemAutogenerated;
94
+ export type NormalizedSidebar = NormalizedSidebarItem[];
95
+ export type NormalizedSidebars = {
96
96
  [sidebarId: string]: NormalizedSidebar;
97
97
  };
98
- export declare type ProcessedSidebarItemCategory = Expand<Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
98
+ export type ProcessedSidebarItemCategory = Expand<Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
99
99
  items: ProcessedSidebarItem[];
100
100
  link?: SidebarItemCategoryLinkConfig;
101
101
  }>;
102
- export declare type ProcessedSidebarItem = SidebarItemDoc | SidebarItemHtml | SidebarItemLink | ProcessedSidebarItemCategory;
103
- export declare type ProcessedSidebar = ProcessedSidebarItem[];
104
- export declare type ProcessedSidebars = {
102
+ export type ProcessedSidebarItem = SidebarItemDoc | SidebarItemHtml | SidebarItemLink | ProcessedSidebarItemCategory;
103
+ export type ProcessedSidebar = ProcessedSidebarItem[];
104
+ export type ProcessedSidebars = {
105
105
  [sidebarId: string]: ProcessedSidebar;
106
106
  };
107
- export declare type SidebarItemCategory = Expand<SidebarItemCategoryBase & {
107
+ export type SidebarItemCategory = Expand<SidebarItemCategoryBase & {
108
108
  items: SidebarItem[];
109
109
  link?: SidebarItemCategoryLink;
110
110
  }>;
111
- export declare type SidebarItemCategoryWithLink = Required<SidebarItemCategory, 'link'>;
112
- export declare type SidebarItemCategoryWithGeneratedIndex = SidebarItemCategoryWithLink & {
111
+ export type SidebarItemCategoryWithLink = Required<SidebarItemCategory, 'link'>;
112
+ export type SidebarItemCategoryWithGeneratedIndex = SidebarItemCategoryWithLink & {
113
113
  link: SidebarItemCategoryLinkGeneratedIndex;
114
114
  };
115
- export declare type SidebarItem = SidebarItemDoc | SidebarItemHtml | SidebarItemLink | SidebarItemCategory;
116
- export declare type SidebarNavigationItem = SidebarItemDoc | SidebarItemCategoryWithLink;
117
- export declare type Sidebar = SidebarItem[];
118
- export declare type SidebarItemType = SidebarItem['type'];
119
- export declare type Sidebars = {
115
+ export type SidebarItem = SidebarItemDoc | SidebarItemHtml | SidebarItemLink | SidebarItemCategory;
116
+ export type SidebarNavigationItem = SidebarItemDoc | SidebarItemCategoryWithLink;
117
+ export type Sidebar = SidebarItem[];
118
+ export type SidebarItemType = SidebarItem['type'];
119
+ export type Sidebars = {
120
120
  [sidebarId: string]: Sidebar;
121
121
  };
122
- export declare type PropSidebarItemCategory = Expand<SidebarItemCategoryBase & {
122
+ export type PropSidebarItemCategory = Expand<SidebarItemCategoryBase & {
123
123
  items: PropSidebarItem[];
124
124
  href?: string;
125
+ linkUnlisted?: boolean;
125
126
  }>;
126
- export declare type PropSidebarItemLink = SidebarItemLink & {
127
+ export type PropSidebarItemLink = SidebarItemLink & {
127
128
  docId?: string;
129
+ unlisted?: boolean;
128
130
  };
129
- export declare type PropSidebarItemHtml = SidebarItemHtml;
130
- export declare type PropSidebarItem = PropSidebarItemLink | PropSidebarItemCategory | PropSidebarItemHtml;
131
- export declare type PropSidebar = PropSidebarItem[];
132
- export declare type PropSidebars = {
131
+ export type PropSidebarItemHtml = SidebarItemHtml;
132
+ export type PropSidebarItem = PropSidebarItemLink | PropSidebarItemCategory | PropSidebarItemHtml;
133
+ export type PropSidebar = PropSidebarItem[];
134
+ export type PropSidebars = {
133
135
  [sidebarId: string]: PropSidebar;
134
136
  };
135
- export declare type PropSidebarBreadcrumbsItem = PropSidebarItemLink | PropSidebarItemCategory;
136
- export declare type CategoryMetadataFile = {
137
+ export type PropSidebarBreadcrumbsItem = PropSidebarItemLink | PropSidebarItemCategory;
138
+ export type CategoryMetadataFile = {
137
139
  label?: string;
138
140
  position?: number;
139
141
  collapsed?: boolean;
@@ -144,9 +146,9 @@ export declare type CategoryMetadataFile = {
144
146
  [key: string]: unknown;
145
147
  };
146
148
  };
147
- export declare type SidebarItemsGeneratorDoc = Pick<DocMetadataBase, 'id' | 'unversionedId' | 'title' | 'frontMatter' | 'source' | 'sourceDirName' | 'sidebarPosition'>;
148
- export declare type SidebarItemsGeneratorVersion = Pick<VersionMetadata, 'versionName' | 'contentPath'>;
149
- export declare type SidebarItemsGeneratorArgs = {
149
+ export type SidebarItemsGeneratorDoc = Pick<DocMetadataBase, 'id' | 'unversionedId' | 'title' | 'frontMatter' | 'source' | 'sourceDirName' | 'sidebarPosition'>;
150
+ export type SidebarItemsGeneratorVersion = Pick<VersionMetadata, 'versionName' | 'contentPath'>;
151
+ export type SidebarItemsGeneratorArgs = {
150
152
  /** The sidebar item with type "autogenerated" to be transformed. */
151
153
  item: SidebarItemAutogenerated;
152
154
  /** Useful metadata for the version this sidebar belongs to. */
@@ -165,8 +167,8 @@ export declare type SidebarItemsGeneratorArgs = {
165
167
  [filePath: string]: CategoryMetadataFile;
166
168
  };
167
169
  };
168
- export declare type SidebarItemsGenerator = (generatorArgs: SidebarItemsGeneratorArgs) => NormalizedSidebar | Promise<NormalizedSidebar>;
169
- export declare type SidebarItemsGeneratorOption = (generatorArgs: {
170
+ export type SidebarItemsGenerator = (generatorArgs: SidebarItemsGeneratorArgs) => NormalizedSidebar | Promise<NormalizedSidebar>;
171
+ export type SidebarItemsGeneratorOption = (generatorArgs: {
170
172
  /**
171
173
  * Useful to re-use/enhance the default sidebar generation logic from
172
174
  * Docusaurus.
@@ -174,7 +176,7 @@ export declare type SidebarItemsGeneratorOption = (generatorArgs: {
174
176
  */
175
177
  defaultSidebarItemsGenerator: SidebarItemsGenerator;
176
178
  } & SidebarItemsGeneratorArgs) => NormalizedSidebar | Promise<NormalizedSidebar>;
177
- export declare type SidebarProcessorParams = {
179
+ export type SidebarProcessorParams = {
178
180
  sidebarItemsGenerator: SidebarItemsGeneratorOption;
179
181
  numberPrefixParser: NumberPrefixParser;
180
182
  docs: DocMetadataBase[];
@@ -20,16 +20,21 @@ export declare function collectSidebarsDocIds(sidebars: Sidebars): {
20
20
  export declare function collectSidebarsNavigations(sidebars: Sidebars): {
21
21
  [sidebarId: string]: SidebarNavigationItem[];
22
22
  };
23
- export declare type SidebarNavigation = {
23
+ export type SidebarNavigation = {
24
24
  sidebarName: string | undefined;
25
25
  previous: SidebarNavigationItem | undefined;
26
26
  next: SidebarNavigationItem | undefined;
27
27
  };
28
- export declare type SidebarsUtils = {
28
+ export type SidebarsUtils = {
29
29
  sidebars: Sidebars;
30
30
  getFirstDocIdOfFirstSidebar: () => string | undefined;
31
31
  getSidebarNameByDocId: (docId: string) => string | undefined;
32
- getDocNavigation: (unversionedId: string, versionedId: string, displayedSidebar: string | null | undefined) => SidebarNavigation;
32
+ getDocNavigation: (params: {
33
+ unversionedId: string;
34
+ versionedId: string;
35
+ displayedSidebar: string | null | undefined;
36
+ unlistedIds: Set<string>;
37
+ }) => SidebarNavigation;
33
38
  getCategoryGeneratedIndexList: () => SidebarItemCategoryWithGeneratedIndex[];
34
39
  getCategoryGeneratedIndexNavigation: (categoryGeneratedIndexPermalink: string) => SidebarNavigation;
35
40
  /**
@@ -110,7 +110,7 @@ function createSidebarsUtils(sidebars) {
110
110
  next: undefined,
111
111
  };
112
112
  }
113
- function getDocNavigation(unversionedId, versionedId, displayedSidebar) {
113
+ function getDocNavigation({ unversionedId, versionedId, displayedSidebar, unlistedIds, }) {
114
114
  // TODO legacy id retro-compatibility!
115
115
  let docId = unversionedId;
116
116
  let sidebarName = displayedSidebar === undefined
@@ -123,10 +123,22 @@ function createSidebarsUtils(sidebars) {
123
123
  if (!sidebarName) {
124
124
  return emptySidebarNavigation();
125
125
  }
126
- const navigationItems = sidebarNameToNavigationItems[sidebarName];
126
+ let navigationItems = sidebarNameToNavigationItems[sidebarName];
127
127
  if (!navigationItems) {
128
128
  throw new Error(`Doc with ID ${docId} wants to display sidebar ${sidebarName} but a sidebar with this name doesn't exist`);
129
129
  }
130
+ // Filter unlisted items from navigation
131
+ navigationItems = navigationItems.filter((item) => {
132
+ if (item.type === 'doc' && unlistedIds.has(item.id)) {
133
+ return false;
134
+ }
135
+ if (item.type === 'category' &&
136
+ item.link.type === 'doc' &&
137
+ unlistedIds.has(item.link.id)) {
138
+ return false;
139
+ }
140
+ return true;
141
+ });
130
142
  const currentItemIndex = navigationItems.findIndex((item) => {
131
143
  if (item.type === 'doc') {
132
144
  return item.id === docId;
package/lib/tags.js CHANGED
@@ -12,10 +12,17 @@ const lodash_1 = tslib_1.__importDefault(require("lodash"));
12
12
  const utils_1 = require("@docusaurus/utils");
13
13
  function getVersionTags(docs) {
14
14
  const groups = (0, utils_1.groupTaggedItems)(docs, (doc) => doc.tags);
15
- return lodash_1.default.mapValues(groups, (group) => ({
16
- label: group.tag.label,
17
- docIds: group.items.map((item) => item.id),
18
- permalink: group.tag.permalink,
19
- }));
15
+ return lodash_1.default.mapValues(groups, ({ tag, items: tagDocs }) => {
16
+ const tagVisibility = (0, utils_1.getTagVisibility)({
17
+ items: tagDocs,
18
+ isUnlisted: (item) => item.unlisted,
19
+ });
20
+ return {
21
+ label: tag.label,
22
+ docIds: tagVisibility.listedItems.map((item) => item.id),
23
+ permalink: tag.permalink,
24
+ unlisted: tagVisibility.unlisted,
25
+ };
26
+ });
20
27
  }
21
28
  exports.getVersionTags = getVersionTags;
package/lib/types.d.ts CHANGED
@@ -7,28 +7,29 @@
7
7
  import type { BrokenMarkdownLink, Tag } from '@docusaurus/utils';
8
8
  import type { VersionMetadata, LoadedVersion, CategoryGeneratedIndexMetadata } from '@docusaurus/plugin-content-docs';
9
9
  import type { SidebarsUtils } from './sidebars/utils';
10
- export declare type DocFile = {
10
+ export type DocFile = {
11
11
  contentPath: string;
12
12
  filePath: string;
13
13
  source: string;
14
14
  content: string;
15
15
  };
16
- export declare type SourceToPermalink = {
16
+ export type SourceToPermalink = {
17
17
  [source: string]: string;
18
18
  };
19
- export declare type VersionTag = Tag & {
19
+ export type VersionTag = Tag & {
20
20
  /** All doc ids having this tag. */
21
21
  docIds: string[];
22
+ unlisted: boolean;
22
23
  };
23
- export declare type VersionTags = {
24
+ export type VersionTags = {
24
25
  [permalink: string]: VersionTag;
25
26
  };
26
- export declare type FullVersion = LoadedVersion & {
27
+ export type FullVersion = LoadedVersion & {
27
28
  sidebarsUtils: SidebarsUtils;
28
29
  categoryGeneratedIndices: CategoryGeneratedIndexMetadata[];
29
30
  };
30
- export declare type DocBrokenMarkdownLink = BrokenMarkdownLink<VersionMetadata>;
31
- export declare type DocsMarkdownOption = {
31
+ export type DocBrokenMarkdownLink = BrokenMarkdownLink<VersionMetadata>;
32
+ export type DocsMarkdownOption = {
32
33
  versionsMetadata: VersionMetadata[];
33
34
  siteDir: string;
34
35
  sourceToPermalink: SourceToPermalink;
@@ -4,9 +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 { PluginOptions, VersionBanner, VersionMetadata } from '@docusaurus/plugin-content-docs';
7
+ import type { FullVersion } from '../types';
8
8
  import type { LoadContext } from '@docusaurus/types';
9
- export declare type VersionContext = {
9
+ import type { LoadedVersion, PluginOptions, VersionBanner, VersionMetadata } from '@docusaurus/plugin-content-docs';
10
+ export type VersionContext = {
10
11
  /** The version name to get banner of. */
11
12
  versionName: string;
12
13
  /** All versions, ordered from newest to oldest. */
@@ -35,3 +36,4 @@ export declare function readVersionsMetadata({ context, options, }: {
35
36
  context: LoadContext;
36
37
  options: PluginOptions;
37
38
  }): Promise<VersionMetadata[]>;
39
+ export declare function toFullVersion(version: LoadedVersion): FullVersion;
@@ -6,13 +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.readVersionsMetadata = exports.filterVersions = exports.getVersionNoIndex = exports.getVersionBadge = exports.getVersionBanner = exports.getDefaultVersionBanner = void 0;
9
+ exports.toFullVersion = exports.readVersionsMetadata = exports.filterVersions = exports.getVersionNoIndex = exports.getVersionBadge = exports.getVersionBanner = exports.getDefaultVersionBanner = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const path_1 = tslib_1.__importDefault(require("path"));
12
12
  const utils_1 = require("@docusaurus/utils");
13
13
  const constants_1 = require("../constants");
14
14
  const validation_1 = require("./validation");
15
15
  const files_1 = require("./files");
16
+ const utils_2 = require("../sidebars/utils");
17
+ const categoryGeneratedIndex_1 = require("../categoryGeneratedIndex");
16
18
  function getVersionEditUrls({ contentPath, contentPathLocalized, context, options, }) {
17
19
  // If the user is using the functional form of editUrl,
18
20
  // she has total freedom and we can't compute a "version edit url"
@@ -157,3 +159,15 @@ async function readVersionsMetadata({ context, options, }) {
157
159
  return versionsMetadata;
158
160
  }
159
161
  exports.readVersionsMetadata = readVersionsMetadata;
162
+ function toFullVersion(version) {
163
+ const sidebarsUtils = (0, utils_2.createSidebarsUtils)(version.sidebars);
164
+ return {
165
+ ...version,
166
+ sidebarsUtils,
167
+ categoryGeneratedIndices: (0, categoryGeneratedIndex_1.getCategoryGeneratedIndexMetadataList)({
168
+ docs: version.docs,
169
+ sidebarsUtils,
170
+ }),
171
+ };
172
+ }
173
+ exports.toFullVersion = toFullVersion;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-docs",
3
- "version": "2.4.0",
3
+ "version": "3.0.0-alpha.0",
4
4
  "description": "Docs plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "sideEffects": false,
@@ -35,22 +35,22 @@
35
35
  },
36
36
  "license": "MIT",
37
37
  "dependencies": {
38
- "@docusaurus/core": "2.4.0",
39
- "@docusaurus/logger": "2.4.0",
40
- "@docusaurus/mdx-loader": "2.4.0",
41
- "@docusaurus/module-type-aliases": "2.4.0",
42
- "@docusaurus/types": "2.4.0",
43
- "@docusaurus/utils": "2.4.0",
44
- "@docusaurus/utils-validation": "2.4.0",
38
+ "@docusaurus/core": "3.0.0-alpha.0",
39
+ "@docusaurus/logger": "3.0.0-alpha.0",
40
+ "@docusaurus/mdx-loader": "3.0.0-alpha.0",
41
+ "@docusaurus/module-type-aliases": "3.0.0-alpha.0",
42
+ "@docusaurus/types": "3.0.0-alpha.0",
43
+ "@docusaurus/utils": "3.0.0-alpha.0",
44
+ "@docusaurus/utils-validation": "3.0.0-alpha.0",
45
45
  "@types/react-router-config": "^5.0.6",
46
46
  "combine-promises": "^1.1.0",
47
- "fs-extra": "^10.1.0",
47
+ "fs-extra": "^11.1.0",
48
48
  "import-fresh": "^3.3.0",
49
49
  "js-yaml": "^4.1.0",
50
50
  "lodash": "^4.17.21",
51
- "tslib": "^2.4.0",
51
+ "tslib": "^2.5.0",
52
52
  "utility-types": "^3.10.0",
53
- "webpack": "^5.73.0"
53
+ "webpack": "^5.76.0"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@types/js-yaml": "^4.0.5",
@@ -60,11 +60,11 @@
60
60
  "shelljs": "^0.8.5"
61
61
  },
62
62
  "peerDependencies": {
63
- "react": "^16.8.4 || ^17.0.0",
64
- "react-dom": "^16.8.4 || ^17.0.0"
63
+ "react": "^18.0.0",
64
+ "react-dom": "^18.0.0"
65
65
  },
66
66
  "engines": {
67
67
  "node": ">=16.14"
68
68
  },
69
- "gitHead": "898b85ef134cc43bf3b1209aad0ca8cdcfb214c5"
69
+ "gitHead": "7327f7ff880ed97ad7855744e59c9c55d467a950"
70
70
  }
@@ -37,7 +37,8 @@ export type GlobalDoc = {
37
37
  */
38
38
  id: string;
39
39
  path: string;
40
- sidebar: string | undefined;
40
+ sidebar?: string;
41
+ unlisted?: boolean;
41
42
  };
42
43
 
43
44
  export type GlobalVersion = {