@docusaurus/plugin-content-docs 2.0.0-beta.1 → 2.0.0-beta.10
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/.tsbuildinfo +1 -1
- package/lib/categoryGeneratedIndex.d.ts +12 -0
- package/lib/categoryGeneratedIndex.js +37 -0
- package/lib/cli.d.ts +2 -2
- package/lib/cli.js +12 -34
- package/lib/client/docsClientUtils.d.ts +1 -4
- package/lib/client/docsClientUtils.js +21 -31
- package/lib/docFrontMatter.d.ts +1 -1
- package/lib/docFrontMatter.js +10 -6
- package/lib/docs.d.ts +25 -3
- package/lib/docs.js +125 -38
- package/lib/globalData.d.ts +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +104 -138
- package/lib/lastUpdate.js +9 -10
- package/lib/markdown/index.d.ts +3 -6
- package/lib/markdown/index.js +3 -3
- package/lib/markdown/linkify.js +2 -2
- package/lib/numberPrefix.d.ts +1 -1
- package/lib/options.d.ts +3 -3
- package/lib/options.js +49 -17
- package/lib/props.d.ts +7 -2
- package/lib/props.js +61 -9
- package/lib/routes.d.ts +27 -0
- package/lib/routes.js +105 -0
- package/lib/{sidebarItemsGenerator.d.ts → sidebars/generator.d.ts} +5 -2
- package/lib/sidebars/generator.js +216 -0
- package/lib/sidebars/index.d.ts +15 -0
- package/lib/sidebars/index.js +73 -0
- package/lib/sidebars/normalization.d.ts +14 -0
- package/lib/sidebars/normalization.js +77 -0
- package/lib/sidebars/processor.d.ts +18 -0
- package/lib/sidebars/processor.js +85 -0
- package/lib/sidebars/types.d.ts +127 -0
- package/lib/sidebars/types.js +8 -0
- package/lib/sidebars/utils.d.ts +35 -0
- package/lib/sidebars/utils.js +228 -0
- package/lib/sidebars/validation.d.ts +10 -0
- package/lib/sidebars/validation.js +138 -0
- package/lib/slug.d.ts +4 -3
- package/lib/slug.js +27 -15
- package/lib/tags.d.ts +8 -0
- package/lib/tags.js +20 -0
- package/lib/theme/hooks/useDocs.js +24 -21
- package/lib/translations.d.ts +2 -2
- package/lib/translations.js +71 -29
- package/lib/types.d.ts +52 -62
- package/lib/versions.d.ts +3 -3
- package/lib/versions.js +76 -24
- package/package.json +22 -20
- package/src/__tests__/__fixtures__/simple-site/docs/_partials/somePartial.md +3 -0
- package/src/__tests__/__fixtures__/simple-site/docs/_partials/subfolder/somePartial.md +3 -0
- package/src/__tests__/__fixtures__/simple-site/docs/_somePartial.md +3 -0
- package/src/__tests__/__fixtures__/simple-site/docs/foo/baz.md +5 -0
- package/src/__tests__/__fixtures__/simple-site/docs/hello.md +2 -0
- package/src/__tests__/__fixtures__/simple-site/docs/rootAbsoluteSlug.md +2 -0
- package/src/__tests__/__fixtures__/simple-site/docs/rootRelativeSlug.md +2 -0
- package/src/__tests__/__fixtures__/simple-site/docs/rootResolvedSlug.md +2 -0
- package/src/__tests__/__fixtures__/simple-site/docs/rootTryToEscapeSlug.md +2 -0
- package/src/__tests__/__fixtures__/simple-site/sidebars.json +15 -1
- package/src/__tests__/__fixtures__/site-with-doc-label/docs/hello-1.md +1 -0
- package/src/__tests__/__fixtures__/versioned-site/docs/foo/bar.md +6 -0
- package/src/__tests__/__fixtures__/versioned-site/docs/hello.md +3 -0
- package/src/__tests__/__fixtures__/versioned-site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md +3 -0
- package/src/__tests__/__fixtures__/versioned-site/i18n/fr/docusaurus-plugin-content-docs/version-1.0.0/hello.md +3 -0
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/hello.md +3 -0
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_partials/somePartial.md +3 -0
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_partials/subfolder/somePartial.md +3 -0
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_somePartial.md +3 -0
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/hello.md +3 -0
- package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-1.0.1-sidebars.json +2 -2
- package/src/__tests__/__snapshots__/cli.test.ts.snap +48 -73
- package/src/__tests__/__snapshots__/docs.test.ts.snap +140 -0
- package/src/__tests__/__snapshots__/index.test.ts.snap +753 -112
- package/src/__tests__/__snapshots__/translations.test.ts.snap +45 -18
- package/src/__tests__/cli.test.ts +15 -11
- package/src/__tests__/docFrontMatter.test.ts +195 -40
- package/src/__tests__/docs.test.ts +311 -150
- package/src/__tests__/index.test.ts +112 -69
- package/src/__tests__/lastUpdate.test.ts +3 -2
- package/src/__tests__/options.test.ts +48 -4
- package/src/__tests__/props.test.ts +62 -0
- package/src/__tests__/slug.test.ts +127 -20
- package/src/__tests__/translations.test.ts +7 -2
- package/src/__tests__/versions.test.ts +93 -67
- package/src/categoryGeneratedIndex.ts +57 -0
- package/src/cli.ts +8 -41
- package/src/client/__tests__/docsClientUtils.test.ts +4 -5
- package/src/client/docsClientUtils.ts +19 -41
- package/{types.d.ts → src/deps.d.ts} +0 -0
- package/src/docFrontMatter.ts +13 -7
- package/src/docs.ts +158 -29
- package/src/globalData.ts +6 -1
- package/src/index.ts +134 -179
- package/src/lastUpdate.ts +10 -9
- package/src/markdown/index.ts +8 -12
- package/src/numberPrefix.ts +5 -3
- package/src/options.ts +59 -28
- package/src/plugin-content-docs.d.ts +179 -35
- package/src/props.ts +91 -16
- package/src/routes.ts +173 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-shorthand.js +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-wrong-items.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-wrong-label.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category.js +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-collapsed-first-level.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-collapsed.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-doc-id-not-string.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-first-level-not-category.js +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link-wrong-href.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link-wrong-label.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-unknown-type.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-wrong-field.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars.json +0 -0
- package/src/{__tests__/__snapshots__/sidebars.test.ts.snap → sidebars/__tests__/__snapshots__/index.test.ts.snap} +36 -6
- package/src/{__tests__/sidebarItemsGenerator.test.ts → sidebars/__tests__/generator.test.ts} +143 -18
- package/src/sidebars/__tests__/index.test.ts +204 -0
- package/src/sidebars/__tests__/processor.test.ts +237 -0
- package/src/sidebars/__tests__/utils.test.ts +695 -0
- package/src/sidebars/__tests__/validation.test.ts +105 -0
- package/src/sidebars/generator.ts +310 -0
- package/src/sidebars/index.ts +94 -0
- package/src/sidebars/normalization.ts +112 -0
- package/src/sidebars/processor.ts +154 -0
- package/src/sidebars/types.ts +211 -0
- package/src/sidebars/utils.ts +329 -0
- package/src/sidebars/validation.ts +168 -0
- package/src/slug.ts +32 -17
- package/src/tags.ts +19 -0
- package/src/theme/hooks/useDocs.ts +5 -1
- package/src/translations.ts +103 -47
- package/src/types.ts +67 -105
- package/src/versions.ts +117 -21
- package/lib/sidebarItemsGenerator.js +0 -211
- package/lib/sidebars.d.ts +0 -43
- package/lib/sidebars.js +0 -319
- package/src/__tests__/sidebars.test.ts +0 -639
- package/src/sidebarItemsGenerator.ts +0 -307
- package/src/sidebars.ts +0 -506
|
@@ -8,14 +8,15 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.getDocVersionSuggestions = exports.getActiveDocContext = exports.getActiveVersion = exports.getLatestVersion = exports.getActivePlugin = void 0;
|
|
10
10
|
const router_1 = require("@docusaurus/router");
|
|
11
|
+
// get the data of the plugin that is currently "active"
|
|
12
|
+
// ie the docs of that plugin are currently browsed
|
|
13
|
+
// it is useful to support multiple docs plugin instances
|
|
11
14
|
function getActivePlugin(allPluginDatas, pathname, options = {}) {
|
|
12
|
-
const activeEntry = Object.entries(allPluginDatas).find(([_id, pluginData]) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
});
|
|
18
|
-
});
|
|
15
|
+
const activeEntry = Object.entries(allPluginDatas).find(([_id, pluginData]) => !!(0, router_1.matchPath)(pathname, {
|
|
16
|
+
path: pluginData.path,
|
|
17
|
+
exact: false,
|
|
18
|
+
strict: false,
|
|
19
|
+
}));
|
|
19
20
|
const activePlugin = activeEntry
|
|
20
21
|
? { pluginId: activeEntry[0], pluginData: activeEntry[1] }
|
|
21
22
|
: undefined;
|
|
@@ -27,32 +28,28 @@ function getActivePlugin(allPluginDatas, pathname, options = {}) {
|
|
|
27
28
|
return activePlugin;
|
|
28
29
|
}
|
|
29
30
|
exports.getActivePlugin = getActivePlugin;
|
|
30
|
-
const getLatestVersion = (data) =>
|
|
31
|
-
return data.versions.find((version) => version.isLast);
|
|
32
|
-
};
|
|
31
|
+
const getLatestVersion = (data) => data.versions.find((version) => version.isLast);
|
|
33
32
|
exports.getLatestVersion = getLatestVersion;
|
|
34
33
|
// Note: return undefined on doc-unrelated pages,
|
|
35
34
|
// because there's no version currently considered as active
|
|
36
35
|
const getActiveVersion = (data, pathname) => {
|
|
37
|
-
const lastVersion = exports.getLatestVersion(data);
|
|
36
|
+
const lastVersion = (0, exports.getLatestVersion)(data);
|
|
38
37
|
// Last version is a route like /docs/*,
|
|
39
38
|
// we need to try to match it last or it would match /docs/version-1.0/* as well
|
|
40
39
|
const orderedVersionsMetadata = [
|
|
41
40
|
...data.versions.filter((version) => version !== lastVersion),
|
|
42
41
|
lastVersion,
|
|
43
42
|
];
|
|
44
|
-
return orderedVersionsMetadata.find((version) => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
});
|
|
50
|
-
});
|
|
43
|
+
return orderedVersionsMetadata.find((version) => !!(0, router_1.matchPath)(pathname, {
|
|
44
|
+
path: version.path,
|
|
45
|
+
exact: false,
|
|
46
|
+
strict: false,
|
|
47
|
+
}));
|
|
51
48
|
};
|
|
52
49
|
exports.getActiveVersion = getActiveVersion;
|
|
53
50
|
const getActiveDocContext = (data, pathname) => {
|
|
54
|
-
const activeVersion = exports.getActiveVersion(data, pathname);
|
|
55
|
-
const activeDoc = activeVersion === null || activeVersion === void 0 ? void 0 : activeVersion.docs.find((doc) => !!router_1.matchPath(pathname, {
|
|
51
|
+
const activeVersion = (0, exports.getActiveVersion)(data, pathname);
|
|
52
|
+
const activeDoc = activeVersion === null || activeVersion === void 0 ? void 0 : activeVersion.docs.find((doc) => !!(0, router_1.matchPath)(pathname, {
|
|
56
53
|
path: doc.path,
|
|
57
54
|
exact: true,
|
|
58
55
|
strict: false,
|
|
@@ -79,16 +76,9 @@ const getActiveDocContext = (data, pathname) => {
|
|
|
79
76
|
};
|
|
80
77
|
exports.getActiveDocContext = getActiveDocContext;
|
|
81
78
|
const getDocVersionSuggestions = (data, pathname) => {
|
|
82
|
-
const latestVersion = exports.getLatestVersion(data);
|
|
83
|
-
const activeDocContext = exports.getActiveDocContext(data, pathname);
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const latestDocSuggestion = isNotOnLatestVersion
|
|
87
|
-
? activeDocContext === null || activeDocContext === void 0 ? void 0 : activeDocContext.alternateDocVersions[latestVersion.name]
|
|
88
|
-
: undefined;
|
|
89
|
-
const latestVersionSuggestion = isNotOnLatestVersion
|
|
90
|
-
? latestVersion
|
|
91
|
-
: undefined;
|
|
92
|
-
return { latestDocSuggestion, latestVersionSuggestion };
|
|
79
|
+
const latestVersion = (0, exports.getLatestVersion)(data);
|
|
80
|
+
const activeDocContext = (0, exports.getActiveDocContext)(data, pathname);
|
|
81
|
+
const latestDocSuggestion = activeDocContext === null || activeDocContext === void 0 ? void 0 : activeDocContext.alternateDocVersions[latestVersion.name];
|
|
82
|
+
return { latestDocSuggestion, latestVersionSuggestion: latestVersion };
|
|
93
83
|
};
|
|
94
84
|
exports.getDocVersionSuggestions = getDocVersionSuggestions;
|
package/lib/docFrontMatter.d.ts
CHANGED
|
@@ -4,5 +4,5 @@
|
|
|
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 { DocFrontMatter } from './types';
|
|
7
|
+
import type { DocFrontMatter } from './types';
|
|
8
8
|
export declare function validateDocFrontMatter(frontMatter: Record<string, unknown>): DocFrontMatter;
|
package/lib/docFrontMatter.js
CHANGED
|
@@ -7,10 +7,9 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.validateDocFrontMatter = void 0;
|
|
10
|
-
/* eslint-disable camelcase */
|
|
11
10
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
12
11
|
// NOTE: we don't add any default value on purpose here
|
|
13
|
-
// We don't want default values to magically appear in doc
|
|
12
|
+
// We don't want default values to magically appear in doc metadata and props
|
|
14
13
|
// While the user did not provide those values explicitly
|
|
15
14
|
// We use default values in code instead
|
|
16
15
|
const DocFrontMatterSchema = utils_validation_1.JoiFrontMatter.object({
|
|
@@ -19,16 +18,21 @@ const DocFrontMatterSchema = utils_validation_1.JoiFrontMatter.object({
|
|
|
19
18
|
hide_title: utils_validation_1.JoiFrontMatter.boolean(),
|
|
20
19
|
hide_table_of_contents: utils_validation_1.JoiFrontMatter.boolean(),
|
|
21
20
|
keywords: utils_validation_1.JoiFrontMatter.array().items(utils_validation_1.JoiFrontMatter.string().required()),
|
|
22
|
-
image: utils_validation_1.
|
|
21
|
+
image: utils_validation_1.URISchema,
|
|
23
22
|
description: utils_validation_1.JoiFrontMatter.string().allow(''),
|
|
24
23
|
slug: utils_validation_1.JoiFrontMatter.string(),
|
|
25
24
|
sidebar_label: utils_validation_1.JoiFrontMatter.string(),
|
|
26
|
-
sidebar_position: utils_validation_1.JoiFrontMatter.number()
|
|
25
|
+
sidebar_position: utils_validation_1.JoiFrontMatter.number(),
|
|
26
|
+
sidebar_class_name: utils_validation_1.JoiFrontMatter.string(),
|
|
27
|
+
tags: utils_validation_1.FrontMatterTagsSchema,
|
|
27
28
|
pagination_label: utils_validation_1.JoiFrontMatter.string(),
|
|
28
|
-
custom_edit_url: utils_validation_1.
|
|
29
|
+
custom_edit_url: utils_validation_1.URISchema.allow('', null),
|
|
29
30
|
parse_number_prefixes: utils_validation_1.JoiFrontMatter.boolean(),
|
|
31
|
+
pagination_next: utils_validation_1.JoiFrontMatter.string().allow(null),
|
|
32
|
+
pagination_prev: utils_validation_1.JoiFrontMatter.string().allow(null),
|
|
33
|
+
...utils_validation_1.FrontMatterTOCHeadingLevels,
|
|
30
34
|
}).unknown();
|
|
31
35
|
function validateDocFrontMatter(frontMatter) {
|
|
32
|
-
return utils_validation_1.validateFrontMatter(frontMatter, DocFrontMatterSchema);
|
|
36
|
+
return (0, utils_validation_1.validateFrontMatter)(frontMatter, DocFrontMatterSchema);
|
|
33
37
|
}
|
|
34
38
|
exports.validateDocFrontMatter = validateDocFrontMatter;
|
package/lib/docs.d.ts
CHANGED
|
@@ -4,15 +4,37 @@
|
|
|
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 { LoadContext } from '@docusaurus/types';
|
|
8
|
-
import { DocFile, DocMetadataBase, MetadataOptions, PluginOptions, VersionMetadata } from './types';
|
|
7
|
+
import type { LoadContext } from '@docusaurus/types';
|
|
8
|
+
import { DocFile, DocMetadataBase, MetadataOptions, PluginOptions, VersionMetadata, LoadedVersion } from './types';
|
|
9
|
+
import { SidebarsUtils } from './sidebars/utils';
|
|
9
10
|
declare type LastUpdateOptions = Pick<PluginOptions, 'showLastUpdateAuthor' | 'showLastUpdateTime'>;
|
|
10
11
|
export declare function readDocFile(versionMetadata: Pick<VersionMetadata, 'contentPath' | 'contentPathLocalized'>, source: string, options: LastUpdateOptions): Promise<DocFile>;
|
|
11
|
-
export declare function readVersionDocs(versionMetadata: VersionMetadata, options: Pick<PluginOptions, 'include' | 'showLastUpdateAuthor' | 'showLastUpdateTime'>): Promise<DocFile[]>;
|
|
12
|
+
export declare function readVersionDocs(versionMetadata: VersionMetadata, options: Pick<PluginOptions, 'include' | 'exclude' | 'showLastUpdateAuthor' | 'showLastUpdateTime'>): Promise<DocFile[]>;
|
|
12
13
|
export declare function processDocMetadata(args: {
|
|
13
14
|
docFile: DocFile;
|
|
14
15
|
versionMetadata: VersionMetadata;
|
|
15
16
|
context: LoadContext;
|
|
16
17
|
options: MetadataOptions;
|
|
17
18
|
}): DocMetadataBase;
|
|
19
|
+
export declare function addDocNavigation(docsBase: DocMetadataBase[], sidebarsUtils: SidebarsUtils, sidebarFilePath: string): LoadedVersion['docs'];
|
|
20
|
+
/**
|
|
21
|
+
* The "main doc" is the "version entry point"
|
|
22
|
+
* We browse this doc by clicking on a version:
|
|
23
|
+
* - the "home" doc (at '/docs/')
|
|
24
|
+
* - the first doc of the first sidebar
|
|
25
|
+
* - a random doc (if no docs are in any sidebar... edge case)
|
|
26
|
+
*/
|
|
27
|
+
export declare function getMainDocId({ docs, sidebarsUtils, }: {
|
|
28
|
+
docs: DocMetadataBase[];
|
|
29
|
+
sidebarsUtils: SidebarsUtils;
|
|
30
|
+
}): string;
|
|
31
|
+
export declare function isConventionalDocIndex(doc: {
|
|
32
|
+
source: DocMetadataBase['slug'];
|
|
33
|
+
sourceDirName: DocMetadataBase['sourceDirName'];
|
|
34
|
+
}): boolean;
|
|
35
|
+
export declare function getDocIds(doc: DocMetadataBase): [string, string];
|
|
36
|
+
export declare function createDocsByIdIndex<Doc extends {
|
|
37
|
+
id: string;
|
|
38
|
+
unversionedId: string;
|
|
39
|
+
}>(docs: Doc[]): Record<string, Doc>;
|
|
18
40
|
export {};
|
package/lib/docs.js
CHANGED
|
@@ -6,25 +6,26 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.processDocMetadata = exports.readVersionDocs = exports.readDocFile = void 0;
|
|
9
|
+
exports.createDocsByIdIndex = exports.getDocIds = exports.isConventionalDocIndex = exports.getMainDocId = exports.addDocNavigation = exports.processDocMetadata = exports.readVersionDocs = exports.readDocFile = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
|
-
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
11
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
12
|
+
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
13
|
+
const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
|
|
14
|
+
const lodash_1 = require("lodash");
|
|
13
15
|
const utils_1 = require("@docusaurus/utils");
|
|
14
16
|
const lastUpdate_1 = require("./lastUpdate");
|
|
15
|
-
const slug_1 = tslib_1.__importDefault(require("./slug"));
|
|
17
|
+
const slug_1 = (0, tslib_1.__importDefault)(require("./slug"));
|
|
16
18
|
const constants_1 = require("./constants");
|
|
17
|
-
const globby_1 = tslib_1.__importDefault(require("globby"));
|
|
18
19
|
const versions_1 = require("./versions");
|
|
19
20
|
const numberPrefix_1 = require("./numberPrefix");
|
|
20
21
|
const docFrontMatter_1 = require("./docFrontMatter");
|
|
21
|
-
const
|
|
22
|
+
const utils_2 = require("./sidebars/utils");
|
|
22
23
|
async function readLastUpdateData(filePath, options) {
|
|
23
24
|
const { showLastUpdateAuthor, showLastUpdateTime } = options;
|
|
24
25
|
if (showLastUpdateAuthor || showLastUpdateTime) {
|
|
25
26
|
// Use fake data in dev for faster development.
|
|
26
27
|
const fileLastUpdateData = process.env.NODE_ENV === 'production'
|
|
27
|
-
? await lastUpdate_1.getFileLastUpdate(filePath)
|
|
28
|
+
? await (0, lastUpdate_1.getFileLastUpdate)(filePath)
|
|
28
29
|
: {
|
|
29
30
|
author: 'Author',
|
|
30
31
|
timestamp: 1539502055,
|
|
@@ -40,7 +41,7 @@ async function readLastUpdateData(filePath, options) {
|
|
|
40
41
|
return {};
|
|
41
42
|
}
|
|
42
43
|
async function readDocFile(versionMetadata, source, options) {
|
|
43
|
-
const contentPath = await utils_1.getFolderContainingFile(versions_1.getDocsDirPaths(versionMetadata), source);
|
|
44
|
+
const contentPath = await (0, utils_1.getFolderContainingFile)((0, versions_1.getDocsDirPaths)(versionMetadata), source);
|
|
44
45
|
const filePath = path_1.default.join(contentPath, source);
|
|
45
46
|
const [content, lastUpdate] = await Promise.all([
|
|
46
47
|
fs_extra_1.default.readFile(filePath, 'utf-8'),
|
|
@@ -50,8 +51,9 @@ async function readDocFile(versionMetadata, source, options) {
|
|
|
50
51
|
}
|
|
51
52
|
exports.readDocFile = readDocFile;
|
|
52
53
|
async function readVersionDocs(versionMetadata, options) {
|
|
53
|
-
const sources = await
|
|
54
|
+
const sources = await (0, utils_1.Globby)(options.include, {
|
|
54
55
|
cwd: versionMetadata.contentPath,
|
|
56
|
+
ignore: options.exclude,
|
|
55
57
|
});
|
|
56
58
|
return Promise.all(sources.map((source) => readDocFile(versionMetadata, source, options)));
|
|
57
59
|
}
|
|
@@ -59,21 +61,20 @@ exports.readVersionDocs = readVersionDocs;
|
|
|
59
61
|
function doProcessDocMetadata({ docFile, versionMetadata, context, options, }) {
|
|
60
62
|
var _a, _b, _c, _d, _e, _f;
|
|
61
63
|
const { source, content, lastUpdate, contentPath, filePath } = docFile;
|
|
62
|
-
const { homePageId } = options;
|
|
63
64
|
const { siteDir, i18n } = context;
|
|
64
|
-
const { frontMatter: unsafeFrontMatter, contentTitle, excerpt, } = utils_1.parseMarkdownString(content);
|
|
65
|
-
const frontMatter = docFrontMatter_1.validateDocFrontMatter(unsafeFrontMatter);
|
|
65
|
+
const { frontMatter: unsafeFrontMatter, contentTitle, excerpt, } = (0, utils_1.parseMarkdownString)(content);
|
|
66
|
+
const frontMatter = (0, docFrontMatter_1.validateDocFrontMatter)(unsafeFrontMatter);
|
|
66
67
|
const { custom_edit_url: customEditURL,
|
|
67
68
|
// Strip number prefixes by default (01-MyFolder/01-MyDoc.md => MyFolder/MyDoc) by default,
|
|
68
|
-
// but allow to disable this behavior with
|
|
69
|
-
parse_number_prefixes = true, } = frontMatter;
|
|
69
|
+
// but allow to disable this behavior with frontmatter
|
|
70
|
+
parse_number_prefixes: parseNumberPrefixes = true, } = frontMatter;
|
|
70
71
|
// ex: api/plugins/myDoc -> myDoc
|
|
71
72
|
// ex: myDoc -> myDoc
|
|
72
73
|
const sourceFileNameWithoutExtension = path_1.default.basename(source, path_1.default.extname(source));
|
|
73
74
|
// ex: api/plugins/myDoc -> api/plugins
|
|
74
75
|
// ex: myDoc -> .
|
|
75
76
|
const sourceDirName = path_1.default.dirname(source);
|
|
76
|
-
const { filename: unprefixedFileName, numberPrefix } =
|
|
77
|
+
const { filename: unprefixedFileName, numberPrefix } = parseNumberPrefixes
|
|
77
78
|
? options.numberPrefixParser(sourceFileNameWithoutExtension)
|
|
78
79
|
: { filename: sourceFileNameWithoutExtension, numberPrefix: undefined };
|
|
79
80
|
const baseID = (_a = frontMatter.id) !== null && _a !== void 0 ? _a : unprefixedFileName;
|
|
@@ -95,8 +96,8 @@ function doProcessDocMetadata({ docFile, versionMetadata, context, options, }) {
|
|
|
95
96
|
return undefined;
|
|
96
97
|
}
|
|
97
98
|
// Eventually remove the number prefixes from intermediate directories
|
|
98
|
-
return
|
|
99
|
-
? numberPrefix_1.stripPathNumberPrefixes(sourceDirName, options.numberPrefixParser)
|
|
99
|
+
return parseNumberPrefixes
|
|
100
|
+
? (0, numberPrefix_1.stripPathNumberPrefixes)(sourceDirName, options.numberPrefixParser)
|
|
100
101
|
: sourceDirName;
|
|
101
102
|
}
|
|
102
103
|
const unversionedId = [computeDirNameIdPrefix(), baseID]
|
|
@@ -105,32 +106,26 @@ function doProcessDocMetadata({ docFile, versionMetadata, context, options, }) {
|
|
|
105
106
|
// TODO is versioning the id very useful in practice?
|
|
106
107
|
// legacy versioned id, requires a breaking change to modify this
|
|
107
108
|
const id = [versionIdPrefix, unversionedId].filter(Boolean).join('/');
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
baseID,
|
|
117
|
-
dirName: sourceDirName,
|
|
118
|
-
frontmatterSlug: frontMatter.slug,
|
|
119
|
-
stripDirNumberPrefixes: parse_number_prefixes,
|
|
120
|
-
numberPrefixParser: options.numberPrefixParser,
|
|
121
|
-
});
|
|
109
|
+
const docSlug = (0, slug_1.default)({
|
|
110
|
+
baseID,
|
|
111
|
+
source,
|
|
112
|
+
sourceDirName,
|
|
113
|
+
frontmatterSlug: frontMatter.slug,
|
|
114
|
+
stripDirNumberPrefixes: parseNumberPrefixes,
|
|
115
|
+
numberPrefixParser: options.numberPrefixParser,
|
|
116
|
+
});
|
|
122
117
|
// Note: the title is used by default for page title, sidebar label, pagination buttons...
|
|
123
118
|
// frontMatter.title should be used in priority over contentTitle (because it can contain markdown/JSX syntax)
|
|
124
119
|
const title = (_d = (_c = frontMatter.title) !== null && _c !== void 0 ? _c : contentTitle) !== null && _d !== void 0 ? _d : baseID;
|
|
125
120
|
const description = (_f = (_e = frontMatter.description) !== null && _e !== void 0 ? _e : excerpt) !== null && _f !== void 0 ? _f : '';
|
|
126
|
-
const permalink = utils_1.normalizeUrl([versionMetadata.versionPath, docSlug]);
|
|
121
|
+
const permalink = (0, utils_1.normalizeUrl)([versionMetadata.versionPath, docSlug]);
|
|
127
122
|
function getDocEditUrl() {
|
|
128
123
|
const relativeFilePath = path_1.default.relative(contentPath, filePath);
|
|
129
124
|
if (typeof options.editUrl === 'function') {
|
|
130
125
|
return options.editUrl({
|
|
131
126
|
version: versionMetadata.versionName,
|
|
132
|
-
versionDocsDirPath: utils_1.posixPath(path_1.default.relative(siteDir, versionMetadata.contentPath)),
|
|
133
|
-
docPath: utils_1.posixPath(relativeFilePath),
|
|
127
|
+
versionDocsDirPath: (0, utils_1.posixPath)(path_1.default.relative(siteDir, versionMetadata.contentPath)),
|
|
128
|
+
docPath: (0, utils_1.posixPath)(relativeFilePath),
|
|
134
129
|
permalink,
|
|
135
130
|
locale: context.i18n.currentLocale,
|
|
136
131
|
});
|
|
@@ -140,7 +135,7 @@ function doProcessDocMetadata({ docFile, versionMetadata, context, options, }) {
|
|
|
140
135
|
const baseVersionEditUrl = isLocalized && options.editLocalizedFiles
|
|
141
136
|
? versionMetadata.versionEditUrlLocalized
|
|
142
137
|
: versionMetadata.versionEditUrl;
|
|
143
|
-
return utils_1.getEditUrl(relativeFilePath, baseVersionEditUrl);
|
|
138
|
+
return (0, utils_1.getEditUrl)(relativeFilePath, baseVersionEditUrl);
|
|
144
139
|
}
|
|
145
140
|
else {
|
|
146
141
|
return undefined;
|
|
@@ -153,14 +148,14 @@ function doProcessDocMetadata({ docFile, versionMetadata, context, options, }) {
|
|
|
153
148
|
return {
|
|
154
149
|
unversionedId,
|
|
155
150
|
id,
|
|
156
|
-
isDocsHomePage,
|
|
157
151
|
title,
|
|
158
152
|
description,
|
|
159
|
-
source: utils_1.aliasedSitePath(filePath, siteDir),
|
|
153
|
+
source: (0, utils_1.aliasedSitePath)(filePath, siteDir),
|
|
160
154
|
sourceDirName,
|
|
161
155
|
slug: docSlug,
|
|
162
156
|
permalink,
|
|
163
157
|
editUrl: customEditURL !== undefined ? customEditURL : getDocEditUrl(),
|
|
158
|
+
tags: (0, utils_1.normalizeFrontMatterTags)(versionMetadata.tagsPath, frontMatter.tags),
|
|
164
159
|
version: versionMetadata.versionName,
|
|
165
160
|
lastUpdatedBy: lastUpdate.lastUpdatedBy,
|
|
166
161
|
lastUpdatedAt: lastUpdate.lastUpdatedAt,
|
|
@@ -176,8 +171,100 @@ function processDocMetadata(args) {
|
|
|
176
171
|
return doProcessDocMetadata(args);
|
|
177
172
|
}
|
|
178
173
|
catch (e) {
|
|
179
|
-
console.error(chalk_1.default.red(`Can't process doc
|
|
174
|
+
console.error(chalk_1.default.red(`Can't process doc metadata for doc at path "${args.docFile.filePath}" in version "${args.versionMetadata.versionName}"`));
|
|
180
175
|
throw e;
|
|
181
176
|
}
|
|
182
177
|
}
|
|
183
178
|
exports.processDocMetadata = processDocMetadata;
|
|
179
|
+
function addDocNavigation(docsBase, sidebarsUtils, sidebarFilePath) {
|
|
180
|
+
const docsById = createDocsByIdIndex(docsBase);
|
|
181
|
+
sidebarsUtils.checkSidebarsDocIds(docsBase.flatMap(getDocIds), sidebarFilePath);
|
|
182
|
+
// Add sidebar/next/previous to the docs
|
|
183
|
+
function addNavData(doc) {
|
|
184
|
+
const navigation = sidebarsUtils.getDocNavigation(doc.unversionedId, doc.id);
|
|
185
|
+
const toNavigationLinkByDocId = (docId, type) => {
|
|
186
|
+
if (!docId) {
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
189
|
+
const navDoc = docsById[docId];
|
|
190
|
+
if (!navDoc) {
|
|
191
|
+
// This could only happen if user provided the ID through front matter
|
|
192
|
+
throw new Error(`Error when loading ${doc.id} in ${doc.sourceDirName}: the pagination_${type} front matter points to a non-existent ID ${docId}.`);
|
|
193
|
+
}
|
|
194
|
+
return (0, utils_2.toDocNavigationLink)(navDoc);
|
|
195
|
+
};
|
|
196
|
+
const previous = doc.frontMatter.pagination_prev
|
|
197
|
+
? toNavigationLinkByDocId(doc.frontMatter.pagination_prev, 'prev')
|
|
198
|
+
: (0, utils_2.toNavigationLink)(navigation.previous, docsById);
|
|
199
|
+
const next = doc.frontMatter.pagination_next
|
|
200
|
+
? toNavigationLinkByDocId(doc.frontMatter.pagination_next, 'next')
|
|
201
|
+
: (0, utils_2.toNavigationLink)(navigation.next, docsById);
|
|
202
|
+
return { ...doc, sidebar: navigation.sidebarName, previous, next };
|
|
203
|
+
}
|
|
204
|
+
const docsWithNavigation = docsBase.map(addNavData);
|
|
205
|
+
// sort to ensure consistent output for tests
|
|
206
|
+
docsWithNavigation.sort((a, b) => a.id.localeCompare(b.id));
|
|
207
|
+
return docsWithNavigation;
|
|
208
|
+
}
|
|
209
|
+
exports.addDocNavigation = addDocNavigation;
|
|
210
|
+
/**
|
|
211
|
+
* The "main doc" is the "version entry point"
|
|
212
|
+
* We browse this doc by clicking on a version:
|
|
213
|
+
* - the "home" doc (at '/docs/')
|
|
214
|
+
* - the first doc of the first sidebar
|
|
215
|
+
* - a random doc (if no docs are in any sidebar... edge case)
|
|
216
|
+
*/
|
|
217
|
+
function getMainDocId({ docs, sidebarsUtils, }) {
|
|
218
|
+
function getMainDoc() {
|
|
219
|
+
const versionHomeDoc = docs.find((doc) => doc.slug === '/');
|
|
220
|
+
const firstDocIdOfFirstSidebar = sidebarsUtils.getFirstDocIdOfFirstSidebar();
|
|
221
|
+
if (versionHomeDoc) {
|
|
222
|
+
return versionHomeDoc;
|
|
223
|
+
}
|
|
224
|
+
else if (firstDocIdOfFirstSidebar) {
|
|
225
|
+
return docs.find((doc) => doc.id === firstDocIdOfFirstSidebar);
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
return docs[0];
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return getMainDoc().unversionedId;
|
|
232
|
+
}
|
|
233
|
+
exports.getMainDocId = getMainDocId;
|
|
234
|
+
function getLastPathSegment(str) {
|
|
235
|
+
return (0, lodash_1.last)(str.split('/'));
|
|
236
|
+
}
|
|
237
|
+
// By convention, Docusaurus considers some docs are "indexes":
|
|
238
|
+
// - index.md
|
|
239
|
+
// - readme.md
|
|
240
|
+
// - <folder>/<folder>.md
|
|
241
|
+
//
|
|
242
|
+
// Those index docs produce a different behavior
|
|
243
|
+
// - Slugs do not end with a weird "/index" suffix
|
|
244
|
+
// - Auto-generated sidebar categories link to them as intro
|
|
245
|
+
function isConventionalDocIndex(doc) {
|
|
246
|
+
// "@site/docs/folder/subFolder/subSubFolder/myDoc.md" => "myDoc"
|
|
247
|
+
const docName = path_1.default.parse(doc.source).name;
|
|
248
|
+
// "folder/subFolder/subSubFolder" => "subSubFolder"
|
|
249
|
+
const lastDirName = getLastPathSegment(doc.sourceDirName);
|
|
250
|
+
const eligibleDocIndexNames = ['index', 'readme', lastDirName.toLowerCase()];
|
|
251
|
+
return eligibleDocIndexNames.includes(docName.toLowerCase());
|
|
252
|
+
}
|
|
253
|
+
exports.isConventionalDocIndex = isConventionalDocIndex;
|
|
254
|
+
// Return both doc ids
|
|
255
|
+
// TODO legacy retro-compatibility due to old versioned sidebars using versioned doc ids
|
|
256
|
+
// ("id" should be removed & "versionedId" should be renamed to "id")
|
|
257
|
+
function getDocIds(doc) {
|
|
258
|
+
return [doc.unversionedId, doc.id];
|
|
259
|
+
}
|
|
260
|
+
exports.getDocIds = getDocIds;
|
|
261
|
+
// docs are indexed by both versioned and unversioned ids at the same time
|
|
262
|
+
// TODO legacy retro-compatibility due to old versioned sidebars using versioned doc ids
|
|
263
|
+
// ("id" should be removed & "versionedId" should be renamed to "id")
|
|
264
|
+
function createDocsByIdIndex(docs) {
|
|
265
|
+
return {
|
|
266
|
+
...(0, lodash_1.keyBy)(docs, (doc) => doc.unversionedId),
|
|
267
|
+
...(0, lodash_1.keyBy)(docs, (doc) => doc.id),
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
exports.createDocsByIdIndex = createDocsByIdIndex;
|
package/lib/globalData.d.ts
CHANGED
|
@@ -4,6 +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 { DocMetadata, GlobalDoc, LoadedVersion, GlobalVersion } from './types';
|
|
7
|
+
import type { DocMetadata, GlobalDoc, LoadedVersion, GlobalVersion } from './types';
|
|
8
8
|
export declare function toGlobalDataDoc(doc: DocMetadata): GlobalDoc;
|
|
9
9
|
export declare function toGlobalDataVersion(version: LoadedVersion): GlobalVersion;
|
package/lib/index.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 { LoadContext, Plugin } from '@docusaurus/types';
|
|
7
|
+
import type { LoadContext, Plugin } from '@docusaurus/types';
|
|
8
8
|
import { PluginOptions, LoadedContent } from './types';
|
|
9
9
|
export default function pluginContentDocs(context: LoadContext, options: PluginOptions): Plugin<LoadedContent>;
|
|
10
10
|
export { validateOptions } from './options';
|