@docusaurus/plugin-content-docs 2.0.0-beta.14 → 2.0.0-beta.15
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 +2 -2
- package/lib/categoryGeneratedIndex.js +2 -0
- package/lib/cli.d.ts +1 -1
- package/lib/client/docsClientUtils.d.ts +3 -22
- package/lib/client/docsClientUtils.js +5 -1
- package/lib/{theme/hooks/useDocs.d.ts → client/globalDataHooks.d.ts} +1 -2
- package/lib/{theme/hooks/useDocs.js → client/globalDataHooks.js} +2 -1
- package/lib/client/index.d.ts +7 -0
- package/lib/client/index.js +10 -0
- package/lib/docFrontMatter.js +1 -0
- package/lib/docs.d.ts +19 -6
- package/lib/docs.js +37 -17
- package/lib/globalData.d.ts +5 -1
- package/lib/globalData.js +34 -2
- package/lib/index.d.ts +3 -2
- package/lib/index.js +2 -8
- package/lib/lastUpdate.js +2 -2
- package/lib/markdown/index.d.ts +1 -1
- package/lib/markdown/linkify.d.ts +1 -1
- package/lib/numberPrefix.d.ts +1 -1
- package/lib/options.d.ts +1 -1
- package/lib/routes.d.ts +4 -3
- package/lib/routes.js +6 -3
- package/lib/sidebars/generator.js +12 -14
- package/lib/sidebars/index.d.ts +3 -2
- package/lib/sidebars/processor.d.ts +3 -2
- package/lib/sidebars/processor.js +2 -0
- package/lib/sidebars/types.d.ts +8 -3
- package/lib/sidebars/utils.d.ts +12 -4
- package/lib/sidebars/utils.js +48 -3
- package/lib/sidebars/validation.d.ts +1 -1
- package/lib/sidebars/validation.js +4 -0
- package/lib/slug.d.ts +5 -4
- package/lib/slug.js +8 -7
- package/lib/translations.js +1 -1
- package/lib/types.d.ts +7 -78
- package/lib/versions.d.ts +3 -2
- package/lib/versions.js +27 -32
- package/package.json +14 -12
- package/src/categoryGeneratedIndex.ts +5 -3
- package/src/cli.ts +4 -1
- package/src/client/docsClientUtils.ts +22 -35
- package/src/{theme/hooks/useDocs.ts → client/globalDataHooks.ts} +6 -2
- package/src/client/index.ts +8 -0
- package/src/docFrontMatter.ts +2 -1
- package/src/docs.ts +62 -29
- package/src/globalData.ts +49 -3
- package/src/index.ts +9 -15
- package/src/lastUpdate.ts +2 -2
- package/src/markdown/index.ts +1 -1
- package/src/markdown/linkify.ts +1 -1
- package/src/numberPrefix.ts +1 -1
- package/src/options.ts +1 -1
- package/src/plugin-content-docs.d.ts +128 -18
- package/src/routes.ts +19 -5
- package/src/sidebars/generator.ts +25 -20
- package/src/sidebars/index.ts +3 -2
- package/src/sidebars/normalization.ts +2 -1
- package/src/sidebars/processor.ts +8 -7
- package/src/sidebars/types.ts +9 -5
- package/src/sidebars/utils.ts +76 -8
- package/src/sidebars/validation.ts +6 -1
- package/src/slug.ts +15 -11
- package/src/translations.ts +2 -2
- package/src/types.ts +12 -98
- package/src/versions.ts +51 -47
|
@@ -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 { CategoryGeneratedIndexMetadata, DocMetadataBase } from './types';
|
|
8
|
-
import { SidebarsUtils } from './sidebars/utils';
|
|
7
|
+
import type { CategoryGeneratedIndexMetadata, DocMetadataBase } from './types';
|
|
8
|
+
import { type SidebarsUtils } from './sidebars/utils';
|
|
9
9
|
export declare function getCategoryGeneratedIndexMetadataList({ docs, sidebarsUtils, }: {
|
|
10
10
|
sidebarsUtils: SidebarsUtils;
|
|
11
11
|
docs: DocMetadataBase[];
|
|
@@ -18,6 +18,8 @@ function getCategoryGeneratedIndexMetadata({ category, sidebarsUtils, docsById,
|
|
|
18
18
|
return {
|
|
19
19
|
title: (_a = category.link.title) !== null && _a !== void 0 ? _a : category.label,
|
|
20
20
|
description: category.link.description,
|
|
21
|
+
image: category.link.image,
|
|
22
|
+
keywords: category.link.keywords,
|
|
21
23
|
slug: category.link.slug,
|
|
22
24
|
permalink: category.link.permalink,
|
|
23
25
|
sidebar: sidebarName,
|
package/lib/cli.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 type { PathOptions, SidebarOptions } from '
|
|
7
|
+
import type { PathOptions, SidebarOptions } from '@docusaurus/plugin-content-docs';
|
|
8
8
|
export declare function cliDocsVersionCommand(version: string | null | undefined, siteDir: string, pluginId: string, options: PathOptions & SidebarOptions): void;
|
|
@@ -4,28 +4,9 @@
|
|
|
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 { GlobalPluginData, GlobalVersion,
|
|
8
|
-
declare type Version = GlobalVersion;
|
|
9
|
-
declare type Doc = GlobalDoc;
|
|
10
|
-
export declare type ActivePlugin = {
|
|
11
|
-
pluginId: string;
|
|
12
|
-
pluginData: GlobalPluginData;
|
|
13
|
-
};
|
|
14
|
-
export declare type GetActivePluginOptions = {
|
|
15
|
-
failfast?: boolean;
|
|
16
|
-
};
|
|
7
|
+
import type { GlobalPluginData, GlobalVersion, GetActivePluginOptions, ActivePlugin, ActiveDocContext, DocVersionSuggestions } from '@docusaurus/plugin-content-docs/client';
|
|
17
8
|
export declare function getActivePlugin(allPluginDatas: Record<string, GlobalPluginData>, pathname: string, options?: GetActivePluginOptions): ActivePlugin | undefined;
|
|
18
|
-
export declare
|
|
19
|
-
|
|
20
|
-
activeDoc?: Doc;
|
|
21
|
-
alternateDocVersions: Record<string, Doc>;
|
|
22
|
-
};
|
|
23
|
-
export declare const getLatestVersion: (data: GlobalPluginData) => Version;
|
|
24
|
-
export declare const getActiveVersion: (data: GlobalPluginData, pathname: string) => Version | undefined;
|
|
9
|
+
export declare const getLatestVersion: (data: GlobalPluginData) => GlobalVersion;
|
|
10
|
+
export declare const getActiveVersion: (data: GlobalPluginData, pathname: string) => GlobalVersion | undefined;
|
|
25
11
|
export declare const getActiveDocContext: (data: GlobalPluginData, pathname: string) => ActiveDocContext;
|
|
26
|
-
export declare type DocVersionSuggestions = {
|
|
27
|
-
latestVersionSuggestion: GlobalVersion;
|
|
28
|
-
latestDocSuggestion?: GlobalDoc;
|
|
29
|
-
};
|
|
30
12
|
export declare const getDocVersionSuggestions: (data: GlobalPluginData, pathname: string) => DocVersionSuggestions;
|
|
31
|
-
export {};
|
|
@@ -8,11 +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
|
+
// This code is not part of the api surface, not in ./theme on purpose
|
|
11
12
|
// get the data of the plugin that is currently "active"
|
|
12
13
|
// ie the docs of that plugin are currently browsed
|
|
13
14
|
// it is useful to support multiple docs plugin instances
|
|
14
15
|
function getActivePlugin(allPluginDatas, pathname, options = {}) {
|
|
15
|
-
const activeEntry = Object.entries(allPluginDatas)
|
|
16
|
+
const activeEntry = Object.entries(allPluginDatas)
|
|
17
|
+
// A quick route sorting: '/android/foo' should match '/android' instead of '/'
|
|
18
|
+
.sort((a, b) => b[1].path.localeCompare(a[1].path))
|
|
19
|
+
.find(([, pluginData]) => !!(0, router_1.matchPath)(pathname, {
|
|
16
20
|
path: pluginData.path,
|
|
17
21
|
exact: false,
|
|
18
22
|
strict: false,
|
|
@@ -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 { GlobalPluginData, GlobalVersion } from '
|
|
8
|
-
import { ActivePlugin, ActiveDocContext, DocVersionSuggestions, GetActivePluginOptions } from '../../client/docsClientUtils';
|
|
7
|
+
import type { GlobalPluginData, GlobalVersion, ActivePlugin, ActiveDocContext, DocVersionSuggestions, GetActivePluginOptions } from '@docusaurus/plugin-content-docs/client';
|
|
9
8
|
export declare const useAllDocsData: () => Record<string, GlobalPluginData>;
|
|
10
9
|
export declare const useDocsData: (pluginId: string | undefined) => GlobalPluginData;
|
|
11
10
|
export declare const useActivePlugin: (options?: GetActivePluginOptions) => ActivePlugin | undefined;
|
|
@@ -10,7 +10,7 @@ exports.useDocVersionSuggestions = exports.useActiveDocContext = exports.useActi
|
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const router_1 = require("@docusaurus/router");
|
|
12
12
|
const useGlobalData_1 = (0, tslib_1.__importStar)(require("@docusaurus/useGlobalData"));
|
|
13
|
-
const docsClientUtils_1 = require("
|
|
13
|
+
const docsClientUtils_1 = require("./docsClientUtils");
|
|
14
14
|
// Important to use a constant object to avoid React useEffect executions etc...,
|
|
15
15
|
// see https://github.com/facebook/docusaurus/issues/5089
|
|
16
16
|
const StableEmptyObject = {};
|
|
@@ -22,6 +22,7 @@ return (_a = (0, useGlobalData_1.default)()['docusaurus-plugin-content-docs']) !
|
|
|
22
22
|
exports.useAllDocsData = useAllDocsData;
|
|
23
23
|
const useDocsData = (pluginId) => (0, useGlobalData_1.usePluginData)('docusaurus-plugin-content-docs', pluginId);
|
|
24
24
|
exports.useDocsData = useDocsData;
|
|
25
|
+
// TODO this feature should be provided by docusaurus core
|
|
25
26
|
const useActivePlugin = (options = {}) => {
|
|
26
27
|
const data = (0, exports.useAllDocsData)();
|
|
27
28
|
const { pathname } = (0, router_1.useLocation)();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
10
|
+
(0, tslib_1.__exportStar)(require("./globalDataHooks"), exports);
|
package/lib/docFrontMatter.js
CHANGED
|
@@ -24,6 +24,7 @@ const DocFrontMatterSchema = utils_validation_1.JoiFrontMatter.object({
|
|
|
24
24
|
sidebar_label: utils_validation_1.JoiFrontMatter.string(),
|
|
25
25
|
sidebar_position: utils_validation_1.JoiFrontMatter.number(),
|
|
26
26
|
sidebar_class_name: utils_validation_1.JoiFrontMatter.string(),
|
|
27
|
+
displayed_sidebar: utils_validation_1.JoiFrontMatter.string().allow(null),
|
|
27
28
|
tags: utils_validation_1.FrontMatterTagsSchema,
|
|
28
29
|
pagination_label: utils_validation_1.JoiFrontMatter.string(),
|
|
29
30
|
custom_edit_url: utils_validation_1.URISchema.allow('', null),
|
package/lib/docs.d.ts
CHANGED
|
@@ -5,8 +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 { DocFile, DocMetadataBase,
|
|
9
|
-
import { SidebarsUtils } from './sidebars/utils';
|
|
8
|
+
import type { DocFile, DocMetadataBase, VersionMetadata, LoadedVersion } from './types';
|
|
9
|
+
import type { SidebarsUtils } from './sidebars/utils';
|
|
10
|
+
import type { MetadataOptions, PluginOptions, CategoryIndexMatcher, CategoryIndexMatcherParam } from '@docusaurus/plugin-content-docs';
|
|
10
11
|
declare type LastUpdateOptions = Pick<PluginOptions, 'showLastUpdateAuthor' | 'showLastUpdateTime'>;
|
|
11
12
|
export declare function readDocFile(versionMetadata: Pick<VersionMetadata, 'contentPath' | 'contentPathLocalized'>, source: string, options: LastUpdateOptions): Promise<DocFile>;
|
|
12
13
|
export declare function readVersionDocs(versionMetadata: VersionMetadata, options: Pick<PluginOptions, 'include' | 'exclude' | 'showLastUpdateAuthor' | 'showLastUpdateTime'>): Promise<DocFile[]>;
|
|
@@ -28,10 +29,22 @@ export declare function getMainDocId({ docs, sidebarsUtils, }: {
|
|
|
28
29
|
docs: DocMetadataBase[];
|
|
29
30
|
sidebarsUtils: SidebarsUtils;
|
|
30
31
|
}): string;
|
|
31
|
-
export declare
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
export declare const isCategoryIndex: CategoryIndexMatcher;
|
|
33
|
+
export declare function toCategoryIndexMatcherParam({ source, sourceDirName, }: Pick<DocMetadataBase, 'source' | 'sourceDirName'>): CategoryIndexMatcherParam;
|
|
34
|
+
/**
|
|
35
|
+
* guides/sidebar/autogenerated.md -> 'autogenerated', '.md', ['sidebar', 'guides']
|
|
36
|
+
*/
|
|
37
|
+
export declare function splitPath(str: string): {
|
|
38
|
+
/**
|
|
39
|
+
* The list of directories, from lowest level to highest.
|
|
40
|
+
* If there's no dir name, directories is ['.']
|
|
41
|
+
*/
|
|
42
|
+
directories: string[];
|
|
43
|
+
/** The file name, without extension */
|
|
44
|
+
fileName: string;
|
|
45
|
+
/** The extension, with a leading dot */
|
|
46
|
+
extension: string;
|
|
47
|
+
};
|
|
35
48
|
export declare function getDocIds(doc: DocMetadataBase): [string, string];
|
|
36
49
|
export declare function createDocsByIdIndex<Doc extends {
|
|
37
50
|
id: string;
|
package/lib/docs.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.createDocsByIdIndex = exports.getDocIds = exports.
|
|
9
|
+
exports.createDocsByIdIndex = exports.getDocIds = exports.splitPath = exports.toCategoryIndexMatcherParam = exports.isCategoryIndex = exports.getMainDocId = exports.addDocNavigation = exports.processDocMetadata = exports.readVersionDocs = exports.readDocFile = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
12
12
|
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
@@ -66,7 +66,7 @@ function doProcessDocMetadata({ docFile, versionMetadata, context, options, }) {
|
|
|
66
66
|
const frontMatter = (0, docFrontMatter_1.validateDocFrontMatter)(unsafeFrontMatter);
|
|
67
67
|
const { custom_edit_url: customEditURL,
|
|
68
68
|
// Strip number prefixes by default (01-MyFolder/01-MyDoc.md => MyFolder/MyDoc) by default,
|
|
69
|
-
// but allow to disable this behavior with
|
|
69
|
+
// but allow to disable this behavior with front matter
|
|
70
70
|
parse_number_prefixes: parseNumberPrefixes = true, } = frontMatter;
|
|
71
71
|
// ex: api/plugins/myDoc -> myDoc
|
|
72
72
|
// ex: myDoc -> myDoc
|
|
@@ -81,7 +81,7 @@ function doProcessDocMetadata({ docFile, versionMetadata, context, options, }) {
|
|
|
81
81
|
if (baseID.includes('/')) {
|
|
82
82
|
throw new Error(`Document id "${baseID}" cannot include slash.`);
|
|
83
83
|
}
|
|
84
|
-
// For autogenerated sidebars, sidebar position can come from filename number prefix or
|
|
84
|
+
// For autogenerated sidebars, sidebar position can come from filename number prefix or front matter
|
|
85
85
|
const sidebarPosition = (_b = frontMatter.sidebar_position) !== null && _b !== void 0 ? _b : numberPrefix;
|
|
86
86
|
// TODO legacy retrocompatibility
|
|
87
87
|
// The same doc in 2 distinct version could keep the same id,
|
|
@@ -90,7 +90,7 @@ function doProcessDocMetadata({ docFile, versionMetadata, context, options, }) {
|
|
|
90
90
|
? undefined
|
|
91
91
|
: `version-${versionMetadata.versionName}`;
|
|
92
92
|
// TODO legacy retrocompatibility
|
|
93
|
-
// I think it's bad to affect the
|
|
93
|
+
// I think it's bad to affect the front matter id with the dirname?
|
|
94
94
|
function computeDirNameIdPrefix() {
|
|
95
95
|
if (sourceDirName === '.') {
|
|
96
96
|
return undefined;
|
|
@@ -110,7 +110,7 @@ function doProcessDocMetadata({ docFile, versionMetadata, context, options, }) {
|
|
|
110
110
|
baseID,
|
|
111
111
|
source,
|
|
112
112
|
sourceDirName,
|
|
113
|
-
|
|
113
|
+
frontMatterSlug: frontMatter.slug,
|
|
114
114
|
stripDirNumberPrefixes: parseNumberPrefixes,
|
|
115
115
|
numberPrefixParser: options.numberPrefixParser,
|
|
116
116
|
});
|
|
@@ -181,7 +181,7 @@ function addDocNavigation(docsBase, sidebarsUtils, sidebarFilePath) {
|
|
|
181
181
|
sidebarsUtils.checkSidebarsDocIds(docsBase.flatMap(getDocIds), sidebarFilePath);
|
|
182
182
|
// Add sidebar/next/previous to the docs
|
|
183
183
|
function addNavData(doc) {
|
|
184
|
-
const navigation = sidebarsUtils.getDocNavigation(doc.unversionedId, doc.id);
|
|
184
|
+
const navigation = sidebarsUtils.getDocNavigation(doc.unversionedId, doc.id, doc.frontMatter.displayed_sidebar);
|
|
185
185
|
const toNavigationLinkByDocId = (docId, type) => {
|
|
186
186
|
if (!docId) {
|
|
187
187
|
return undefined;
|
|
@@ -232,26 +232,46 @@ function getMainDocId({ docs, sidebarsUtils, }) {
|
|
|
232
232
|
return getMainDoc().unversionedId;
|
|
233
233
|
}
|
|
234
234
|
exports.getMainDocId = getMainDocId;
|
|
235
|
-
function getLastPathSegment(str) {
|
|
236
|
-
return (0, lodash_1.last)(str.split('/'));
|
|
237
|
-
}
|
|
238
235
|
// By convention, Docusaurus considers some docs are "indexes":
|
|
239
236
|
// - index.md
|
|
240
237
|
// - readme.md
|
|
241
238
|
// - <folder>/<folder>.md
|
|
242
239
|
//
|
|
240
|
+
// This function is the default implementation of this convention
|
|
241
|
+
//
|
|
243
242
|
// Those index docs produce a different behavior
|
|
244
243
|
// - Slugs do not end with a weird "/index" suffix
|
|
245
244
|
// - Auto-generated sidebar categories link to them as intro
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
245
|
+
const isCategoryIndex = ({ fileName, directories, }) => {
|
|
246
|
+
var _a;
|
|
247
|
+
const eligibleDocIndexNames = [
|
|
248
|
+
'index',
|
|
249
|
+
'readme',
|
|
250
|
+
(_a = directories[0]) === null || _a === void 0 ? void 0 : _a.toLowerCase(),
|
|
251
|
+
];
|
|
252
|
+
return eligibleDocIndexNames.includes(fileName.toLowerCase());
|
|
253
|
+
};
|
|
254
|
+
exports.isCategoryIndex = isCategoryIndex;
|
|
255
|
+
function toCategoryIndexMatcherParam({ source, sourceDirName, }) {
|
|
256
|
+
// source + sourceDirName are always posix-style
|
|
257
|
+
return {
|
|
258
|
+
fileName: path_1.default.posix.parse(source).name,
|
|
259
|
+
extension: path_1.default.posix.parse(source).ext,
|
|
260
|
+
directories: sourceDirName.split(path_1.default.posix.sep).reverse(),
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
exports.toCategoryIndexMatcherParam = toCategoryIndexMatcherParam;
|
|
264
|
+
/**
|
|
265
|
+
* guides/sidebar/autogenerated.md -> 'autogenerated', '.md', ['sidebar', 'guides']
|
|
266
|
+
*/
|
|
267
|
+
function splitPath(str) {
|
|
268
|
+
return {
|
|
269
|
+
fileName: path_1.default.parse(str).name,
|
|
270
|
+
extension: path_1.default.parse(str).ext,
|
|
271
|
+
directories: path_1.default.dirname(str).split(path_1.default.sep).reverse(),
|
|
272
|
+
};
|
|
253
273
|
}
|
|
254
|
-
exports.
|
|
274
|
+
exports.splitPath = splitPath;
|
|
255
275
|
// Return both doc ids
|
|
256
276
|
// TODO legacy retro-compatibility due to old versioned sidebars using versioned doc ids
|
|
257
277
|
// ("id" should be removed & "versionedId" should be renamed to "id")
|
package/lib/globalData.d.ts
CHANGED
|
@@ -4,6 +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 {
|
|
7
|
+
import type { Sidebars } from './sidebars/types';
|
|
8
|
+
import type { CategoryGeneratedIndexMetadata, DocMetadata, LoadedVersion } from './types';
|
|
9
|
+
import type { GlobalVersion, GlobalSidebar, GlobalDoc } from '@docusaurus/plugin-content-docs/client';
|
|
8
10
|
export declare function toGlobalDataDoc(doc: DocMetadata): GlobalDoc;
|
|
11
|
+
export declare function toGlobalDataGeneratedIndex(doc: CategoryGeneratedIndexMetadata): GlobalDoc;
|
|
12
|
+
export declare function toGlobalSidebars(sidebars: Sidebars, version: LoadedVersion): Record<string, GlobalSidebar>;
|
|
9
13
|
export declare function toGlobalDataVersion(version: LoadedVersion): GlobalVersion;
|
package/lib/globalData.js
CHANGED
|
@@ -6,7 +6,10 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.toGlobalDataVersion = exports.toGlobalDataDoc = void 0;
|
|
9
|
+
exports.toGlobalDataVersion = exports.toGlobalSidebars = exports.toGlobalDataGeneratedIndex = exports.toGlobalDataDoc = void 0;
|
|
10
|
+
const lodash_1 = require("lodash");
|
|
11
|
+
const utils_1 = require("@docusaurus/utils");
|
|
12
|
+
const utils_2 = require("./sidebars/utils");
|
|
10
13
|
function toGlobalDataDoc(doc) {
|
|
11
14
|
return {
|
|
12
15
|
id: doc.unversionedId,
|
|
@@ -15,6 +18,32 @@ function toGlobalDataDoc(doc) {
|
|
|
15
18
|
};
|
|
16
19
|
}
|
|
17
20
|
exports.toGlobalDataDoc = toGlobalDataDoc;
|
|
21
|
+
function toGlobalDataGeneratedIndex(doc) {
|
|
22
|
+
return {
|
|
23
|
+
id: doc.slug,
|
|
24
|
+
path: doc.permalink,
|
|
25
|
+
sidebar: doc.sidebar,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
exports.toGlobalDataGeneratedIndex = toGlobalDataGeneratedIndex;
|
|
29
|
+
function toGlobalSidebars(sidebars, version) {
|
|
30
|
+
const { getFirstLink } = (0, utils_2.createSidebarsUtils)(sidebars);
|
|
31
|
+
return (0, lodash_1.mapValues)(sidebars, (sidebar, sidebarId) => {
|
|
32
|
+
const firstLink = getFirstLink(sidebarId);
|
|
33
|
+
if (!firstLink) {
|
|
34
|
+
return {};
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
link: {
|
|
38
|
+
path: firstLink.type === 'generated-index'
|
|
39
|
+
? (0, utils_1.normalizeUrl)([version.versionPath, firstLink.slug])
|
|
40
|
+
: version.docs.find((doc) => doc.id === firstLink.id || doc.unversionedId === firstLink.id).permalink,
|
|
41
|
+
label: firstLink.label,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
exports.toGlobalSidebars = toGlobalSidebars;
|
|
18
47
|
function toGlobalDataVersion(version) {
|
|
19
48
|
return {
|
|
20
49
|
name: version.versionName,
|
|
@@ -22,7 +51,10 @@ function toGlobalDataVersion(version) {
|
|
|
22
51
|
isLast: version.isLast,
|
|
23
52
|
path: version.versionPath,
|
|
24
53
|
mainDocId: version.mainDocId,
|
|
25
|
-
docs: version.docs
|
|
54
|
+
docs: version.docs
|
|
55
|
+
.map(toGlobalDataDoc)
|
|
56
|
+
.concat(version.categoryGeneratedIndices.map(toGlobalDataGeneratedIndex)),
|
|
57
|
+
sidebars: toGlobalSidebars(version.sidebars, version),
|
|
26
58
|
};
|
|
27
59
|
}
|
|
28
60
|
exports.toGlobalDataVersion = toGlobalDataVersion;
|
package/lib/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { LoadContext, Plugin } from '@docusaurus/types';
|
|
8
|
-
import {
|
|
9
|
-
|
|
8
|
+
import type { LoadedContent } from './types';
|
|
9
|
+
import type { PluginOptions } from '@docusaurus/plugin-content-docs';
|
|
10
|
+
export default function pluginContentDocs(context: LoadContext, options: PluginOptions): Promise<Plugin<LoadedContent>>;
|
|
10
11
|
export { validateOptions } from './options';
|
package/lib/index.js
CHANGED
|
@@ -25,22 +25,16 @@ const tags_1 = require("./tags");
|
|
|
25
25
|
const routes_1 = require("./routes");
|
|
26
26
|
const utils_2 = require("./sidebars/utils");
|
|
27
27
|
const categoryGeneratedIndex_1 = require("./categoryGeneratedIndex");
|
|
28
|
-
function pluginContentDocs(context, options) {
|
|
28
|
+
async function pluginContentDocs(context, options) {
|
|
29
29
|
var _a;
|
|
30
30
|
const { siteDir, generatedFilesDir, baseUrl, siteConfig } = context;
|
|
31
|
-
const versionsMetadata = (0, versions_1.readVersionsMetadata)({ context, options });
|
|
31
|
+
const versionsMetadata = await (0, versions_1.readVersionsMetadata)({ context, options });
|
|
32
32
|
const pluginId = (_a = options.id) !== null && _a !== void 0 ? _a : utils_1.DEFAULT_PLUGIN_ID;
|
|
33
33
|
const pluginDataDirRoot = path_1.default.join(generatedFilesDir, 'docusaurus-plugin-content-docs');
|
|
34
34
|
const dataDir = path_1.default.join(pluginDataDirRoot, pluginId);
|
|
35
35
|
const aliasedSource = (source) => `~docs/${(0, utils_1.posixPath)(path_1.default.relative(pluginDataDirRoot, source))}`;
|
|
36
36
|
return {
|
|
37
37
|
name: 'docusaurus-plugin-content-docs',
|
|
38
|
-
getThemePath() {
|
|
39
|
-
return path_1.default.resolve(__dirname, './theme');
|
|
40
|
-
},
|
|
41
|
-
getTypeScriptThemePath() {
|
|
42
|
-
return path_1.default.resolve(__dirname, '..', 'src', 'theme');
|
|
43
|
-
},
|
|
44
38
|
extendCli(cli) {
|
|
45
39
|
const isDefaultPluginId = pluginId === utils_1.DEFAULT_PLUGIN_ID;
|
|
46
40
|
// Need to create one distinct command per plugin instance
|
package/lib/lastUpdate.js
CHANGED
|
@@ -35,11 +35,11 @@ async function getFileLastUpdate(filePath) {
|
|
|
35
35
|
}
|
|
36
36
|
return null;
|
|
37
37
|
}
|
|
38
|
-
const result = shelljs_1.default.exec(`git log -1 --format=%ct,%an ${filePath}`, {
|
|
38
|
+
const result = shelljs_1.default.exec(`git log -1 --format=%ct,%an "${filePath}"`, {
|
|
39
39
|
silent: true,
|
|
40
40
|
});
|
|
41
41
|
if (result.code !== 0) {
|
|
42
|
-
throw new Error(`Retrieval of git history failed at ${filePath} with exit code ${result.code}: ${result.stderr}`);
|
|
42
|
+
throw new Error(`Retrieval of git history failed at "${filePath}" with exit code ${result.code}: ${result.stderr}`);
|
|
43
43
|
}
|
|
44
44
|
return getTimestampAndAuthor(result.stdout.trim());
|
|
45
45
|
}
|
package/lib/markdown/index.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 { DocsMarkdownOption } from '../types';
|
|
7
|
+
import type { DocsMarkdownOption } from '../types';
|
|
8
8
|
import type { LoaderContext } from 'webpack';
|
|
9
9
|
export default function markdownLoader(this: LoaderContext<DocsMarkdownOption>, source: string): void;
|
|
@@ -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 { DocsMarkdownOption } from '../types';
|
|
7
|
+
import type { DocsMarkdownOption } from '../types';
|
|
8
8
|
export declare function linkify(fileString: string, filePath: string, options: DocsMarkdownOption): string;
|
package/lib/numberPrefix.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 { NumberPrefixParser } from '
|
|
7
|
+
import type { NumberPrefixParser } from '@docusaurus/plugin-content-docs';
|
|
8
8
|
export declare const DefaultNumberPrefixParser: NumberPrefixParser;
|
|
9
9
|
export declare const DisabledNumberPrefixParser: NumberPrefixParser;
|
|
10
10
|
export declare function stripNumberPrefix(str: string, parser: NumberPrefixParser): string;
|
package/lib/options.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 { PluginOptions } from '
|
|
7
|
+
import type { PluginOptions } from '@docusaurus/plugin-content-docs';
|
|
8
8
|
import { Joi } from '@docusaurus/utils-validation';
|
|
9
9
|
import type { OptionValidationContext, ValidationResult } from '@docusaurus/types';
|
|
10
10
|
export declare const DEFAULT_OPTIONS: Omit<PluginOptions, 'id' | 'sidebarPath'>;
|
package/lib/routes.d.ts
CHANGED
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import { PluginContentLoadedActions, RouteConfig } from '@docusaurus/types';
|
|
8
|
-
import { DocMetadata, LoadedVersion } from './types';
|
|
9
|
-
export declare function createCategoryGeneratedIndexRoutes({ version, actions, docCategoryGeneratedIndexComponent, }: {
|
|
7
|
+
import type { PluginContentLoadedActions, RouteConfig } from '@docusaurus/types';
|
|
8
|
+
import type { DocMetadata, LoadedVersion } from './types';
|
|
9
|
+
export declare function createCategoryGeneratedIndexRoutes({ version, actions, docCategoryGeneratedIndexComponent, aliasedSource, }: {
|
|
10
10
|
version: LoadedVersion;
|
|
11
11
|
actions: PluginContentLoadedActions;
|
|
12
12
|
docCategoryGeneratedIndexComponent: string;
|
|
13
|
+
aliasedSource: (str: string) => string;
|
|
13
14
|
}): Promise<RouteConfig[]>;
|
|
14
15
|
export declare function createDocRoutes({ docs, actions, docItemComponent, }: {
|
|
15
16
|
docs: DocMetadata[];
|
package/lib/routes.js
CHANGED
|
@@ -11,16 +11,18 @@ const tslib_1 = require("tslib");
|
|
|
11
11
|
const utils_1 = require("@docusaurus/utils");
|
|
12
12
|
const props_1 = require("./props");
|
|
13
13
|
const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
14
|
-
async function createCategoryGeneratedIndexRoutes({ version, actions, docCategoryGeneratedIndexComponent, }) {
|
|
14
|
+
async function createCategoryGeneratedIndexRoutes({ version, actions, docCategoryGeneratedIndexComponent, aliasedSource, }) {
|
|
15
15
|
const slugs = (0, utils_1.createSlugger)();
|
|
16
16
|
async function createCategoryGeneratedIndexRoute(categoryGeneratedIndex) {
|
|
17
|
-
const { sidebar, title, description, slug, permalink, previous, next } = categoryGeneratedIndex;
|
|
17
|
+
const { sidebar, title, description, slug, permalink, previous, next, image, keywords, } = categoryGeneratedIndex;
|
|
18
18
|
const propFileName = slugs.slug(`${version.versionPath}-${categoryGeneratedIndex.sidebar}-category-${categoryGeneratedIndex.title}`);
|
|
19
19
|
const prop = {
|
|
20
20
|
title,
|
|
21
21
|
description,
|
|
22
22
|
slug,
|
|
23
23
|
permalink,
|
|
24
|
+
image,
|
|
25
|
+
keywords,
|
|
24
26
|
navigation: {
|
|
25
27
|
previous,
|
|
26
28
|
next,
|
|
@@ -32,7 +34,7 @@ async function createCategoryGeneratedIndexRoutes({ version, actions, docCategor
|
|
|
32
34
|
component: docCategoryGeneratedIndexComponent,
|
|
33
35
|
exact: true,
|
|
34
36
|
modules: {
|
|
35
|
-
categoryGeneratedIndex: propData,
|
|
37
|
+
categoryGeneratedIndex: aliasedSource(propData),
|
|
36
38
|
},
|
|
37
39
|
// Same as doc, this sidebar route attribute permits to associate this subpage to the given sidebar
|
|
38
40
|
...(sidebar && { sidebar }),
|
|
@@ -75,6 +77,7 @@ async function createVersionRoutes({ loadedVersion, actions, docItemComponent, d
|
|
|
75
77
|
version,
|
|
76
78
|
actions,
|
|
77
79
|
docCategoryGeneratedIndexComponent,
|
|
80
|
+
aliasedSource,
|
|
78
81
|
}),
|
|
79
82
|
]);
|
|
80
83
|
const routes = [...docRoutes, ...sidebarsRoutes];
|
|
@@ -41,18 +41,11 @@ async function readCategoryMetadataFile(categoryDirPath) {
|
|
|
41
41
|
throw e;
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
// Simpler to use only posix paths for mocking file metadata in tests
|
|
47
|
-
const filePath = (0, utils_1.posixPath)(path_1.default.join(categoryDirPath, `${exports.CategoryMetadataFilenameBase}${ext}`));
|
|
48
|
-
if (await fs_extra_1.default.pathExists(filePath)) {
|
|
49
|
-
return tryReadFile(filePath);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return null;
|
|
44
|
+
const filePath = await (0, utils_1.findAsyncSequential)(['.json', '.yml', '.yaml'].map((ext) => (0, utils_1.posixPath)(path_1.default.join(categoryDirPath, `${exports.CategoryMetadataFilenameBase}${ext}`))), fs_extra_1.default.pathExists);
|
|
45
|
+
return filePath ? tryReadFile(filePath) : null;
|
|
53
46
|
}
|
|
54
47
|
// Comment for this feature: https://github.com/facebook/docusaurus/issues/3464#issuecomment-818670449
|
|
55
|
-
const DefaultSidebarItemsGenerator = async ({ numberPrefixParser, docs: allDocs, options, item: { dirName: autogenDir }, version, }) => {
|
|
48
|
+
const DefaultSidebarItemsGenerator = async ({ numberPrefixParser, isCategoryIndex, docs: allDocs, options, item: { dirName: autogenDir }, version, }) => {
|
|
56
49
|
const docsById = (0, docs_1.createDocsByIdIndex)(allDocs);
|
|
57
50
|
const findDoc = (docId) => docsById[docId];
|
|
58
51
|
const getDoc = (docId) => {
|
|
@@ -101,13 +94,12 @@ const DefaultSidebarItemsGenerator = async ({ numberPrefixParser, docs: allDocs,
|
|
|
101
94
|
docs.forEach((doc) => {
|
|
102
95
|
const breadcrumb = getRelativeBreadcrumb(doc);
|
|
103
96
|
let currentDir = treeRoot; // We walk down the file's path to generate the fs structure
|
|
104
|
-
|
|
105
|
-
for (const dir of breadcrumb) {
|
|
97
|
+
breadcrumb.forEach((dir) => {
|
|
106
98
|
if (typeof currentDir[dir] === 'undefined') {
|
|
107
99
|
currentDir[dir] = {}; // Create new folder.
|
|
108
100
|
}
|
|
109
101
|
currentDir = currentDir[dir]; // Go into the subdirectory.
|
|
110
|
-
}
|
|
102
|
+
});
|
|
111
103
|
currentDir[`${docIdPrefix}${doc.id}`] = null; // We've walked through the file path. Register the file in this directory.
|
|
112
104
|
});
|
|
113
105
|
return treeRoot;
|
|
@@ -141,7 +133,13 @@ const DefaultSidebarItemsGenerator = async ({ numberPrefixParser, docs: allDocs,
|
|
|
141
133
|
return allItems.find((item) => item.type === 'doc' && getLocalDocId(item.id) === localId);
|
|
142
134
|
}
|
|
143
135
|
function findConventionalCategoryDocLink() {
|
|
144
|
-
return allItems.find((item) =>
|
|
136
|
+
return allItems.find((item) => {
|
|
137
|
+
if (item.type !== 'doc') {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
const doc = getDoc(item.id);
|
|
141
|
+
return isCategoryIndex((0, docs_1.toCategoryIndexMatcherParam)(doc));
|
|
142
|
+
});
|
|
145
143
|
}
|
|
146
144
|
function getCategoryLinkedDocId() {
|
|
147
145
|
var _a, _b;
|
package/lib/sidebars/index.d.ts
CHANGED
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { SidebarsConfig, Sidebars, NormalizedSidebars } from './types';
|
|
8
|
-
import type { NormalizeSidebarsParams
|
|
9
|
-
import { SidebarProcessorParams } from './processor';
|
|
8
|
+
import type { NormalizeSidebarsParams } from '../types';
|
|
9
|
+
import { type SidebarProcessorParams } from './processor';
|
|
10
|
+
import type { PluginOptions } from '@docusaurus/plugin-content-docs';
|
|
10
11
|
export declare const DefaultSidebars: SidebarsConfig;
|
|
11
12
|
export declare const DisabledSidebars: SidebarsConfig;
|
|
12
13
|
export declare function resolveSidebarPathOption(siteDir: string, sidebarPathOption: PluginOptions['sidebarPath']): PluginOptions['sidebarPath'];
|
|
@@ -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 {
|
|
7
|
+
import type { DocMetadataBase, VersionMetadata } from '../types';
|
|
8
8
|
import type { Sidebars, NormalizedSidebars, SidebarItemsGeneratorOption } from './types';
|
|
9
|
-
import { Slugger } from '@docusaurus/utils';
|
|
9
|
+
import type { Slugger } from '@docusaurus/utils';
|
|
10
|
+
import type { NumberPrefixParser, SidebarOptions } from '@docusaurus/plugin-content-docs';
|
|
10
11
|
export declare type SidebarProcessorParams = {
|
|
11
12
|
sidebarItemsGenerator: SidebarItemsGeneratorOption;
|
|
12
13
|
numberPrefixParser: NumberPrefixParser;
|
|
@@ -13,6 +13,7 @@ const generator_1 = require("./generator");
|
|
|
13
13
|
const lodash_1 = require("lodash");
|
|
14
14
|
const combine_promises_1 = (0, tslib_1.__importDefault)(require("combine-promises"));
|
|
15
15
|
const normalization_1 = require("./normalization");
|
|
16
|
+
const docs_1 = require("../docs");
|
|
16
17
|
function toSidebarItemsGeneratorDoc(doc) {
|
|
17
18
|
return (0, lodash_1.pick)(doc, [
|
|
18
19
|
'id',
|
|
@@ -46,6 +47,7 @@ async function processSidebar(unprocessedSidebar, params) {
|
|
|
46
47
|
item,
|
|
47
48
|
numberPrefixParser,
|
|
48
49
|
defaultSidebarItemsGenerator: generator_1.DefaultSidebarItemsGenerator,
|
|
50
|
+
isCategoryIndex: docs_1.isCategoryIndex,
|
|
49
51
|
...getSidebarItemsGeneratorDocsAndVersion(),
|
|
50
52
|
options: sidebarOptions,
|
|
51
53
|
});
|