@docusaurus/plugin-content-docs 2.0.0-beta.138b4c997 → 2.0.0-beta.14
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 +12 -0
- package/lib/categoryGeneratedIndex.js +37 -0
- package/lib/cli.d.ts +2 -2
- package/lib/cli.js +14 -35
- package/lib/client/docsClientUtils.d.ts +0 -3
- package/lib/client/docsClientUtils.js +19 -22
- package/lib/docFrontMatter.d.ts +1 -1
- package/lib/docFrontMatter.js +8 -4
- package/lib/docs.d.ts +25 -3
- package/lib/docs.js +126 -41
- package/lib/globalData.d.ts +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +101 -133
- package/lib/lastUpdate.js +12 -12
- 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 +48 -11
- package/lib/props.d.ts +7 -2
- package/lib/props.js +60 -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/{src/__tests__/__fixtures__/site-with-autogenerated-sidebar/partialAutogeneratedSidebars2.js → lib/sidebars/types.js} +2 -10
- 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/{src/__tests__/__fixtures__/site-with-doc-label/docusaurus.config.js → lib/tags.d.ts} +2 -8
- 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 -64
- package/lib/versions.d.ts +3 -3
- package/lib/versions.js +41 -22
- package/package.json +20 -20
- package/src/categoryGeneratedIndex.ts +57 -0
- package/src/cli.ts +10 -42
- package/src/client/docsClientUtils.ts +14 -26
- package/{types.d.ts → src/deps.d.ts} +0 -0
- package/src/docFrontMatter.ts +10 -5
- package/src/docs.ts +164 -36
- package/src/globalData.ts +6 -1
- package/src/index.ts +127 -177
- package/src/lastUpdate.ts +14 -16
- package/src/markdown/index.ts +8 -12
- package/src/numberPrefix.ts +5 -3
- package/src/options.ts +56 -15
- package/src/plugin-content-docs.d.ts +172 -43
- package/src/props.ts +90 -16
- package/src/routes.ts +169 -0
- package/src/sidebars/generator.ts +302 -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 +64 -108
- package/src/versions.ts +59 -25
- package/lib/.tsbuildinfo +0 -1
- package/lib/sidebarItemsGenerator.js +0 -211
- package/lib/sidebars.d.ts +0 -43
- package/lib/sidebars.js +0 -320
- package/src/__tests__/__fixtures__/bad-id-site/docs/invalid-id.md +0 -5
- package/src/__tests__/__fixtures__/bad-slug-on-doc-home-site/docs/docWithSlug.md +0 -5
- package/src/__tests__/__fixtures__/empty-site/docusaurus.config.js +0 -16
- package/src/__tests__/__fixtures__/empty-site/sidebars.json +0 -1
- package/src/__tests__/__fixtures__/sidebars/sidebars-category-shorthand.js +0 -34
- package/src/__tests__/__fixtures__/sidebars/sidebars-category-wrong-items.json +0 -11
- package/src/__tests__/__fixtures__/sidebars/sidebars-category-wrong-label.json +0 -11
- package/src/__tests__/__fixtures__/sidebars/sidebars-category.js +0 -44
- package/src/__tests__/__fixtures__/sidebars/sidebars-collapsed-first-level.json +0 -20
- package/src/__tests__/__fixtures__/sidebars/sidebars-collapsed.json +0 -21
- package/src/__tests__/__fixtures__/sidebars/sidebars-doc-id-not-string.json +0 -10
- package/src/__tests__/__fixtures__/sidebars/sidebars-first-level-not-category.js +0 -20
- package/src/__tests__/__fixtures__/sidebars/sidebars-link-wrong-href.json +0 -11
- package/src/__tests__/__fixtures__/sidebars/sidebars-link-wrong-label.json +0 -11
- package/src/__tests__/__fixtures__/sidebars/sidebars-link.json +0 -11
- package/src/__tests__/__fixtures__/sidebars/sidebars-unknown-type.json +0 -14
- package/src/__tests__/__fixtures__/sidebars/sidebars-wrong-field.json +0 -20
- package/src/__tests__/__fixtures__/sidebars/sidebars.json +0 -20
- package/src/__tests__/__fixtures__/simple-site/docs/foo/bar.md +0 -69
- package/src/__tests__/__fixtures__/simple-site/docs/foo/baz.md +0 -70
- package/src/__tests__/__fixtures__/simple-site/docs/headingAsTitle.md +0 -1
- package/src/__tests__/__fixtures__/simple-site/docs/hello.md +0 -53
- package/src/__tests__/__fixtures__/simple-site/docs/ipsum.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/lorem.md +0 -6
- package/src/__tests__/__fixtures__/simple-site/docs/rootAbsoluteSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/rootRelativeSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/rootResolvedSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/rootTryToEscapeSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/slugs/absoluteSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/slugs/relativeSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/slugs/resolvedSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/slugs/tryToEscapeSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docusaurus.config.js +0 -14
- package/src/__tests__/__fixtures__/simple-site/sidebars.json +0 -23
- package/src/__tests__/__fixtures__/simple-site/wrong-sidebars.json +0 -7
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/0-getting-started.md +0 -3
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/1-installation.md +0 -3
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/00_api-overview.md +0 -3
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/01_Core APIs/0 --- Client API.md +0 -1
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/01_Core APIs/1 --- Server API.md +0 -1
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/0. Plugin API.md +0 -1
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/1. Theme API.md +0 -1
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/_category_.yml +0 -1
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/03_api-end.md +0 -3
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/_category_.json +0 -3
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/0-guide2.5.md +0 -8
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/02-guide2.md +0 -7
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/_category_.json +0 -3
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/a-guide4.md +0 -7
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/b-guide5.md +0 -7
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/guide3.md +0 -8
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/z-guide1.md +0 -8
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docusaurus.config.js +0 -14
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/partialAutogeneratedSidebars.js +0 -23
- package/src/__tests__/__fixtures__/site-with-doc-label/docs/hello-1.md +0 -7
- package/src/__tests__/__fixtures__/site-with-doc-label/docs/hello-2.md +0 -8
- package/src/__tests__/__fixtures__/site-with-doc-label/sidebars.json +0 -14
- package/src/__tests__/__fixtures__/versioned-site/community/team.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/community_sidebars.json +0 -3
- package/src/__tests__/__fixtures__/versioned-site/community_versioned_docs/version-1.0.0/team.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/community_versioned_sidebars/version-1.0.0-sidebars.json +0 -3
- package/src/__tests__/__fixtures__/versioned-site/community_versions.json +0 -1
- package/src/__tests__/__fixtures__/versioned-site/docs/foo/bar.md +0 -4
- package/src/__tests__/__fixtures__/versioned-site/docs/hello.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/docs/slugs/absoluteSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/docs/slugs/relativeSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/docs/slugs/resolvedSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/docs/slugs/tryToEscapeSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/docusaurus.config.js +0 -18
- package/src/__tests__/__fixtures__/versioned-site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/i18n/en/docusaurus-plugin-content-docs-community/current/team.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/i18n/fr/docusaurus-plugin-content-docs/version-1.0.0/hello.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/sidebars.json +0 -10
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/foo/bar.md +0 -4
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/foo/baz.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/hello.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/foo/bar.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/hello.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootAbsoluteSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootRelativeSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootResolvedSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootTryToEscapeSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/absoluteSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/relativeSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/resolvedSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/tryToEscapeSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-1.0.0-sidebars.json +0 -11
- package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-1.0.1-sidebars.json +0 -10
- package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-withSlugs-sidebars.json +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versions.json +0 -5
- package/src/__tests__/__snapshots__/cli.test.ts.snap +0 -90
- package/src/__tests__/__snapshots__/index.test.ts.snap +0 -1916
- package/src/__tests__/__snapshots__/sidebars.test.ts.snap +0 -218
- package/src/__tests__/__snapshots__/translations.test.ts.snap +0 -487
- package/src/__tests__/cli.test.ts +0 -333
- package/src/__tests__/docFrontMatter.test.ts +0 -244
- package/src/__tests__/docs.test.ts +0 -878
- package/src/__tests__/index.test.ts +0 -1871
- package/src/__tests__/lastUpdate.test.ts +0 -69
- package/src/__tests__/numberPrefix.test.ts +0 -199
- package/src/__tests__/options.test.ts +0 -231
- package/src/__tests__/sidebarItemsGenerator.test.ts +0 -336
- package/src/__tests__/sidebars.test.ts +0 -639
- package/src/__tests__/slug.test.ts +0 -109
- package/src/__tests__/translations.test.ts +0 -159
- package/src/__tests__/versions.test.ts +0 -741
- package/src/client/__tests__/docsClientUtils.test.ts +0 -371
- package/src/markdown/__tests__/__fixtures__/docs/doc-localized.md +0 -1
- package/src/markdown/__tests__/__fixtures__/docs/doc1.md +0 -13
- package/src/markdown/__tests__/__fixtures__/docs/doc2.md +0 -12
- package/src/markdown/__tests__/__fixtures__/docs/doc4.md +0 -19
- package/src/markdown/__tests__/__fixtures__/docs/doc5.md +0 -6
- package/src/markdown/__tests__/__fixtures__/docs/subdir/doc3.md +0 -3
- package/src/markdown/__tests__/__fixtures__/versioned_docs/version-1.0.0/doc2.md +0 -7
- package/src/markdown/__tests__/__fixtures__/versioned_docs/version-1.0.0/subdir/doc1.md +0 -3
- package/src/markdown/__tests__/__snapshots__/linkify.test.ts.snap +0 -82
- package/src/markdown/__tests__/linkify.test.ts +0 -190
- package/src/sidebarItemsGenerator.ts +0 -307
- package/src/sidebars.ts +0 -522
- package/tsconfig.json +0 -9
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import { CategoryGeneratedIndexMetadata, DocMetadataBase } from './types';
|
|
8
|
+
import { SidebarsUtils } from './sidebars/utils';
|
|
9
|
+
export declare function getCategoryGeneratedIndexMetadataList({ docs, sidebarsUtils, }: {
|
|
10
|
+
sidebarsUtils: SidebarsUtils;
|
|
11
|
+
docs: DocMetadataBase[];
|
|
12
|
+
}): CategoryGeneratedIndexMetadata[];
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
exports.getCategoryGeneratedIndexMetadataList = void 0;
|
|
10
|
+
const utils_1 = require("./sidebars/utils");
|
|
11
|
+
const docs_1 = require("./docs");
|
|
12
|
+
function getCategoryGeneratedIndexMetadata({ category, sidebarsUtils, docsById, }) {
|
|
13
|
+
var _a;
|
|
14
|
+
const { sidebarName, previous, next } = sidebarsUtils.getCategoryGeneratedIndexNavigation(category.link.permalink);
|
|
15
|
+
if (!sidebarName) {
|
|
16
|
+
throw new Error('unexpected');
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
title: (_a = category.link.title) !== null && _a !== void 0 ? _a : category.label,
|
|
20
|
+
description: category.link.description,
|
|
21
|
+
slug: category.link.slug,
|
|
22
|
+
permalink: category.link.permalink,
|
|
23
|
+
sidebar: sidebarName,
|
|
24
|
+
previous: (0, utils_1.toNavigationLink)(previous, docsById),
|
|
25
|
+
next: (0, utils_1.toNavigationLink)(next, docsById),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function getCategoryGeneratedIndexMetadataList({ docs, sidebarsUtils, }) {
|
|
29
|
+
const docsById = (0, docs_1.createDocsByIdIndex)(docs);
|
|
30
|
+
const categoryGeneratedIndexItems = sidebarsUtils.getCategoryGeneratedIndexList();
|
|
31
|
+
return categoryGeneratedIndexItems.map((category) => getCategoryGeneratedIndexMetadata({
|
|
32
|
+
category,
|
|
33
|
+
sidebarsUtils,
|
|
34
|
+
docsById,
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
exports.getCategoryGeneratedIndexMetadataList = getCategoryGeneratedIndexMetadataList;
|
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 { PathOptions } from './types';
|
|
8
|
-
export declare function cliDocsVersionCommand(version: string | null | undefined, siteDir: string, pluginId: string, options: PathOptions): void;
|
|
7
|
+
import type { PathOptions, SidebarOptions } from './types';
|
|
8
|
+
export declare function cliDocsVersionCommand(version: string | null | undefined, siteDir: string, pluginId: string, options: PathOptions & SidebarOptions): void;
|
package/lib/cli.js
CHANGED
|
@@ -9,50 +9,29 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.cliDocsVersionCommand = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const versions_1 = require("./versions");
|
|
12
|
-
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
13
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
|
+
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
13
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
14
14
|
const sidebars_1 = require("./sidebars");
|
|
15
|
-
const
|
|
15
|
+
const utils_1 = require("@docusaurus/utils");
|
|
16
|
+
const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
16
17
|
function createVersionedSidebarFile({ siteDir, pluginId, sidebarPath, version, }) {
|
|
17
18
|
// Load current sidebar and create a new versioned sidebars file (if needed).
|
|
18
|
-
|
|
19
|
+
// Note: we don't need the sidebars file to be normalized: it's ok to let plugin option changes to impact older, versioned sidebars
|
|
20
|
+
const sidebars = (0, sidebars_1.loadSidebarsFile)(sidebarPath);
|
|
19
21
|
// Do not create a useless versioned sidebars file if sidebars file is empty or sidebars are disabled/false)
|
|
20
|
-
const shouldCreateVersionedSidebarFile = Object.keys(
|
|
22
|
+
const shouldCreateVersionedSidebarFile = Object.keys(sidebars).length > 0;
|
|
21
23
|
if (shouldCreateVersionedSidebarFile) {
|
|
22
|
-
|
|
23
|
-
// TODO try to get rid of it
|
|
24
|
-
// Transform id in original sidebar to versioned id.
|
|
25
|
-
const normalizeItem = (item) => {
|
|
26
|
-
switch (item.type) {
|
|
27
|
-
case 'category':
|
|
28
|
-
return { ...item, items: item.items.map(normalizeItem) };
|
|
29
|
-
case 'ref':
|
|
30
|
-
case 'doc':
|
|
31
|
-
return {
|
|
32
|
-
type: item.type,
|
|
33
|
-
id: `version-${version}/${item.id}`,
|
|
34
|
-
};
|
|
35
|
-
default:
|
|
36
|
-
return item;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
const versionedSidebar = Object.entries(loadedSidebars).reduce((acc, [sidebarId, sidebarItems]) => {
|
|
40
|
-
const newVersionedSidebarId = `version-${version}/${sidebarId}`;
|
|
41
|
-
acc[newVersionedSidebarId] = sidebarItems.map(normalizeItem);
|
|
42
|
-
return acc;
|
|
43
|
-
}, {});
|
|
44
|
-
const versionedSidebarsDir = versions_1.getVersionedSidebarsDirPath(siteDir, pluginId);
|
|
24
|
+
const versionedSidebarsDir = (0, versions_1.getVersionedSidebarsDirPath)(siteDir, pluginId);
|
|
45
25
|
const newSidebarFile = path_1.default.join(versionedSidebarsDir, `version-${version}-sidebars.json`);
|
|
46
26
|
fs_extra_1.default.ensureDirSync(path_1.default.dirname(newSidebarFile));
|
|
47
|
-
fs_extra_1.default.writeFileSync(newSidebarFile, `${JSON.stringify(
|
|
27
|
+
fs_extra_1.default.writeFileSync(newSidebarFile, `${JSON.stringify(sidebars, null, 2)}\n`, 'utf8');
|
|
48
28
|
}
|
|
49
29
|
}
|
|
50
30
|
// Tests depend on non-default export for mocking.
|
|
51
|
-
// eslint-disable-next-line import/prefer-default-export
|
|
52
31
|
function cliDocsVersionCommand(version, siteDir, pluginId, options) {
|
|
53
32
|
// It wouldn't be very user-friendly to show a [default] log prefix,
|
|
54
33
|
// so we use [docs] instead of [default]
|
|
55
|
-
const pluginIdLogPrefix = pluginId ===
|
|
34
|
+
const pluginIdLogPrefix = pluginId === utils_1.DEFAULT_PLUGIN_ID ? '[docs]' : `[${pluginId}]`;
|
|
56
35
|
if (!version) {
|
|
57
36
|
throw new Error(`${pluginIdLogPrefix}: no version tag specified! Pass the version you wish to create as an argument, for example: 1.0.0.`);
|
|
58
37
|
}
|
|
@@ -73,7 +52,7 @@ function cliDocsVersionCommand(version, siteDir, pluginId, options) {
|
|
|
73
52
|
}
|
|
74
53
|
// Load existing versions.
|
|
75
54
|
let versions = [];
|
|
76
|
-
const versionsJSONFile = versions_1.getVersionsFilePath(siteDir, pluginId);
|
|
55
|
+
const versionsJSONFile = (0, versions_1.getVersionsFilePath)(siteDir, pluginId);
|
|
77
56
|
if (fs_extra_1.default.existsSync(versionsJSONFile)) {
|
|
78
57
|
versions = JSON.parse(fs_extra_1.default.readFileSync(versionsJSONFile, 'utf8'));
|
|
79
58
|
}
|
|
@@ -85,7 +64,7 @@ function cliDocsVersionCommand(version, siteDir, pluginId, options) {
|
|
|
85
64
|
// Copy docs files.
|
|
86
65
|
const docsDir = path_1.default.join(siteDir, docsPath);
|
|
87
66
|
if (fs_extra_1.default.existsSync(docsDir) && fs_extra_1.default.readdirSync(docsDir).length > 0) {
|
|
88
|
-
const versionedDir = versions_1.getVersionedDocsDirPath(siteDir, pluginId);
|
|
67
|
+
const versionedDir = (0, versions_1.getVersionedDocsDirPath)(siteDir, pluginId);
|
|
89
68
|
const newVersionDir = path_1.default.join(versionedDir, `version-${version}`);
|
|
90
69
|
fs_extra_1.default.copySync(docsDir, newVersionDir);
|
|
91
70
|
}
|
|
@@ -96,12 +75,12 @@ function cliDocsVersionCommand(version, siteDir, pluginId, options) {
|
|
|
96
75
|
siteDir,
|
|
97
76
|
pluginId,
|
|
98
77
|
version,
|
|
99
|
-
sidebarPath: sidebars_1.resolveSidebarPathOption(siteDir, sidebarPath),
|
|
78
|
+
sidebarPath: (0, sidebars_1.resolveSidebarPathOption)(siteDir, sidebarPath),
|
|
100
79
|
});
|
|
101
80
|
// Update versions.json file.
|
|
102
81
|
versions.unshift(version);
|
|
103
82
|
fs_extra_1.default.ensureDirSync(path_1.default.dirname(versionsJSONFile));
|
|
104
83
|
fs_extra_1.default.writeFileSync(versionsJSONFile, `${JSON.stringify(versions, null, 2)}\n`);
|
|
105
|
-
|
|
84
|
+
logger_1.default.success `name=${pluginIdLogPrefix}: version name=${version} created!`;
|
|
106
85
|
}
|
|
107
86
|
exports.cliDocsVersionCommand = cliDocsVersionCommand;
|
|
@@ -14,9 +14,6 @@ export declare type ActivePlugin = {
|
|
|
14
14
|
export declare type GetActivePluginOptions = {
|
|
15
15
|
failfast?: boolean;
|
|
16
16
|
};
|
|
17
|
-
export declare function getActivePlugin(allPluginDatas: Record<string, GlobalPluginData>, pathname: string, options: {
|
|
18
|
-
failfast: true;
|
|
19
|
-
}): ActivePlugin;
|
|
20
17
|
export declare function getActivePlugin(allPluginDatas: Record<string, GlobalPluginData>, pathname: string, options?: GetActivePluginOptions): ActivePlugin | undefined;
|
|
21
18
|
export declare type ActiveDocContext = {
|
|
22
19
|
activeVersion?: Version;
|
|
@@ -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,8 +76,8 @@ 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);
|
|
79
|
+
const latestVersion = (0, exports.getLatestVersion)(data);
|
|
80
|
+
const activeDocContext = (0, exports.getActiveDocContext)(data, pathname);
|
|
84
81
|
const latestDocSuggestion = activeDocContext === null || activeDocContext === void 0 ? void 0 : activeDocContext.alternateDocVersions[latestVersion.name];
|
|
85
82
|
return { latestDocSuggestion, latestVersionSuggestion: latestVersion };
|
|
86
83
|
};
|
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({
|
|
@@ -23,12 +22,17 @@ const DocFrontMatterSchema = utils_validation_1.JoiFrontMatter.object({
|
|
|
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
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 logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
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,23 +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
|
-
|
|
70
|
-
parse_number_prefixes = true, } = frontMatter;
|
|
69
|
+
// but allow to disable this behavior with frontmatter
|
|
70
|
+
parse_number_prefixes: parseNumberPrefixes = true, } = frontMatter;
|
|
71
71
|
// ex: api/plugins/myDoc -> myDoc
|
|
72
72
|
// ex: myDoc -> myDoc
|
|
73
73
|
const sourceFileNameWithoutExtension = path_1.default.basename(source, path_1.default.extname(source));
|
|
74
74
|
// ex: api/plugins/myDoc -> api/plugins
|
|
75
75
|
// ex: myDoc -> .
|
|
76
76
|
const sourceDirName = path_1.default.dirname(source);
|
|
77
|
-
|
|
78
|
-
const { filename: unprefixedFileName, numberPrefix } = parse_number_prefixes
|
|
77
|
+
const { filename: unprefixedFileName, numberPrefix } = parseNumberPrefixes
|
|
79
78
|
? options.numberPrefixParser(sourceFileNameWithoutExtension)
|
|
80
79
|
: { filename: sourceFileNameWithoutExtension, numberPrefix: undefined };
|
|
81
80
|
const baseID = (_a = frontMatter.id) !== null && _a !== void 0 ? _a : unprefixedFileName;
|
|
@@ -97,9 +96,8 @@ function doProcessDocMetadata({ docFile, versionMetadata, context, options, }) {
|
|
|
97
96
|
return undefined;
|
|
98
97
|
}
|
|
99
98
|
// Eventually remove the number prefixes from intermediate directories
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
? numberPrefix_1.stripPathNumberPrefixes(sourceDirName, options.numberPrefixParser)
|
|
99
|
+
return parseNumberPrefixes
|
|
100
|
+
? (0, numberPrefix_1.stripPathNumberPrefixes)(sourceDirName, options.numberPrefixParser)
|
|
103
101
|
: sourceDirName;
|
|
104
102
|
}
|
|
105
103
|
const unversionedId = [computeDirNameIdPrefix(), baseID]
|
|
@@ -108,32 +106,26 @@ function doProcessDocMetadata({ docFile, versionMetadata, context, options, }) {
|
|
|
108
106
|
// TODO is versioning the id very useful in practice?
|
|
109
107
|
// legacy versioned id, requires a breaking change to modify this
|
|
110
108
|
const id = [versionIdPrefix, unversionedId].filter(Boolean).join('/');
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
baseID,
|
|
120
|
-
dirName: sourceDirName,
|
|
121
|
-
frontmatterSlug: frontMatter.slug,
|
|
122
|
-
stripDirNumberPrefixes: parse_number_prefixes,
|
|
123
|
-
numberPrefixParser: options.numberPrefixParser,
|
|
124
|
-
});
|
|
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
|
+
});
|
|
125
117
|
// Note: the title is used by default for page title, sidebar label, pagination buttons...
|
|
126
118
|
// frontMatter.title should be used in priority over contentTitle (because it can contain markdown/JSX syntax)
|
|
127
119
|
const title = (_d = (_c = frontMatter.title) !== null && _c !== void 0 ? _c : contentTitle) !== null && _d !== void 0 ? _d : baseID;
|
|
128
120
|
const description = (_f = (_e = frontMatter.description) !== null && _e !== void 0 ? _e : excerpt) !== null && _f !== void 0 ? _f : '';
|
|
129
|
-
const permalink = utils_1.normalizeUrl([versionMetadata.versionPath, docSlug]);
|
|
121
|
+
const permalink = (0, utils_1.normalizeUrl)([versionMetadata.versionPath, docSlug]);
|
|
130
122
|
function getDocEditUrl() {
|
|
131
123
|
const relativeFilePath = path_1.default.relative(contentPath, filePath);
|
|
132
124
|
if (typeof options.editUrl === 'function') {
|
|
133
125
|
return options.editUrl({
|
|
134
126
|
version: versionMetadata.versionName,
|
|
135
|
-
versionDocsDirPath: utils_1.posixPath(path_1.default.relative(siteDir, versionMetadata.contentPath)),
|
|
136
|
-
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),
|
|
137
129
|
permalink,
|
|
138
130
|
locale: context.i18n.currentLocale,
|
|
139
131
|
});
|
|
@@ -143,7 +135,7 @@ function doProcessDocMetadata({ docFile, versionMetadata, context, options, }) {
|
|
|
143
135
|
const baseVersionEditUrl = isLocalized && options.editLocalizedFiles
|
|
144
136
|
? versionMetadata.versionEditUrlLocalized
|
|
145
137
|
: versionMetadata.versionEditUrl;
|
|
146
|
-
return utils_1.getEditUrl(relativeFilePath, baseVersionEditUrl);
|
|
138
|
+
return (0, utils_1.getEditUrl)(relativeFilePath, baseVersionEditUrl);
|
|
147
139
|
}
|
|
148
140
|
else {
|
|
149
141
|
return undefined;
|
|
@@ -156,14 +148,14 @@ function doProcessDocMetadata({ docFile, versionMetadata, context, options, }) {
|
|
|
156
148
|
return {
|
|
157
149
|
unversionedId,
|
|
158
150
|
id,
|
|
159
|
-
isDocsHomePage,
|
|
160
151
|
title,
|
|
161
152
|
description,
|
|
162
|
-
source: utils_1.aliasedSitePath(filePath, siteDir),
|
|
153
|
+
source: (0, utils_1.aliasedSitePath)(filePath, siteDir),
|
|
163
154
|
sourceDirName,
|
|
164
155
|
slug: docSlug,
|
|
165
156
|
permalink,
|
|
166
157
|
editUrl: customEditURL !== undefined ? customEditURL : getDocEditUrl(),
|
|
158
|
+
tags: (0, utils_1.normalizeFrontMatterTags)(versionMetadata.tagsPath, frontMatter.tags),
|
|
167
159
|
version: versionMetadata.versionName,
|
|
168
160
|
lastUpdatedBy: lastUpdate.lastUpdatedBy,
|
|
169
161
|
lastUpdatedAt: lastUpdate.lastUpdatedAt,
|
|
@@ -179,8 +171,101 @@ function processDocMetadata(args) {
|
|
|
179
171
|
return doProcessDocMetadata(args);
|
|
180
172
|
}
|
|
181
173
|
catch (e) {
|
|
182
|
-
|
|
174
|
+
logger_1.default.error `Can't process doc metadata for doc at path path=${args.docFile.filePath} in version name=${args.versionMetadata.versionName}`;
|
|
183
175
|
throw e;
|
|
184
176
|
}
|
|
185
177
|
}
|
|
186
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 !== undefined
|
|
197
|
+
? toNavigationLinkByDocId(doc.frontMatter.pagination_prev, 'prev')
|
|
198
|
+
: (0, utils_2.toNavigationLink)(navigation.previous, docsById);
|
|
199
|
+
const next = doc.frontMatter.pagination_next !== undefined
|
|
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
|
+
doc.unversionedId === firstDocIdOfFirstSidebar);
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
return docs[0];
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return getMainDoc().unversionedId;
|
|
233
|
+
}
|
|
234
|
+
exports.getMainDocId = getMainDocId;
|
|
235
|
+
function getLastPathSegment(str) {
|
|
236
|
+
return (0, lodash_1.last)(str.split('/'));
|
|
237
|
+
}
|
|
238
|
+
// By convention, Docusaurus considers some docs are "indexes":
|
|
239
|
+
// - index.md
|
|
240
|
+
// - readme.md
|
|
241
|
+
// - <folder>/<folder>.md
|
|
242
|
+
//
|
|
243
|
+
// Those index docs produce a different behavior
|
|
244
|
+
// - Slugs do not end with a weird "/index" suffix
|
|
245
|
+
// - Auto-generated sidebar categories link to them as intro
|
|
246
|
+
function isConventionalDocIndex(doc) {
|
|
247
|
+
// "@site/docs/folder/subFolder/subSubFolder/myDoc.md" => "myDoc"
|
|
248
|
+
const docName = path_1.default.parse(doc.source).name;
|
|
249
|
+
// "folder/subFolder/subSubFolder" => "subSubFolder"
|
|
250
|
+
const lastDirName = getLastPathSegment(doc.sourceDirName);
|
|
251
|
+
const eligibleDocIndexNames = ['index', 'readme', lastDirName.toLowerCase()];
|
|
252
|
+
return eligibleDocIndexNames.includes(docName.toLowerCase());
|
|
253
|
+
}
|
|
254
|
+
exports.isConventionalDocIndex = isConventionalDocIndex;
|
|
255
|
+
// Return both doc ids
|
|
256
|
+
// TODO legacy retro-compatibility due to old versioned sidebars using versioned doc ids
|
|
257
|
+
// ("id" should be removed & "versionedId" should be renamed to "id")
|
|
258
|
+
function getDocIds(doc) {
|
|
259
|
+
return [doc.unversionedId, doc.id];
|
|
260
|
+
}
|
|
261
|
+
exports.getDocIds = getDocIds;
|
|
262
|
+
// docs are indexed by both versioned and unversioned ids at the same time
|
|
263
|
+
// TODO legacy retro-compatibility due to old versioned sidebars using versioned doc ids
|
|
264
|
+
// ("id" should be removed & "versionedId" should be renamed to "id")
|
|
265
|
+
function createDocsByIdIndex(docs) {
|
|
266
|
+
return {
|
|
267
|
+
...(0, lodash_1.keyBy)(docs, (doc) => doc.unversionedId),
|
|
268
|
+
...(0, lodash_1.keyBy)(docs, (doc) => doc.id),
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
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';
|