@docusaurus/plugin-content-docs 2.0.0-beta.1ec2c95e3 → 2.0.0-beta.21
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 +3 -2
- package/lib/cli.js +58 -72
- package/lib/client/docsClientUtils.d.ts +9 -28
- package/lib/client/docsClientUtils.js +34 -43
- package/lib/client/index.d.ts +22 -0
- package/lib/client/index.js +59 -0
- package/lib/constants.d.ts +4 -0
- package/lib/constants.js +4 -1
- package/lib/docs.d.ts +32 -3
- package/lib/docs.js +164 -63
- package/{src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docusaurus.config.js → lib/frontMatter.d.ts} +4 -8
- package/lib/{docFrontMatter.js → frontMatter.js} +12 -3
- package/lib/globalData.d.ts +3 -3
- package/lib/globalData.js +35 -6
- package/lib/index.d.ts +3 -3
- package/lib/index.js +123 -149
- package/lib/lastUpdate.d.ts +4 -6
- package/lib/lastUpdate.js +22 -26
- package/lib/markdown/index.d.ts +3 -6
- package/lib/markdown/index.js +3 -3
- package/lib/markdown/linkify.d.ts +1 -1
- package/lib/markdown/linkify.js +6 -3
- package/lib/numberPrefix.d.ts +1 -1
- package/lib/numberPrefix.js +16 -21
- package/lib/options.d.ts +3 -5
- package/lib/options.js +54 -13
- package/lib/props.d.ts +7 -2
- package/lib/props.js +70 -14
- package/lib/routes.d.ts +29 -0
- package/lib/routes.js +96 -0
- package/lib/server-export.d.ts +9 -0
- package/lib/server-export.js +22 -0
- package/lib/{sidebarItemsGenerator.d.ts → sidebars/generator.d.ts} +1 -6
- package/lib/sidebars/generator.js +209 -0
- package/lib/sidebars/index.d.ts +13 -0
- package/lib/sidebars/index.js +92 -0
- package/lib/sidebars/normalization.d.ts +13 -0
- package/lib/sidebars/normalization.js +55 -0
- package/lib/sidebars/postProcessor.d.ts +11 -0
- package/lib/sidebars/postProcessor.js +81 -0
- package/lib/sidebars/processor.d.ts +10 -0
- package/lib/sidebars/processor.js +79 -0
- package/lib/sidebars/types.d.ts +178 -0
- package/lib/{docFrontMatter.d.ts → sidebars/types.js} +2 -2
- package/lib/sidebars/utils.d.ts +54 -0
- package/lib/sidebars/utils.js +255 -0
- package/lib/sidebars/validation.d.ts +11 -0
- package/lib/sidebars/validation.js +142 -0
- package/lib/slug.d.ts +5 -4
- package/lib/slug.js +28 -18
- package/{src/__tests__/__fixtures__/sidebars/sidebars-first-level-not-category.js → lib/tags.d.ts} +3 -14
- package/lib/tags.js +21 -0
- package/lib/translations.d.ts +3 -3
- package/lib/translations.js +83 -93
- package/lib/types.d.ts +13 -184
- package/lib/versions/files.d.ts +51 -0
- package/lib/versions/files.js +143 -0
- package/lib/versions/index.d.ts +36 -0
- package/lib/versions/index.js +155 -0
- package/lib/versions/validation.d.ts +17 -0
- package/lib/versions/validation.js +71 -0
- package/package.json +34 -29
- package/src/categoryGeneratedIndex.ts +60 -0
- package/src/cli.ts +85 -114
- package/src/client/docsClientUtils.ts +44 -71
- package/src/client/index.ts +106 -0
- package/src/constants.ts +4 -2
- package/{types.d.ts → src/deps.d.ts} +1 -1
- package/src/docs.ts +228 -65
- package/src/{docFrontMatter.ts → frontMatter.ts} +20 -10
- package/src/globalData.ts +57 -7
- package/src/index.ts +179 -216
- package/src/lastUpdate.ts +26 -37
- package/src/markdown/index.ts +10 -16
- package/src/markdown/linkify.ts +7 -4
- package/src/numberPrefix.ts +19 -26
- package/src/options.ts +59 -18
- package/src/plugin-content-docs.d.ts +642 -89
- package/src/props.ts +103 -21
- package/src/routes.ts +159 -0
- package/src/server-export.ts +22 -0
- package/src/sidebars/README.md +10 -0
- package/src/sidebars/generator.ts +292 -0
- package/src/sidebars/index.ts +118 -0
- package/src/sidebars/normalization.ts +85 -0
- package/src/sidebars/postProcessor.ts +112 -0
- package/src/sidebars/processor.ts +123 -0
- package/src/sidebars/types.ts +275 -0
- package/src/sidebars/utils.ts +390 -0
- package/src/sidebars/validation.ts +178 -0
- package/src/slug.ts +41 -22
- package/src/tags.ts +20 -0
- package/src/translations.ts +129 -123
- package/src/types.ts +18 -249
- package/src/versions/files.ts +220 -0
- package/src/versions/index.ts +247 -0
- package/src/versions/validation.ts +115 -0
- 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/lib/theme/hooks/useDocs.d.ts +0 -20
- package/lib/theme/hooks/useDocs.js +0 -75
- package/lib/versions.d.ts +0 -16
- package/lib/versions.js +0 -319
- 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-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/partialAutogeneratedSidebars.js +0 -23
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/partialAutogeneratedSidebars2.js +0 -16
- 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/docusaurus.config.js +0 -14
- 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/src/theme/hooks/useDocs.ts +0 -103
- package/src/versions.ts +0 -572
- package/tsconfig.json +0 -9
package/lib/translations.js
CHANGED
|
@@ -7,19 +7,18 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.translateLoadedContent = exports.getLoadedContentTranslationFiles = void 0;
|
|
10
|
-
const
|
|
11
|
-
const
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
12
|
const utils_1 = require("@docusaurus/utils");
|
|
13
13
|
const constants_1 = require("./constants");
|
|
14
|
+
const utils_2 = require("./sidebars/utils");
|
|
14
15
|
function getVersionFileName(versionName) {
|
|
15
16
|
if (versionName === constants_1.CURRENT_VERSION_NAME) {
|
|
16
17
|
return versionName;
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return `version-${versionName}`;
|
|
22
|
-
}
|
|
19
|
+
// I don't like this "version-" prefix,
|
|
20
|
+
// but it's for consistency with site/versioned_docs
|
|
21
|
+
return `version-${versionName}`;
|
|
23
22
|
}
|
|
24
23
|
// TODO legacy, the sidebar name is like "version-2.0.0-alpha.66/docs"
|
|
25
24
|
// input: "version-2.0.0-alpha.66/docs"
|
|
@@ -31,87 +30,87 @@ function getNormalizedSidebarName({ versionName, sidebarName, }) {
|
|
|
31
30
|
const [, ...rest] = sidebarName.split('/');
|
|
32
31
|
return rest.join('/');
|
|
33
32
|
}
|
|
34
|
-
/*
|
|
35
|
-
// Do we need to translate doc metadatas?
|
|
36
|
-
// It seems translating frontmatter labels is good enough
|
|
37
|
-
function getDocTranslations(doc: DocMetadata): TranslationFileContent {
|
|
38
|
-
return {
|
|
39
|
-
[`${doc.unversionedId}.title`]: {
|
|
40
|
-
message: doc.title,
|
|
41
|
-
description: `The title for doc with id=${doc.unversionedId}`,
|
|
42
|
-
},
|
|
43
|
-
...(doc.sidebar_label
|
|
44
|
-
? {
|
|
45
|
-
[`${doc.unversionedId}.sidebar_label`]: {
|
|
46
|
-
message: doc.sidebar_label,
|
|
47
|
-
description: `The sidebar label for doc with id=${doc.unversionedId}`,
|
|
48
|
-
},
|
|
49
|
-
}
|
|
50
|
-
: undefined),
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
function translateDoc(
|
|
54
|
-
doc: DocMetadata,
|
|
55
|
-
docsTranslations: TranslationFileContent,
|
|
56
|
-
): DocMetadata {
|
|
57
|
-
return {
|
|
58
|
-
...doc,
|
|
59
|
-
title: docsTranslations[`${doc.unversionedId}.title`]?.message ?? doc.title,
|
|
60
|
-
sidebar_label:
|
|
61
|
-
docsTranslations[`${doc.unversionedId}.sidebar_label`]?.message ??
|
|
62
|
-
doc.sidebar_label,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function getDocsTranslations(version: LoadedVersion): TranslationFileContent {
|
|
67
|
-
return mergeTranslations(version.docs.map(getDocTranslations));
|
|
68
|
-
}
|
|
69
|
-
function translateDocs(
|
|
70
|
-
docs: DocMetadata[],
|
|
71
|
-
docsTranslations: TranslationFileContent,
|
|
72
|
-
): DocMetadata[] {
|
|
73
|
-
return docs.map((doc) => translateDoc(doc, docsTranslations));
|
|
74
|
-
}
|
|
75
|
-
*/
|
|
76
33
|
function getSidebarTranslationFileContent(sidebar, sidebarName) {
|
|
77
|
-
const categories =
|
|
78
|
-
const categoryContent =
|
|
79
|
-
|
|
80
|
-
.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
.
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
34
|
+
const categories = (0, utils_2.collectSidebarCategories)(sidebar);
|
|
35
|
+
const categoryContent = Object.fromEntries(categories.flatMap((category) => {
|
|
36
|
+
const entries = [];
|
|
37
|
+
entries.push([
|
|
38
|
+
`sidebar.${sidebarName}.category.${category.label}`,
|
|
39
|
+
{
|
|
40
|
+
message: category.label,
|
|
41
|
+
description: `The label for category ${category.label} in sidebar ${sidebarName}`,
|
|
42
|
+
},
|
|
43
|
+
]);
|
|
44
|
+
if (category.link?.type === 'generated-index') {
|
|
45
|
+
if (category.link.title) {
|
|
46
|
+
entries.push([
|
|
47
|
+
`sidebar.${sidebarName}.category.${category.label}.link.generated-index.title`,
|
|
48
|
+
{
|
|
49
|
+
message: category.link.title,
|
|
50
|
+
description: `The generated-index page title for category ${category.label} in sidebar ${sidebarName}`,
|
|
51
|
+
},
|
|
52
|
+
]);
|
|
53
|
+
}
|
|
54
|
+
if (category.link.description) {
|
|
55
|
+
entries.push([
|
|
56
|
+
`sidebar.${sidebarName}.category.${category.label}.link.generated-index.description`,
|
|
57
|
+
{
|
|
58
|
+
message: category.link.description,
|
|
59
|
+
description: `The generated-index page description for category ${category.label} in sidebar ${sidebarName}`,
|
|
60
|
+
},
|
|
61
|
+
]);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return entries;
|
|
65
|
+
}));
|
|
66
|
+
const links = (0, utils_2.collectSidebarLinks)(sidebar);
|
|
67
|
+
const linksContent = Object.fromEntries(links.map((link) => [
|
|
68
|
+
`sidebar.${sidebarName}.link.${link.label}`,
|
|
69
|
+
{
|
|
70
|
+
message: link.label,
|
|
71
|
+
description: `The label for link ${link.label} in sidebar ${sidebarName}, linking to ${link.href}`,
|
|
72
|
+
},
|
|
73
|
+
]));
|
|
74
|
+
return (0, utils_1.mergeTranslations)([categoryContent, linksContent]);
|
|
94
75
|
}
|
|
95
76
|
function translateSidebar({ sidebar, sidebarName, sidebarsTranslations, }) {
|
|
96
|
-
|
|
97
|
-
|
|
77
|
+
function transformSidebarCategoryLink(category) {
|
|
78
|
+
if (!category.link) {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
if (category.link.type === 'generated-index') {
|
|
82
|
+
const title = sidebarsTranslations[`sidebar.${sidebarName}.category.${category.label}.link.generated-index.title`]?.message ?? category.link.title;
|
|
83
|
+
const description = sidebarsTranslations[`sidebar.${sidebarName}.category.${category.label}.link.generated-index.description`]?.message ?? category.link.description;
|
|
84
|
+
return {
|
|
85
|
+
...category.link,
|
|
86
|
+
title,
|
|
87
|
+
description,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return category.link;
|
|
91
|
+
}
|
|
92
|
+
return (0, utils_2.transformSidebarItems)(sidebar, (item) => {
|
|
98
93
|
if (item.type === 'category') {
|
|
94
|
+
const link = transformSidebarCategoryLink(item);
|
|
99
95
|
return {
|
|
100
96
|
...item,
|
|
101
|
-
label:
|
|
97
|
+
label: sidebarsTranslations[`sidebar.${sidebarName}.category.${item.label}`]
|
|
98
|
+
?.message ?? item.label,
|
|
99
|
+
...(link && { link }),
|
|
102
100
|
};
|
|
103
101
|
}
|
|
104
102
|
if (item.type === 'link') {
|
|
105
103
|
return {
|
|
106
104
|
...item,
|
|
107
|
-
label:
|
|
105
|
+
label: sidebarsTranslations[`sidebar.${sidebarName}.link.${item.label}`]
|
|
106
|
+
?.message ?? item.label,
|
|
108
107
|
};
|
|
109
108
|
}
|
|
110
109
|
return item;
|
|
111
110
|
});
|
|
112
111
|
}
|
|
113
112
|
function getSidebarsTranslations(version) {
|
|
114
|
-
return utils_1.mergeTranslations(Object.entries(version.sidebars).map(([sidebarName, sidebar]) => {
|
|
113
|
+
return (0, utils_1.mergeTranslations)(Object.entries(version.sidebars).map(([sidebarName, sidebar]) => {
|
|
115
114
|
const normalizedSidebarName = getNormalizedSidebarName({
|
|
116
115
|
sidebarName,
|
|
117
116
|
versionName: version.versionName,
|
|
@@ -120,49 +119,40 @@ function getSidebarsTranslations(version) {
|
|
|
120
119
|
}));
|
|
121
120
|
}
|
|
122
121
|
function translateSidebars(version, sidebarsTranslations) {
|
|
123
|
-
return lodash_1.mapValues(version.sidebars, (sidebar, sidebarName) => {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
sidebarName
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
});
|
|
132
|
-
});
|
|
122
|
+
return lodash_1.default.mapValues(version.sidebars, (sidebar, sidebarName) => translateSidebar({
|
|
123
|
+
sidebar,
|
|
124
|
+
sidebarName: getNormalizedSidebarName({
|
|
125
|
+
sidebarName,
|
|
126
|
+
versionName: version.versionName,
|
|
127
|
+
}),
|
|
128
|
+
sidebarsTranslations,
|
|
129
|
+
}));
|
|
133
130
|
}
|
|
134
131
|
function getVersionTranslationFiles(version) {
|
|
135
132
|
const versionTranslations = {
|
|
136
133
|
'version.label': {
|
|
137
|
-
message: version.
|
|
134
|
+
message: version.label,
|
|
138
135
|
description: `The label for version ${version.versionName}`,
|
|
139
136
|
},
|
|
140
137
|
};
|
|
141
138
|
const sidebarsTranslations = getSidebarsTranslations(version);
|
|
142
|
-
// const docsTranslations: TranslationFileContent = getDocsTranslations(version);
|
|
143
139
|
return [
|
|
144
140
|
{
|
|
145
141
|
path: getVersionFileName(version.versionName),
|
|
146
|
-
content: utils_1.mergeTranslations([
|
|
147
|
-
versionTranslations,
|
|
148
|
-
sidebarsTranslations,
|
|
149
|
-
// docsTranslations,
|
|
150
|
-
]),
|
|
142
|
+
content: (0, utils_1.mergeTranslations)([versionTranslations, sidebarsTranslations]),
|
|
151
143
|
},
|
|
152
144
|
];
|
|
153
145
|
}
|
|
154
146
|
function translateVersion(version, translationFiles) {
|
|
155
|
-
var _a;
|
|
156
147
|
const versionTranslations = translationFiles[getVersionFileName(version.versionName)].content;
|
|
157
148
|
return {
|
|
158
149
|
...version,
|
|
159
|
-
|
|
150
|
+
label: versionTranslations['version.label']?.message ?? version.label,
|
|
160
151
|
sidebars: translateSidebars(version, versionTranslations),
|
|
161
|
-
// docs: translateDocs(version.docs, versionTranslations),
|
|
162
152
|
};
|
|
163
153
|
}
|
|
164
154
|
function getVersionsTranslationFiles(versions) {
|
|
165
|
-
return
|
|
155
|
+
return versions.flatMap(getVersionTranslationFiles);
|
|
166
156
|
}
|
|
167
157
|
function translateVersions(versions, translationFiles) {
|
|
168
158
|
return versions.map((version) => translateVersion(version, translationFiles));
|
|
@@ -172,7 +162,7 @@ function getLoadedContentTranslationFiles(loadedContent) {
|
|
|
172
162
|
}
|
|
173
163
|
exports.getLoadedContentTranslationFiles = getLoadedContentTranslationFiles;
|
|
174
164
|
function translateLoadedContent(loadedContent, translationFiles) {
|
|
175
|
-
const translationFilesMap = lodash_1.keyBy(translationFiles, (f) => f.path);
|
|
165
|
+
const translationFilesMap = lodash_1.default.keyBy(translationFiles, (f) => f.path);
|
|
176
166
|
return {
|
|
177
167
|
loadedVersions: translateVersions(loadedContent.loadedVersions, translationFilesMap),
|
|
178
168
|
};
|
package/lib/types.d.ts
CHANGED
|
@@ -4,8 +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 type {
|
|
8
|
-
import {
|
|
7
|
+
import type { BrokenMarkdownLink, Tag } from '@docusaurus/utils';
|
|
8
|
+
import type { VersionMetadata, LastUpdateData, LoadedVersion, CategoryGeneratedIndexMetadata } from '@docusaurus/plugin-content-docs';
|
|
9
|
+
import type { SidebarsUtils } from './sidebars/utils';
|
|
9
10
|
export declare type DocFile = {
|
|
10
11
|
contentPath: string;
|
|
11
12
|
filePath: string;
|
|
@@ -13,196 +14,24 @@ export declare type DocFile = {
|
|
|
13
14
|
content: string;
|
|
14
15
|
lastUpdate: LastUpdateData;
|
|
15
16
|
};
|
|
16
|
-
export declare type VersionName = string;
|
|
17
|
-
export declare type VersionMetadata = ContentPaths & {
|
|
18
|
-
versionName: VersionName;
|
|
19
|
-
versionLabel: string;
|
|
20
|
-
versionPath: string;
|
|
21
|
-
versionEditUrl?: string | undefined;
|
|
22
|
-
versionEditUrlLocalized?: string | undefined;
|
|
23
|
-
versionBanner: VersionBanner;
|
|
24
|
-
isLast: boolean;
|
|
25
|
-
sidebarFilePath: string | false | undefined;
|
|
26
|
-
routePriority: number | undefined;
|
|
27
|
-
};
|
|
28
|
-
export declare type EditUrlFunction = (editUrlParams: {
|
|
29
|
-
version: string;
|
|
30
|
-
versionDocsDirPath: string;
|
|
31
|
-
docPath: string;
|
|
32
|
-
permalink: string;
|
|
33
|
-
locale: string;
|
|
34
|
-
}) => string | undefined;
|
|
35
|
-
export declare type MetadataOptions = {
|
|
36
|
-
routeBasePath: string;
|
|
37
|
-
homePageId?: string;
|
|
38
|
-
editUrl?: string | EditUrlFunction;
|
|
39
|
-
editCurrentVersion: boolean;
|
|
40
|
-
editLocalizedFiles: boolean;
|
|
41
|
-
showLastUpdateTime?: boolean;
|
|
42
|
-
showLastUpdateAuthor?: boolean;
|
|
43
|
-
numberPrefixParser: NumberPrefixParser;
|
|
44
|
-
};
|
|
45
|
-
export declare type PathOptions = {
|
|
46
|
-
path: string;
|
|
47
|
-
sidebarPath?: string | false | undefined;
|
|
48
|
-
};
|
|
49
|
-
export declare type VersionBanner = 'none' | 'unreleased' | 'unmaintained';
|
|
50
|
-
export declare type VersionOptions = {
|
|
51
|
-
path?: string;
|
|
52
|
-
label?: string;
|
|
53
|
-
banner?: VersionBanner;
|
|
54
|
-
};
|
|
55
|
-
export declare type VersionsOptions = {
|
|
56
|
-
lastVersion?: string;
|
|
57
|
-
versions: Record<string, VersionOptions>;
|
|
58
|
-
onlyIncludeVersions?: string[];
|
|
59
|
-
};
|
|
60
|
-
export declare type PluginOptions = MetadataOptions & PathOptions & VersionsOptions & RemarkAndRehypePluginOptions & {
|
|
61
|
-
id: string;
|
|
62
|
-
include: string[];
|
|
63
|
-
docLayoutComponent: string;
|
|
64
|
-
docItemComponent: string;
|
|
65
|
-
admonitions: Record<string, unknown>;
|
|
66
|
-
disableVersioning: boolean;
|
|
67
|
-
includeCurrentVersion: boolean;
|
|
68
|
-
sidebarItemsGenerator: SidebarItemsGeneratorOption;
|
|
69
|
-
};
|
|
70
|
-
export declare type SidebarItemBase = {
|
|
71
|
-
customProps?: Record<string, unknown>;
|
|
72
|
-
};
|
|
73
|
-
export declare type SidebarItemDoc = SidebarItemBase & {
|
|
74
|
-
type: 'doc' | 'ref';
|
|
75
|
-
label?: string;
|
|
76
|
-
id: string;
|
|
77
|
-
};
|
|
78
|
-
export declare type SidebarItemLink = SidebarItemBase & {
|
|
79
|
-
type: 'link';
|
|
80
|
-
href: string;
|
|
81
|
-
label: string;
|
|
82
|
-
};
|
|
83
|
-
export declare type SidebarItemCategory = SidebarItemBase & {
|
|
84
|
-
type: 'category';
|
|
85
|
-
label: string;
|
|
86
|
-
items: SidebarItem[];
|
|
87
|
-
collapsed: boolean;
|
|
88
|
-
};
|
|
89
|
-
export declare type UnprocessedSidebarItemAutogenerated = {
|
|
90
|
-
type: 'autogenerated';
|
|
91
|
-
dirName: string;
|
|
92
|
-
};
|
|
93
|
-
export declare type UnprocessedSidebarItemCategory = SidebarItemBase & {
|
|
94
|
-
type: 'category';
|
|
95
|
-
label: string;
|
|
96
|
-
items: UnprocessedSidebarItem[];
|
|
97
|
-
collapsed: boolean;
|
|
98
|
-
};
|
|
99
|
-
export declare type UnprocessedSidebarItem = SidebarItemDoc | SidebarItemLink | UnprocessedSidebarItemCategory | UnprocessedSidebarItemAutogenerated;
|
|
100
|
-
export declare type UnprocessedSidebar = UnprocessedSidebarItem[];
|
|
101
|
-
export declare type UnprocessedSidebars = Record<string, UnprocessedSidebar>;
|
|
102
|
-
export declare type SidebarItem = SidebarItemDoc | SidebarItemLink | SidebarItemCategory;
|
|
103
|
-
export declare type Sidebar = SidebarItem[];
|
|
104
|
-
export declare type SidebarItemType = SidebarItem['type'];
|
|
105
|
-
export declare type Sidebars = Record<string, Sidebar>;
|
|
106
|
-
export declare type SidebarItemsGeneratorDoc = Pick<DocMetadataBase, 'id' | 'frontMatter' | 'source' | 'sourceDirName' | 'sidebarPosition'>;
|
|
107
|
-
export declare type SidebarItemsGeneratorVersion = Pick<VersionMetadata, 'versionName' | 'contentPath'>;
|
|
108
|
-
export declare type SidebarItemsGeneratorArgs = {
|
|
109
|
-
item: UnprocessedSidebarItemAutogenerated;
|
|
110
|
-
version: SidebarItemsGeneratorVersion;
|
|
111
|
-
docs: SidebarItemsGeneratorDoc[];
|
|
112
|
-
numberPrefixParser: NumberPrefixParser;
|
|
113
|
-
};
|
|
114
|
-
export declare type SidebarItemsGenerator = (generatorArgs: SidebarItemsGeneratorArgs) => Promise<SidebarItem[]>;
|
|
115
|
-
export declare type SidebarItemsGeneratorOptionArgs = {
|
|
116
|
-
defaultSidebarItemsGenerator: SidebarItemsGenerator;
|
|
117
|
-
} & SidebarItemsGeneratorArgs;
|
|
118
|
-
export declare type SidebarItemsGeneratorOption = (generatorArgs: SidebarItemsGeneratorOptionArgs) => Promise<SidebarItem[]>;
|
|
119
|
-
export declare type OrderMetadata = {
|
|
120
|
-
previous?: string;
|
|
121
|
-
next?: string;
|
|
122
|
-
sidebar?: string;
|
|
123
|
-
};
|
|
124
|
-
export declare type LastUpdateData = {
|
|
125
|
-
lastUpdatedAt?: number;
|
|
126
|
-
formattedLastUpdatedAt?: string;
|
|
127
|
-
lastUpdatedBy?: string;
|
|
128
|
-
};
|
|
129
|
-
export declare type DocFrontMatter = {
|
|
130
|
-
id?: string;
|
|
131
|
-
title?: string;
|
|
132
|
-
hide_title?: boolean;
|
|
133
|
-
hide_table_of_contents?: boolean;
|
|
134
|
-
keywords?: string[];
|
|
135
|
-
image?: string;
|
|
136
|
-
description?: string;
|
|
137
|
-
slug?: string;
|
|
138
|
-
sidebar_label?: string;
|
|
139
|
-
sidebar_position?: number;
|
|
140
|
-
pagination_label?: string;
|
|
141
|
-
custom_edit_url?: string | null;
|
|
142
|
-
parse_number_prefixes?: boolean;
|
|
143
|
-
};
|
|
144
|
-
export declare type DocMetadataBase = LastUpdateData & {
|
|
145
|
-
version: VersionName;
|
|
146
|
-
unversionedId: string;
|
|
147
|
-
id: string;
|
|
148
|
-
isDocsHomePage: boolean;
|
|
149
|
-
title: string;
|
|
150
|
-
description: string;
|
|
151
|
-
source: string;
|
|
152
|
-
sourceDirName: string;
|
|
153
|
-
slug: string;
|
|
154
|
-
permalink: string;
|
|
155
|
-
sidebarPosition?: number;
|
|
156
|
-
editUrl?: string | null;
|
|
157
|
-
frontMatter: DocFrontMatter & Record<string, unknown>;
|
|
158
|
-
};
|
|
159
|
-
export declare type DocNavLink = {
|
|
160
|
-
title: string;
|
|
161
|
-
permalink: string;
|
|
162
|
-
};
|
|
163
|
-
export declare type DocMetadata = DocMetadataBase & {
|
|
164
|
-
sidebar?: string;
|
|
165
|
-
previous?: DocNavLink;
|
|
166
|
-
next?: DocNavLink;
|
|
167
|
-
};
|
|
168
17
|
export declare type SourceToPermalink = {
|
|
169
18
|
[source: string]: string;
|
|
170
19
|
};
|
|
171
|
-
export declare type
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
docs: DocMetadata[];
|
|
175
|
-
sidebars: Sidebars;
|
|
176
|
-
permalinkToSidebar: Record<string, string>;
|
|
177
|
-
};
|
|
178
|
-
export declare type LoadedContent = {
|
|
179
|
-
loadedVersions: LoadedVersion[];
|
|
20
|
+
export declare type VersionTag = Tag & {
|
|
21
|
+
/** All doc ids having this tag. */
|
|
22
|
+
docIds: string[];
|
|
180
23
|
};
|
|
181
|
-
export declare type
|
|
182
|
-
|
|
183
|
-
path: string;
|
|
184
|
-
sidebar: string | undefined;
|
|
24
|
+
export declare type VersionTags = {
|
|
25
|
+
[permalink: string]: VersionTag;
|
|
185
26
|
};
|
|
186
|
-
export declare type
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
isLast: boolean;
|
|
190
|
-
path: string;
|
|
191
|
-
mainDocId: string;
|
|
192
|
-
docs: GlobalDoc[];
|
|
27
|
+
export declare type FullVersion = LoadedVersion & {
|
|
28
|
+
sidebarsUtils: SidebarsUtils;
|
|
29
|
+
categoryGeneratedIndices: CategoryGeneratedIndexMetadata[];
|
|
193
30
|
};
|
|
194
|
-
export declare type
|
|
195
|
-
path: string;
|
|
196
|
-
versions: GlobalVersion[];
|
|
197
|
-
};
|
|
198
|
-
export declare type BrokenMarkdownLink = IBrokenMarkdownLink<VersionMetadata>;
|
|
31
|
+
export declare type DocBrokenMarkdownLink = BrokenMarkdownLink<VersionMetadata>;
|
|
199
32
|
export declare type DocsMarkdownOption = {
|
|
200
33
|
versionsMetadata: VersionMetadata[];
|
|
201
34
|
siteDir: string;
|
|
202
35
|
sourceToPermalink: SourceToPermalink;
|
|
203
|
-
onBrokenMarkdownLink: (brokenMarkdownLink:
|
|
204
|
-
};
|
|
205
|
-
export declare type NumberPrefixParser = (filename: string) => {
|
|
206
|
-
filename: string;
|
|
207
|
-
numberPrefix?: number;
|
|
36
|
+
onBrokenMarkdownLink: (brokenMarkdownLink: DocBrokenMarkdownLink) => void;
|
|
208
37
|
};
|
|
@@ -0,0 +1,51 @@
|
|
|
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 type { PluginOptions, VersionMetadata } from '@docusaurus/plugin-content-docs';
|
|
8
|
+
import type { VersionContext } from './index';
|
|
9
|
+
/** `[siteDir]/community_versioned_docs/version-1.0.0` */
|
|
10
|
+
export declare function getVersionDocsDirPath(siteDir: string, pluginId: string, versionName: string): string;
|
|
11
|
+
/** `[siteDir]/community_versioned_sidebars/version-1.0.0-sidebars.json` */
|
|
12
|
+
export declare function getVersionSidebarsPath(siteDir: string, pluginId: string, versionName: string): string;
|
|
13
|
+
export declare function getDocsDirPathLocalized({ siteDir, locale, pluginId, versionName, }: {
|
|
14
|
+
siteDir: string;
|
|
15
|
+
locale: string;
|
|
16
|
+
pluginId: string;
|
|
17
|
+
versionName: string;
|
|
18
|
+
}): string;
|
|
19
|
+
/** `community` => `[siteDir]/community_versions.json` */
|
|
20
|
+
export declare function getVersionsFilePath(siteDir: string, pluginId: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Reads the plugin's respective `versions.json` file, and returns its content.
|
|
23
|
+
*
|
|
24
|
+
* @throws Throws if validation fails, i.e. `versions.json` doesn't contain an
|
|
25
|
+
* array of valid version names.
|
|
26
|
+
*/
|
|
27
|
+
export declare function readVersionsFile(siteDir: string, pluginId: string): Promise<string[] | null>;
|
|
28
|
+
/**
|
|
29
|
+
* Reads the `versions.json` file, and returns an ordered list of version names.
|
|
30
|
+
*
|
|
31
|
+
* - If `disableVersioning` is turned on, it will return `["current"]` (requires
|
|
32
|
+
* `includeCurrentVersion` to be true);
|
|
33
|
+
* - If `includeCurrentVersion` is turned on, "current" will be inserted at the
|
|
34
|
+
* beginning, if not already there.
|
|
35
|
+
*
|
|
36
|
+
* You need to use {@link filterVersions} after this.
|
|
37
|
+
*
|
|
38
|
+
* @throws Throws an error if `disableVersioning: true` but `versions.json`
|
|
39
|
+
* doesn't exist (i.e. site is not versioned)
|
|
40
|
+
* @throws Throws an error if versions list is empty (empty `versions.json` or
|
|
41
|
+
* `disableVersioning` is true, and not including current version)
|
|
42
|
+
*/
|
|
43
|
+
export declare function readVersionNames(siteDir: string, options: PluginOptions): Promise<string[]>;
|
|
44
|
+
/**
|
|
45
|
+
* Gets the path-related version metadata.
|
|
46
|
+
*
|
|
47
|
+
* @throws Throws if the resolved docs folder or sidebars file doesn't exist.
|
|
48
|
+
* Does not throw if a versioned sidebar is missing (since we don't create empty
|
|
49
|
+
* files).
|
|
50
|
+
*/
|
|
51
|
+
export declare function getVersionMetadataPaths({ versionName, context, options, }: VersionContext): Promise<Pick<VersionMetadata, 'contentPath' | 'contentPathLocalized' | 'sidebarFilePath'>>;
|
|
@@ -0,0 +1,143 @@
|
|
|
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.getVersionMetadataPaths = exports.readVersionNames = exports.readVersionsFile = exports.getVersionsFilePath = exports.getDocsDirPathLocalized = exports.getVersionSidebarsPath = exports.getVersionDocsDirPath = void 0;
|
|
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"));
|
|
13
|
+
const utils_1 = require("@docusaurus/utils");
|
|
14
|
+
const constants_1 = require("../constants");
|
|
15
|
+
const validation_1 = require("./validation");
|
|
16
|
+
/** Add a prefix like `community_version-1.0.0`. No-op for default instance. */
|
|
17
|
+
function addPluginIdPrefix(fileOrDir, pluginId) {
|
|
18
|
+
return pluginId === utils_1.DEFAULT_PLUGIN_ID
|
|
19
|
+
? fileOrDir
|
|
20
|
+
: `${pluginId}_${fileOrDir}`;
|
|
21
|
+
}
|
|
22
|
+
/** `[siteDir]/community_versioned_docs/version-1.0.0` */
|
|
23
|
+
function getVersionDocsDirPath(siteDir, pluginId, versionName) {
|
|
24
|
+
return path_1.default.join(siteDir, addPluginIdPrefix(constants_1.VERSIONED_DOCS_DIR, pluginId), `version-${versionName}`);
|
|
25
|
+
}
|
|
26
|
+
exports.getVersionDocsDirPath = getVersionDocsDirPath;
|
|
27
|
+
/** `[siteDir]/community_versioned_sidebars/version-1.0.0-sidebars.json` */
|
|
28
|
+
function getVersionSidebarsPath(siteDir, pluginId, versionName) {
|
|
29
|
+
return path_1.default.join(siteDir, addPluginIdPrefix(constants_1.VERSIONED_SIDEBARS_DIR, pluginId), `version-${versionName}-sidebars.json`);
|
|
30
|
+
}
|
|
31
|
+
exports.getVersionSidebarsPath = getVersionSidebarsPath;
|
|
32
|
+
function getDocsDirPathLocalized({ siteDir, locale, pluginId, versionName, }) {
|
|
33
|
+
return (0, utils_1.getPluginI18nPath)({
|
|
34
|
+
siteDir,
|
|
35
|
+
locale,
|
|
36
|
+
pluginName: 'docusaurus-plugin-content-docs',
|
|
37
|
+
pluginId,
|
|
38
|
+
subPaths: [
|
|
39
|
+
versionName === constants_1.CURRENT_VERSION_NAME
|
|
40
|
+
? constants_1.CURRENT_VERSION_NAME
|
|
41
|
+
: `version-${versionName}`,
|
|
42
|
+
],
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
exports.getDocsDirPathLocalized = getDocsDirPathLocalized;
|
|
46
|
+
/** `community` => `[siteDir]/community_versions.json` */
|
|
47
|
+
function getVersionsFilePath(siteDir, pluginId) {
|
|
48
|
+
return path_1.default.join(siteDir, addPluginIdPrefix(constants_1.VERSIONS_JSON_FILE, pluginId));
|
|
49
|
+
}
|
|
50
|
+
exports.getVersionsFilePath = getVersionsFilePath;
|
|
51
|
+
/**
|
|
52
|
+
* Reads the plugin's respective `versions.json` file, and returns its content.
|
|
53
|
+
*
|
|
54
|
+
* @throws Throws if validation fails, i.e. `versions.json` doesn't contain an
|
|
55
|
+
* array of valid version names.
|
|
56
|
+
*/
|
|
57
|
+
async function readVersionsFile(siteDir, pluginId) {
|
|
58
|
+
const versionsFilePath = getVersionsFilePath(siteDir, pluginId);
|
|
59
|
+
if (await fs_extra_1.default.pathExists(versionsFilePath)) {
|
|
60
|
+
const content = await fs_extra_1.default.readJSON(versionsFilePath);
|
|
61
|
+
(0, validation_1.validateVersionNames)(content);
|
|
62
|
+
return content;
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
exports.readVersionsFile = readVersionsFile;
|
|
67
|
+
/**
|
|
68
|
+
* Reads the `versions.json` file, and returns an ordered list of version names.
|
|
69
|
+
*
|
|
70
|
+
* - If `disableVersioning` is turned on, it will return `["current"]` (requires
|
|
71
|
+
* `includeCurrentVersion` to be true);
|
|
72
|
+
* - If `includeCurrentVersion` is turned on, "current" will be inserted at the
|
|
73
|
+
* beginning, if not already there.
|
|
74
|
+
*
|
|
75
|
+
* You need to use {@link filterVersions} after this.
|
|
76
|
+
*
|
|
77
|
+
* @throws Throws an error if `disableVersioning: true` but `versions.json`
|
|
78
|
+
* doesn't exist (i.e. site is not versioned)
|
|
79
|
+
* @throws Throws an error if versions list is empty (empty `versions.json` or
|
|
80
|
+
* `disableVersioning` is true, and not including current version)
|
|
81
|
+
*/
|
|
82
|
+
async function readVersionNames(siteDir, options) {
|
|
83
|
+
const versionFileContent = await readVersionsFile(siteDir, options.id);
|
|
84
|
+
if (!versionFileContent && options.disableVersioning) {
|
|
85
|
+
throw new Error(`Docs: using "disableVersioning: true" option on a non-versioned site does not make sense.`);
|
|
86
|
+
}
|
|
87
|
+
const versions = options.disableVersioning ? [] : versionFileContent ?? [];
|
|
88
|
+
// We add the current version at the beginning, unless:
|
|
89
|
+
// - user don't want to; or
|
|
90
|
+
// - it's already been explicitly added to versions.json
|
|
91
|
+
if (options.includeCurrentVersion &&
|
|
92
|
+
!versions.includes(constants_1.CURRENT_VERSION_NAME)) {
|
|
93
|
+
versions.unshift(constants_1.CURRENT_VERSION_NAME);
|
|
94
|
+
}
|
|
95
|
+
if (versions.length === 0) {
|
|
96
|
+
throw new Error(`It is not possible to use docs without any version. No version is included because you have requested to not include ${path_1.default.resolve(options.path)} through "includeCurrentVersion: false", while ${options.disableVersioning
|
|
97
|
+
? 'versioning is disabled with "disableVersioning: true"'
|
|
98
|
+
: `the versions file is empty/non-existent`}.`);
|
|
99
|
+
}
|
|
100
|
+
return versions;
|
|
101
|
+
}
|
|
102
|
+
exports.readVersionNames = readVersionNames;
|
|
103
|
+
/**
|
|
104
|
+
* Gets the path-related version metadata.
|
|
105
|
+
*
|
|
106
|
+
* @throws Throws if the resolved docs folder or sidebars file doesn't exist.
|
|
107
|
+
* Does not throw if a versioned sidebar is missing (since we don't create empty
|
|
108
|
+
* files).
|
|
109
|
+
*/
|
|
110
|
+
async function getVersionMetadataPaths({ versionName, context, options, }) {
|
|
111
|
+
const isCurrent = versionName === constants_1.CURRENT_VERSION_NAME;
|
|
112
|
+
const contentPathLocalized = getDocsDirPathLocalized({
|
|
113
|
+
siteDir: context.siteDir,
|
|
114
|
+
locale: context.i18n.currentLocale,
|
|
115
|
+
pluginId: options.id,
|
|
116
|
+
versionName,
|
|
117
|
+
});
|
|
118
|
+
const contentPath = isCurrent
|
|
119
|
+
? path_1.default.resolve(context.siteDir, options.path)
|
|
120
|
+
: getVersionDocsDirPath(context.siteDir, options.id, versionName);
|
|
121
|
+
const sidebarFilePath = isCurrent
|
|
122
|
+
? options.sidebarPath
|
|
123
|
+
: getVersionSidebarsPath(context.siteDir, options.id, versionName);
|
|
124
|
+
if (!(await fs_extra_1.default.pathExists(contentPath))) {
|
|
125
|
+
throw new Error(`The docs folder does not exist for version "${versionName}". A docs folder is expected to be found at ${path_1.default.relative(context.siteDir, contentPath)}.`);
|
|
126
|
+
}
|
|
127
|
+
// If the current version defines a path to a sidebar file that does not
|
|
128
|
+
// exist, we throw! Note: for versioned sidebars, the file may not exist (as
|
|
129
|
+
// we prefer to not create it rather than to create an empty file)
|
|
130
|
+
// See https://github.com/facebook/docusaurus/issues/3366
|
|
131
|
+
// See https://github.com/facebook/docusaurus/pull/4775
|
|
132
|
+
if (versionName === constants_1.CURRENT_VERSION_NAME &&
|
|
133
|
+
typeof sidebarFilePath === 'string' &&
|
|
134
|
+
!(await fs_extra_1.default.pathExists(sidebarFilePath))) {
|
|
135
|
+
throw new Error(`The path to the sidebar file does not exist at "${path_1.default.relative(context.siteDir, sidebarFilePath)}".
|
|
136
|
+
Please set the docs "sidebarPath" field in your config file to:
|
|
137
|
+
- a sidebars path that exists
|
|
138
|
+
- false: to disable the sidebar
|
|
139
|
+
- undefined: for Docusaurus to generate it automatically`);
|
|
140
|
+
}
|
|
141
|
+
return { contentPath, contentPathLocalized, sidebarFilePath };
|
|
142
|
+
}
|
|
143
|
+
exports.getVersionMetadataPaths = getVersionMetadataPaths;
|