@docusaurus/plugin-content-docs 0.0.0-4786 → 0.0.0-4791
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/categoryGeneratedIndex.d.ts +1 -1
- package/lib/categoryGeneratedIndex.js +4 -2
- package/lib/cli.js +2 -2
- package/lib/docs.d.ts +3 -3
- package/lib/docs.js +4 -5
- package/lib/frontMatter.d.ts +1 -1
- package/lib/globalData.js +2 -2
- package/lib/index.js +3 -3
- package/lib/markdown/linkify.js +1 -2
- package/lib/props.d.ts +2 -2
- package/lib/props.js +5 -5
- package/lib/routes.d.ts +2 -1
- package/lib/routes.js +4 -16
- package/lib/sidebars/generator.js +1 -1
- package/lib/sidebars/postProcessor.js +1 -1
- package/lib/sidebars/types.d.ts +14 -11
- package/lib/sidebars/utils.d.ts +3 -3
- package/lib/slug.d.ts +1 -2
- package/lib/tags.d.ts +2 -1
- package/lib/tags.js +1 -1
- package/lib/translations.js +2 -2
- package/lib/types.d.ts +4 -87
- package/lib/versions.d.ts +1 -3
- package/lib/versions.js +21 -32
- package/package.json +9 -9
- package/src/categoryGeneratedIndex.ts +8 -3
- package/src/cli.ts +2 -2
- package/src/docs.ts +13 -17
- package/src/frontMatter.ts +1 -1
- package/src/globalData.ts +4 -4
- package/src/index.ts +8 -8
- package/src/markdown/linkify.ts +2 -3
- package/src/plugin-content-docs.d.ts +377 -66
- package/src/props.ts +8 -7
- package/src/routes.ts +6 -30
- package/src/sidebars/generator.ts +2 -2
- package/src/sidebars/postProcessor.ts +1 -1
- package/src/sidebars/processor.ts +4 -1
- package/src/sidebars/types.ts +15 -11
- package/src/sidebars/utils.ts +6 -3
- package/src/slug.ts +4 -2
- package/src/tags.ts +3 -2
- package/src/translations.ts +2 -3
- package/src/types.ts +9 -96
- package/src/versions.ts +28 -41
|
@@ -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 { CategoryGeneratedIndexMetadata, DocMetadataBase } from '
|
|
7
|
+
import type { CategoryGeneratedIndexMetadata, DocMetadataBase } from '@docusaurus/plugin-content-docs';
|
|
8
8
|
import { type SidebarsUtils } from './sidebars/utils';
|
|
9
9
|
export declare function getCategoryGeneratedIndexMetadataList({ docs, sidebarsUtils, }: {
|
|
10
10
|
sidebarsUtils: SidebarsUtils;
|
|
@@ -19,8 +19,10 @@ function getCategoryGeneratedIndexMetadata({ category, sidebarsUtils, docsById,
|
|
|
19
19
|
slug: category.link.slug,
|
|
20
20
|
permalink: category.link.permalink,
|
|
21
21
|
sidebar: sidebarName,
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
navigation: {
|
|
23
|
+
previous: (0, utils_1.toNavigationLink)(previous, docsById),
|
|
24
|
+
next: (0, utils_1.toNavigationLink)(next, docsById),
|
|
25
|
+
},
|
|
24
26
|
};
|
|
25
27
|
}
|
|
26
28
|
function getCategoryGeneratedIndexMetadataList({ docs, sidebarsUtils, }) {
|
package/lib/cli.js
CHANGED
|
@@ -64,7 +64,7 @@ async function cliDocsVersionCommand(version, siteDir, pluginId, options) {
|
|
|
64
64
|
}
|
|
65
65
|
const { path: docsPath, sidebarPath } = options;
|
|
66
66
|
// Copy docs files.
|
|
67
|
-
const docsDir = path_1.default.
|
|
67
|
+
const docsDir = path_1.default.resolve(siteDir, docsPath);
|
|
68
68
|
if ((await fs_extra_1.default.pathExists(docsDir)) &&
|
|
69
69
|
(await fs_extra_1.default.readdir(docsDir)).length > 0) {
|
|
70
70
|
const versionedDir = (0, versions_1.getVersionedDocsDirPath)(siteDir, pluginId);
|
|
@@ -72,7 +72,7 @@ async function cliDocsVersionCommand(version, siteDir, pluginId, options) {
|
|
|
72
72
|
await fs_extra_1.default.copy(docsDir, newVersionDir);
|
|
73
73
|
}
|
|
74
74
|
else {
|
|
75
|
-
throw new Error(`${pluginIdLogPrefix}:
|
|
75
|
+
throw new Error(`${pluginIdLogPrefix}: no docs found in ${docsDir}.`);
|
|
76
76
|
}
|
|
77
77
|
await createVersionedSidebarFile({
|
|
78
78
|
siteDir,
|
package/lib/docs.d.ts
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { LoadContext } from '@docusaurus/types';
|
|
8
|
-
import type { DocFile,
|
|
8
|
+
import type { DocFile, LoadedVersion } from './types';
|
|
9
9
|
import type { SidebarsUtils } from './sidebars/utils';
|
|
10
|
-
import type { MetadataOptions, PluginOptions, CategoryIndexMatcher,
|
|
10
|
+
import type { MetadataOptions, PluginOptions, CategoryIndexMatcher, DocMetadataBase, VersionMetadata } from '@docusaurus/plugin-content-docs';
|
|
11
11
|
declare type LastUpdateOptions = Pick<PluginOptions, 'showLastUpdateAuthor' | 'showLastUpdateTime'>;
|
|
12
12
|
export declare function readDocFile(versionMetadata: Pick<VersionMetadata, 'contentPath' | 'contentPathLocalized'>, source: string, options: LastUpdateOptions): Promise<DocFile>;
|
|
13
13
|
export declare function readVersionDocs(versionMetadata: VersionMetadata, options: Pick<PluginOptions, 'include' | 'exclude' | 'showLastUpdateAuthor' | 'showLastUpdateTime'>): Promise<DocFile[]>;
|
|
@@ -34,7 +34,7 @@ export declare const isCategoryIndex: CategoryIndexMatcher;
|
|
|
34
34
|
* `guides/sidebar/autogenerated.md` ->
|
|
35
35
|
* `'autogenerated', '.md', ['sidebar', 'guides']`
|
|
36
36
|
*/
|
|
37
|
-
export declare function toCategoryIndexMatcherParam({ source, sourceDirName, }: Pick<DocMetadataBase, 'source' | 'sourceDirName'>):
|
|
37
|
+
export declare function toCategoryIndexMatcherParam({ source, sourceDirName, }: Pick<DocMetadataBase, 'source' | 'sourceDirName'>): Parameters<CategoryIndexMatcher>[0];
|
|
38
38
|
export declare function getDocIds(doc: DocMetadataBase): [string, string];
|
|
39
39
|
export declare function createDocsByIdIndex<Doc extends {
|
|
40
40
|
id: string;
|
package/lib/docs.js
CHANGED
|
@@ -15,7 +15,6 @@ const utils_1 = require("@docusaurus/utils");
|
|
|
15
15
|
const lastUpdate_1 = require("./lastUpdate");
|
|
16
16
|
const slug_1 = tslib_1.__importDefault(require("./slug"));
|
|
17
17
|
const constants_1 = require("./constants");
|
|
18
|
-
const versions_1 = require("./versions");
|
|
19
18
|
const numberPrefix_1 = require("./numberPrefix");
|
|
20
19
|
const frontMatter_1 = require("./frontMatter");
|
|
21
20
|
const utils_2 = require("./sidebars/utils");
|
|
@@ -40,7 +39,7 @@ async function readLastUpdateData(filePath, options) {
|
|
|
40
39
|
return {};
|
|
41
40
|
}
|
|
42
41
|
async function readDocFile(versionMetadata, source, options) {
|
|
43
|
-
const contentPath = await (0, utils_1.getFolderContainingFile)((0,
|
|
42
|
+
const contentPath = await (0, utils_1.getFolderContainingFile)((0, utils_1.getContentPathList)(versionMetadata), source);
|
|
44
43
|
const filePath = path_1.default.join(contentPath, source);
|
|
45
44
|
const [content, lastUpdate] = await Promise.all([
|
|
46
45
|
fs_extra_1.default.readFile(filePath, 'utf-8'),
|
|
@@ -119,7 +118,7 @@ function doProcessDocMetadata({ docFile, versionMetadata, context, options, }) {
|
|
|
119
118
|
// contentTitle (because it can contain markdown/JSX syntax)
|
|
120
119
|
const title = frontMatter.title ?? contentTitle ?? baseID;
|
|
121
120
|
const description = frontMatter.description ?? excerpt ?? '';
|
|
122
|
-
const permalink = (0, utils_1.normalizeUrl)([versionMetadata.
|
|
121
|
+
const permalink = (0, utils_1.normalizeUrl)([versionMetadata.path, docSlug]);
|
|
123
122
|
function getDocEditUrl() {
|
|
124
123
|
const relativeFilePath = path_1.default.relative(contentPath, filePath);
|
|
125
124
|
if (typeof options.editUrl === 'function') {
|
|
@@ -134,8 +133,8 @@ function doProcessDocMetadata({ docFile, versionMetadata, context, options, }) {
|
|
|
134
133
|
else if (typeof options.editUrl === 'string') {
|
|
135
134
|
const isLocalized = contentPath === versionMetadata.contentPathLocalized;
|
|
136
135
|
const baseVersionEditUrl = isLocalized && options.editLocalizedFiles
|
|
137
|
-
? versionMetadata.
|
|
138
|
-
: versionMetadata.
|
|
136
|
+
? versionMetadata.editUrlLocalized
|
|
137
|
+
: versionMetadata.editUrl;
|
|
139
138
|
return (0, utils_1.getEditUrl)(relativeFilePath, baseVersionEditUrl);
|
|
140
139
|
}
|
|
141
140
|
return undefined;
|
package/lib/frontMatter.d.ts
CHANGED
|
@@ -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 { DocFrontMatter } from '
|
|
7
|
+
import type { DocFrontMatter } from '@docusaurus/plugin-content-docs';
|
|
8
8
|
export declare function validateDocFrontMatter(frontMatter: {
|
|
9
9
|
[key: string]: unknown;
|
|
10
10
|
}): DocFrontMatter;
|
package/lib/globalData.js
CHANGED
|
@@ -44,9 +44,9 @@ function toGlobalSidebars(sidebars, version) {
|
|
|
44
44
|
function toGlobalDataVersion(version) {
|
|
45
45
|
return {
|
|
46
46
|
name: version.versionName,
|
|
47
|
-
label: version.
|
|
47
|
+
label: version.label,
|
|
48
48
|
isLast: version.isLast,
|
|
49
|
-
path: version.
|
|
49
|
+
path: version.path,
|
|
50
50
|
mainDocId: version.mainDocId,
|
|
51
51
|
docs: version.docs
|
|
52
52
|
.map(toGlobalDataDoc)
|
package/lib/index.js
CHANGED
|
@@ -62,7 +62,7 @@ async function pluginContentDocs(context, options) {
|
|
|
62
62
|
getPathsToWatch() {
|
|
63
63
|
function getVersionPathsToWatch(version) {
|
|
64
64
|
const result = [
|
|
65
|
-
...options.include.flatMap((pattern) => (0,
|
|
65
|
+
...options.include.flatMap((pattern) => (0, utils_1.getContentPathList)(version).map((docsDirPath) => `${docsDirPath}/${pattern}`)),
|
|
66
66
|
`${version.contentPath}/**/${generator_1.CategoryMetadataFilenamePattern}`,
|
|
67
67
|
];
|
|
68
68
|
if (typeof version.sidebarFilePath === 'string') {
|
|
@@ -138,7 +138,7 @@ async function pluginContentDocs(context, options) {
|
|
|
138
138
|
// TODO tags should be a sub route of the version route
|
|
139
139
|
async function createTagsListPage() {
|
|
140
140
|
const tagsProp = Object.values(versionTags).map((tagValue) => ({
|
|
141
|
-
name: tagValue.
|
|
141
|
+
name: tagValue.label,
|
|
142
142
|
permalink: tagValue.permalink,
|
|
143
143
|
count: tagValue.docIds.length,
|
|
144
144
|
}));
|
|
@@ -211,7 +211,7 @@ async function pluginContentDocs(context, options) {
|
|
|
211
211
|
},
|
|
212
212
|
};
|
|
213
213
|
function createMDXLoaderRule() {
|
|
214
|
-
const contentDirs = versionsMetadata.flatMap(
|
|
214
|
+
const contentDirs = versionsMetadata.flatMap(utils_1.getContentPathList);
|
|
215
215
|
return {
|
|
216
216
|
test: /\.mdx?$/i,
|
|
217
217
|
include: contentDirs
|
package/lib/markdown/linkify.js
CHANGED
|
@@ -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,
|
|
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,8 +4,8 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import type { LoadedVersion, VersionTag
|
|
8
|
-
import type { PropSidebars, PropVersionMetadata, PropTagDocList } from '@docusaurus/plugin-content-docs';
|
|
7
|
+
import type { LoadedVersion, VersionTag } from './types';
|
|
8
|
+
import type { PropSidebars, PropVersionMetadata, PropTagDocList, DocMetadata } 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, }: {
|
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.
|
|
85
|
-
banner: loadedVersion.
|
|
86
|
-
badge: loadedVersion.
|
|
87
|
-
className: loadedVersion.
|
|
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,7 +104,7 @@ function toTagDocListProp({ allTagsPath, tag, docs, }) {
|
|
|
104
104
|
}));
|
|
105
105
|
}
|
|
106
106
|
return {
|
|
107
|
-
name: tag.
|
|
107
|
+
name: tag.label,
|
|
108
108
|
permalink: tag.permalink,
|
|
109
109
|
docs: toDocListProp(),
|
|
110
110
|
allTagsPath,
|
package/lib/routes.d.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
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 {
|
|
8
|
+
import type { LoadedVersion } from './types';
|
|
9
|
+
import type { DocMetadata } from '@docusaurus/plugin-content-docs';
|
|
9
10
|
export declare function createCategoryGeneratedIndexRoutes({ version, actions, docCategoryGeneratedIndexComponent, aliasedSource, }: {
|
|
10
11
|
version: LoadedVersion;
|
|
11
12
|
actions: PluginContentLoadedActions;
|
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,
|
|
18
|
-
const propFileName = slugs.slug(`${version.
|
|
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: {
|
|
@@ -86,7 +74,7 @@ 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.
|
|
77
|
+
path: version.path,
|
|
90
78
|
// allow matching /docs/* as well
|
|
91
79
|
exact: false,
|
|
92
80
|
// main docs component (DocPage)
|
|
@@ -104,7 +104,7 @@ Available doc IDs:
|
|
|
104
104
|
};
|
|
105
105
|
}
|
|
106
106
|
function createCategoryItem(dir, fullPath, folderName) {
|
|
107
|
-
const categoryMetadata = categoriesMetadata[
|
|
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)
|
|
@@ -15,7 +15,7 @@ function normalizeCategoryLink(category, params) {
|
|
|
15
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.
|
|
18
|
+
const permalink = (0, utils_1.normalizeUrl)([params.version.path, slug]);
|
|
19
19
|
return {
|
|
20
20
|
...category.link,
|
|
21
21
|
slug,
|
package/lib/sidebars/types.d.ts
CHANGED
|
@@ -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 '
|
|
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,17 +139,30 @@ 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
161
|
export declare type SidebarItemsGeneratorOptionArgs = {
|
|
162
|
+
/**
|
|
163
|
+
* Useful to re-use/enhance the default sidebar generation logic from
|
|
164
|
+
* Docusaurus.
|
|
165
|
+
*/
|
|
163
166
|
defaultSidebarItemsGenerator: SidebarItemsGenerator;
|
|
164
167
|
} & SidebarItemsGeneratorArgs;
|
|
165
168
|
export declare type SidebarItemsGeneratorOption = (generatorArgs: SidebarItemsGeneratorOptionArgs) => Promise<NormalizedSidebarItem[]>;
|
package/lib/sidebars/utils.d.ts
CHANGED
|
@@ -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,
|
|
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):
|
|
51
|
+
export declare function toDocNavigationLink(doc: DocMetadataBase): PropNavigationLink;
|
|
52
52
|
export declare function toNavigationLink(navigationItem: SidebarNavigationItem | undefined, docsById: {
|
|
53
53
|
[docId: string]: DocMetadataBase;
|
|
54
|
-
}):
|
|
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 '
|
|
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
|
|
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
|
-
|
|
16
|
+
label: group.tag.label,
|
|
17
17
|
docIds: group.items.map((item) => item.id),
|
|
18
18
|
permalink: group.tag.permalink,
|
|
19
19
|
}));
|
package/lib/translations.js
CHANGED
|
@@ -174,7 +174,7 @@ function translateSidebars(version, sidebarsTranslations) {
|
|
|
174
174
|
function getVersionTranslationFiles(version) {
|
|
175
175
|
const versionTranslations = {
|
|
176
176
|
'version.label': {
|
|
177
|
-
message: version.
|
|
177
|
+
message: version.label,
|
|
178
178
|
description: `The label for version ${version.versionName}`,
|
|
179
179
|
},
|
|
180
180
|
};
|
|
@@ -196,7 +196,7 @@ function translateVersion(version, translationFiles) {
|
|
|
196
196
|
const versionTranslations = translationFiles[getVersionFileName(version.versionName)].content;
|
|
197
197
|
return {
|
|
198
198
|
...version,
|
|
199
|
-
|
|
199
|
+
label: versionTranslations['version.label']?.message ?? version.label,
|
|
200
200
|
sidebars: translateSidebars(version, versionTranslations),
|
|
201
201
|
// docs: translateDocs(version.docs, versionTranslations),
|
|
202
202
|
};
|
package/lib/types.d.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { Sidebars } from './sidebars/types';
|
|
8
|
-
import type {
|
|
9
|
-
import type {
|
|
8
|
+
import type { BrokenMarkdownLink, Tag } from '@docusaurus/utils';
|
|
9
|
+
import type { VersionMetadata, LastUpdateData, DocMetadata, CategoryGeneratedIndexMetadata } from '@docusaurus/plugin-content-docs';
|
|
10
10
|
export declare type DocFile = {
|
|
11
11
|
contentPath: string;
|
|
12
12
|
filePath: string;
|
|
@@ -14,100 +14,17 @@ export declare type DocFile = {
|
|
|
14
14
|
content: string;
|
|
15
15
|
lastUpdate: LastUpdateData;
|
|
16
16
|
};
|
|
17
|
-
export declare type VersionMetadata = ContentPaths & {
|
|
18
|
-
versionName: string;
|
|
19
|
-
versionLabel: string;
|
|
20
|
-
versionPath: string;
|
|
21
|
-
tagsPath: string;
|
|
22
|
-
versionEditUrl?: string | undefined;
|
|
23
|
-
versionEditUrlLocalized?: string | undefined;
|
|
24
|
-
versionBanner: VersionBanner | null;
|
|
25
|
-
versionBadge: boolean;
|
|
26
|
-
versionClassName: string;
|
|
27
|
-
isLast: boolean;
|
|
28
|
-
sidebarFilePath: string | false | undefined;
|
|
29
|
-
routePriority: number | undefined;
|
|
30
|
-
};
|
|
31
|
-
export declare type LastUpdateData = {
|
|
32
|
-
lastUpdatedAt?: number;
|
|
33
|
-
formattedLastUpdatedAt?: string;
|
|
34
|
-
lastUpdatedBy?: string;
|
|
35
|
-
};
|
|
36
|
-
export declare type DocFrontMatter = {
|
|
37
|
-
id?: string;
|
|
38
|
-
title?: string;
|
|
39
|
-
tags?: FrontMatterTag[];
|
|
40
|
-
hide_title?: boolean;
|
|
41
|
-
hide_table_of_contents?: boolean;
|
|
42
|
-
keywords?: string[];
|
|
43
|
-
image?: string;
|
|
44
|
-
description?: string;
|
|
45
|
-
slug?: string;
|
|
46
|
-
sidebar_label?: string;
|
|
47
|
-
sidebar_position?: number;
|
|
48
|
-
sidebar_class_name?: string;
|
|
49
|
-
sidebar_custom_props?: {
|
|
50
|
-
[key: string]: unknown;
|
|
51
|
-
};
|
|
52
|
-
displayed_sidebar?: string | null;
|
|
53
|
-
pagination_label?: string;
|
|
54
|
-
custom_edit_url?: string | null;
|
|
55
|
-
parse_number_prefixes?: boolean;
|
|
56
|
-
toc_min_heading_level?: number;
|
|
57
|
-
toc_max_heading_level?: number;
|
|
58
|
-
pagination_next?: string | null;
|
|
59
|
-
pagination_prev?: string | null;
|
|
60
|
-
};
|
|
61
|
-
export declare type DocMetadataBase = LastUpdateData & {
|
|
62
|
-
id: string;
|
|
63
|
-
unversionedId: string;
|
|
64
|
-
version: string;
|
|
65
|
-
title: string;
|
|
66
|
-
description: string;
|
|
67
|
-
source: string;
|
|
68
|
-
sourceDirName: string;
|
|
69
|
-
slug: string;
|
|
70
|
-
permalink: string;
|
|
71
|
-
sidebarPosition?: number;
|
|
72
|
-
editUrl?: string | null;
|
|
73
|
-
tags: Tag[];
|
|
74
|
-
frontMatter: DocFrontMatter & {
|
|
75
|
-
[key: string]: unknown;
|
|
76
|
-
};
|
|
77
|
-
};
|
|
78
|
-
export declare type DocNavLink = {
|
|
79
|
-
title: string;
|
|
80
|
-
permalink: string;
|
|
81
|
-
};
|
|
82
|
-
export declare type DocMetadata = DocMetadataBase & {
|
|
83
|
-
sidebar?: string;
|
|
84
|
-
previous?: DocNavLink;
|
|
85
|
-
next?: DocNavLink;
|
|
86
|
-
};
|
|
87
|
-
export declare type CategoryGeneratedIndexMetadata = {
|
|
88
|
-
title: string;
|
|
89
|
-
description?: string;
|
|
90
|
-
slug: string;
|
|
91
|
-
permalink: string;
|
|
92
|
-
sidebar: string;
|
|
93
|
-
previous?: DocNavLink;
|
|
94
|
-
next?: DocNavLink;
|
|
95
|
-
image?: string;
|
|
96
|
-
keywords?: string | readonly string[];
|
|
97
|
-
};
|
|
98
17
|
export declare type SourceToPermalink = {
|
|
99
18
|
[source: string]: string;
|
|
100
19
|
};
|
|
101
|
-
export declare type VersionTag = {
|
|
102
|
-
|
|
20
|
+
export declare type VersionTag = Tag & {
|
|
21
|
+
/** all doc ids having this tag. */
|
|
103
22
|
docIds: string[];
|
|
104
|
-
permalink: string;
|
|
105
23
|
};
|
|
106
24
|
export declare type VersionTags = {
|
|
107
25
|
[key: string]: VersionTag;
|
|
108
26
|
};
|
|
109
27
|
export declare type LoadedVersion = VersionMetadata & {
|
|
110
|
-
versionPath: string;
|
|
111
28
|
mainDocId: string;
|
|
112
29
|
docs: DocMetadata[];
|
|
113
30
|
sidebars: Sidebars;
|
package/lib/versions.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 { VersionMetadata } from '
|
|
8
|
-
import type { PluginOptions, VersionBanner } from '@docusaurus/plugin-content-docs';
|
|
7
|
+
import type { PluginOptions, VersionBanner, VersionMetadata } from '@docusaurus/plugin-content-docs';
|
|
9
8
|
import type { LoadContext } from '@docusaurus/types';
|
|
10
9
|
export declare function getVersionedDocsDirPath(siteDir: string, pluginId: string): string;
|
|
11
10
|
export declare function getVersionedSidebarsDirPath(siteDir: string, pluginId: string): string;
|
|
@@ -38,4 +37,3 @@ export declare function readVersionsMetadata({ context, options, }: {
|
|
|
38
37
|
context: Pick<LoadContext, 'siteDir' | 'baseUrl' | 'i18n'>;
|
|
39
38
|
options: Pick<PluginOptions, 'id' | 'path' | 'sidebarPath' | 'routeBasePath' | 'tagsBasePath' | 'includeCurrentVersion' | 'disableVersioning' | 'lastVersion' | 'versions' | 'onlyIncludeVersions' | 'editUrl' | 'editCurrentVersion'>;
|
|
40
39
|
}): Promise<VersionMetadata[]>;
|
|
41
|
-
export declare function getDocsDirPaths(versionMetadata: Pick<VersionMetadata, 'contentPath' | 'contentPathLocalized'>): [string, string];
|
package/lib/versions.js
CHANGED
|
@@ -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.
|
|
9
|
+
exports.readVersionsMetadata = exports.filterVersions = exports.getVersionBadge = exports.getVersionBanner = exports.getDefaultVersionBanner = exports.readVersionNames = exports.readVersionsFile = exports.getVersionsFilePath = exports.getVersionedSidebarsDirPath = exports.getVersionedDocsDirPath = 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"));
|
|
@@ -110,14 +110,11 @@ function getVersionMetadataPaths({ versionName, context, options, }) {
|
|
|
110
110
|
sidebarFilePath: path_1.default.join(getVersionedSidebarsDirPath(context.siteDir, options.id), `version-${versionName}-sidebars.json`),
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
|
-
function getVersionEditUrls({ contentPath, contentPathLocalized, context: { siteDir, i18n }, options: { id, path: currentVersionPath, editUrl, editCurrentVersion }, }) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
// he has total freedom and we can't compute a "version edit url"
|
|
119
|
-
if (typeof editUrl === 'function') {
|
|
120
|
-
return undefined;
|
|
113
|
+
function getVersionEditUrls({ contentPath, contentPathLocalized, context: { siteDir, i18n }, options: { id, path: currentVersionPath, editUrl: editUrlOption, editCurrentVersion, }, }) {
|
|
114
|
+
// If the user is using the functional form of editUrl,
|
|
115
|
+
// she has total freedom and we can't compute a "version edit url"
|
|
116
|
+
if (!editUrlOption || typeof editUrlOption === 'function') {
|
|
117
|
+
return { editUrl: undefined, editUrlLocalized: undefined };
|
|
121
118
|
}
|
|
122
119
|
const editDirPath = editCurrentVersion ? currentVersionPath : contentPath;
|
|
123
120
|
const editDirPathLocalized = editCurrentVersion
|
|
@@ -130,14 +127,14 @@ function getVersionEditUrls({ contentPath, contentPathLocalized, context: { site
|
|
|
130
127
|
: contentPathLocalized;
|
|
131
128
|
const versionPathSegment = (0, utils_1.posixPath)(path_1.default.relative(siteDir, path_1.default.resolve(siteDir, editDirPath)));
|
|
132
129
|
const versionPathSegmentLocalized = (0, utils_1.posixPath)(path_1.default.relative(siteDir, path_1.default.resolve(siteDir, editDirPathLocalized)));
|
|
133
|
-
const
|
|
134
|
-
const
|
|
135
|
-
|
|
130
|
+
const editUrl = (0, utils_1.normalizeUrl)([editUrlOption, versionPathSegment]);
|
|
131
|
+
const editUrlLocalized = (0, utils_1.normalizeUrl)([
|
|
132
|
+
editUrlOption,
|
|
136
133
|
versionPathSegmentLocalized,
|
|
137
134
|
]);
|
|
138
135
|
return {
|
|
139
|
-
|
|
140
|
-
|
|
136
|
+
editUrl,
|
|
137
|
+
editUrlLocalized,
|
|
141
138
|
};
|
|
142
139
|
}
|
|
143
140
|
function getDefaultVersionBanner({ versionName, versionNames, lastVersionName, }) {
|
|
@@ -192,9 +189,9 @@ function createVersionMetadata({ versionName, versionNames, lastVersionName, con
|
|
|
192
189
|
}
|
|
193
190
|
const defaultVersionPathPart = getDefaultVersionPathPart();
|
|
194
191
|
const versionOptions = options.versions[versionName] ?? {};
|
|
195
|
-
const
|
|
192
|
+
const label = versionOptions.label ?? defaultVersionLabel;
|
|
196
193
|
const versionPathPart = versionOptions.path ?? defaultVersionPathPart;
|
|
197
|
-
const
|
|
194
|
+
const routePath = (0, utils_1.normalizeUrl)([
|
|
198
195
|
context.baseUrl,
|
|
199
196
|
options.routeBasePath,
|
|
200
197
|
versionPathPart,
|
|
@@ -205,26 +202,25 @@ function createVersionMetadata({ versionName, versionNames, lastVersionName, con
|
|
|
205
202
|
context,
|
|
206
203
|
options,
|
|
207
204
|
});
|
|
208
|
-
// Because /docs/:route` should always be after `/docs/versionName/:route`.
|
|
209
205
|
const routePriority = versionPathPart === '' ? -1 : undefined;
|
|
210
206
|
// the path that will be used to refer the docs tags
|
|
211
207
|
// example below will be using /docs/tags
|
|
212
|
-
const tagsPath = (0, utils_1.normalizeUrl)([
|
|
208
|
+
const tagsPath = (0, utils_1.normalizeUrl)([routePath, options.tagsBasePath]);
|
|
213
209
|
return {
|
|
214
210
|
versionName,
|
|
215
|
-
|
|
216
|
-
|
|
211
|
+
label,
|
|
212
|
+
path: routePath,
|
|
217
213
|
tagsPath,
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
214
|
+
editUrl: versionEditUrls.editUrl,
|
|
215
|
+
editUrlLocalized: versionEditUrls.editUrlLocalized,
|
|
216
|
+
banner: getVersionBanner({
|
|
221
217
|
versionName,
|
|
222
218
|
versionNames,
|
|
223
219
|
lastVersionName,
|
|
224
220
|
options,
|
|
225
221
|
}),
|
|
226
|
-
|
|
227
|
-
|
|
222
|
+
badge: getVersionBadge({ versionName, versionNames, options }),
|
|
223
|
+
className: getVersionClassName({ versionName, options }),
|
|
228
224
|
isLast,
|
|
229
225
|
routePriority,
|
|
230
226
|
sidebarFilePath,
|
|
@@ -315,10 +311,3 @@ async function readVersionsMetadata({ context, options, }) {
|
|
|
315
311
|
return versionsMetadata;
|
|
316
312
|
}
|
|
317
313
|
exports.readVersionsMetadata = readVersionsMetadata;
|
|
318
|
-
// order matter!
|
|
319
|
-
// Read in priority the localized path, then the unlocalized one
|
|
320
|
-
// We want the localized doc to "override" the unlocalized one
|
|
321
|
-
function getDocsDirPaths(versionMetadata) {
|
|
322
|
-
return [versionMetadata.contentPathLocalized, versionMetadata.contentPath];
|
|
323
|
-
}
|
|
324
|
-
exports.getDocsDirPaths = getDocsDirPaths;
|