Compare commits

...

2 Commits

Author SHA1 Message Date
Joshua Chen 80fe374f74
Fix tests 2022-10-26 02:55:39 -04:00
Joshua Chen 0835d5f7e1
fix(content-docs): translate generated index pagination title 2022-10-26 02:03:20 -04:00
10 changed files with 233 additions and 423 deletions

View File

@ -45,136 +45,6 @@ Available document ids are:
exports[`simple website content 1`] = `
{
"description": "Images",
"draft": false,
"editUrl": undefined,
"formattedLastUpdatedAt": undefined,
"frontMatter": {
"id": "baz",
"pagination_label": "baz pagination_label",
"slug": "bazSlug.html",
"tags": [
"tag 1",
"tag-1",
{
"label": "tag 2",
"permalink": "tag2-custom-permalink",
},
],
"title": "baz",
},
"id": "foo/baz",
"lastUpdatedAt": undefined,
"lastUpdatedBy": undefined,
"next": {
"permalink": "/docs/category/slugs",
"title": "Slugs",
},
"permalink": "/docs/foo/bazSlug.html",
"previous": {
"permalink": "/docs/foo/bar",
"title": "Bar",
},
"sidebar": "docs",
"sidebarPosition": undefined,
"slug": "/foo/bazSlug.html",
"source": "@site/docs/foo/baz.md",
"sourceDirName": "foo",
"tags": [
{
"label": "tag 1",
"permalink": "/docs/tags/tag-1",
},
{
"label": "tag 2",
"permalink": "/docs/tags/tag2-custom-permalink",
},
],
"title": "baz",
"unversionedId": "foo/baz",
"version": "current",
}
`;
exports[`simple website content 2`] = `
{
"description": "Hi, Endilie here :)",
"draft": false,
"editUrl": undefined,
"formattedLastUpdatedAt": undefined,
"frontMatter": {
"id": "hello",
"sidebar_label": "Hello sidebar_label",
"slug": "/",
"tags": [
"tag-1",
"tag 3",
],
"title": "Hello, World !",
},
"id": "hello",
"lastUpdatedAt": undefined,
"lastUpdatedBy": undefined,
"next": undefined,
"permalink": "/docs/",
"previous": {
"permalink": "/docs/headingAsTitle",
"title": "My heading as title",
},
"sidebar": "docs",
"sidebarPosition": undefined,
"slug": "/",
"source": "@site/docs/hello.md",
"sourceDirName": ".",
"tags": [
{
"label": "tag-1",
"permalink": "/docs/tags/tag-1",
},
{
"label": "tag 3",
"permalink": "/docs/tags/tag-3",
},
],
"title": "Hello, World !",
"unversionedId": "hello",
"version": "current",
}
`;
exports[`simple website content 3`] = `
{
"description": "This is custom description",
"draft": false,
"editUrl": undefined,
"formattedLastUpdatedAt": undefined,
"frontMatter": {
"description": "This is custom description",
"id": "bar",
"pagination_next": null,
"pagination_prev": null,
"title": "Bar",
},
"id": "foo/bar",
"lastUpdatedAt": undefined,
"lastUpdatedBy": undefined,
"next": undefined,
"permalink": "/docs/foo/bar",
"previous": undefined,
"sidebar": "docs",
"sidebarPosition": undefined,
"slug": "/foo/bar",
"source": "@site/docs/foo/bar.md",
"sourceDirName": "foo",
"tags": [],
"title": "Bar",
"unversionedId": "foo/bar",
"version": "current",
}
`;
exports[`simple website content 4`] = `
{
"docs": [
{
"collapsed": true,
@ -261,6 +131,118 @@ exports[`simple website content 4`] = `
}
`;
exports[`simple website content 2`] = `
{
"description": "Images",
"draft": false,
"frontMatter": {
"id": "baz",
"pagination_label": "baz pagination_label",
"slug": "bazSlug.html",
"tags": [
"tag 1",
"tag-1",
{
"label": "tag 2",
"permalink": "tag2-custom-permalink",
},
],
"title": "baz",
},
"id": "foo/baz",
"next": {
"permalink": "/docs/category/slugs",
"title": "Slugs",
},
"permalink": "/docs/foo/bazSlug.html",
"previous": {
"permalink": "/docs/foo/bar",
"title": "Bar",
},
"sidebar": "docs",
"slug": "/foo/bazSlug.html",
"source": "@site/docs/foo/baz.md",
"sourceDirName": "foo",
"tags": [
{
"label": "tag 1",
"permalink": "/docs/tags/tag-1",
},
{
"label": "tag 2",
"permalink": "/docs/tags/tag2-custom-permalink",
},
],
"title": "baz",
"unversionedId": "foo/baz",
"version": "current",
}
`;
exports[`simple website content 3`] = `
{
"description": "Hi, Endilie here :)",
"draft": false,
"frontMatter": {
"id": "hello",
"sidebar_label": "Hello sidebar_label",
"slug": "/",
"tags": [
"tag-1",
"tag 3",
],
"title": "Hello, World !",
},
"id": "hello",
"permalink": "/docs/",
"previous": {
"permalink": "/docs/headingAsTitle",
"title": "My heading as title",
},
"sidebar": "docs",
"slug": "/",
"source": "@site/docs/hello.md",
"sourceDirName": ".",
"tags": [
{
"label": "tag-1",
"permalink": "/docs/tags/tag-1",
},
{
"label": "tag 3",
"permalink": "/docs/tags/tag-3",
},
],
"title": "Hello, World !",
"unversionedId": "hello",
"version": "current",
}
`;
exports[`simple website content 4`] = `
{
"description": "This is custom description",
"draft": false,
"frontMatter": {
"description": "This is custom description",
"id": "bar",
"pagination_next": null,
"pagination_prev": null,
"title": "Bar",
},
"id": "foo/bar",
"permalink": "/docs/foo/bar",
"sidebar": "docs",
"slug": "/foo/bar",
"source": "@site/docs/foo/bar.md",
"sourceDirName": "foo",
"tags": [],
"title": "Bar",
"unversionedId": "foo/bar",
"version": "current",
}
`;
exports[`simple website content 5`] = `
{
"pluginName": {
@ -1774,13 +1756,7 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha
"id": "getting-started",
"lastUpdatedAt": undefined,
"lastUpdatedBy": undefined,
"next": {
"permalink": "/docs/installation",
"title": "Installation",
},
"permalink": "/docs/getting-started",
"previous": undefined,
"sidebar": "defaultSidebar",
"sidebarPosition": 0,
"slug": "/getting-started",
"source": "@site/docs/0-getting-started.md",
@ -1802,16 +1778,7 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha
"id": "installation",
"lastUpdatedAt": undefined,
"lastUpdatedBy": undefined,
"next": {
"permalink": "/docs/Guides/guide1",
"title": "Guide 1",
},
"permalink": "/docs/installation",
"previous": {
"permalink": "/docs/getting-started",
"title": "Getting Started",
},
"sidebar": "defaultSidebar",
"sidebarPosition": 1,
"slug": "/installation",
"source": "@site/docs/1-installation.md",
@ -1836,16 +1803,7 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha
"id": "Guides/guide1",
"lastUpdatedAt": undefined,
"lastUpdatedBy": undefined,
"next": {
"permalink": "/docs/Guides/guide2",
"title": "Guide 2",
},
"permalink": "/docs/Guides/guide1",
"previous": {
"permalink": "/docs/installation",
"title": "Installation",
},
"sidebar": "defaultSidebar",
"sidebarPosition": 1,
"slug": "/Guides/guide1",
"source": "@site/docs/Guides/z-guide1.md",
@ -1869,16 +1827,7 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha
"id": "Guides/guide2",
"lastUpdatedAt": undefined,
"lastUpdatedBy": undefined,
"next": {
"permalink": "/docs/Guides/guide2.5",
"title": "Guide 2.5",
},
"permalink": "/docs/Guides/guide2",
"previous": {
"permalink": "/docs/Guides/guide1",
"title": "Guide 1",
},
"sidebar": "defaultSidebar",
"sidebarPosition": 2,
"slug": "/Guides/guide2",
"source": "@site/docs/Guides/02-guide2.md",
@ -1903,16 +1852,7 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha
"id": "Guides/guide2.5",
"lastUpdatedAt": undefined,
"lastUpdatedBy": undefined,
"next": {
"permalink": "/docs/Guides/guide3",
"title": "Guide 3",
},
"permalink": "/docs/Guides/guide2.5",
"previous": {
"permalink": "/docs/Guides/guide2",
"title": "Guide 2",
},
"sidebar": "defaultSidebar",
"sidebarPosition": 2.5,
"slug": "/Guides/guide2.5",
"source": "@site/docs/Guides/0-guide2.5.md",
@ -1937,16 +1877,7 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha
"id": "Guides/guide3",
"lastUpdatedAt": undefined,
"lastUpdatedBy": undefined,
"next": {
"permalink": "/docs/Guides/guide4",
"title": "Guide 4",
},
"permalink": "/docs/Guides/guide3",
"previous": {
"permalink": "/docs/Guides/guide2.5",
"title": "Guide 2.5",
},
"sidebar": "defaultSidebar",
"sidebarPosition": 3,
"slug": "/Guides/guide3",
"source": "@site/docs/Guides/guide3.md",
@ -1970,16 +1901,7 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha
"id": "Guides/guide4",
"lastUpdatedAt": undefined,
"lastUpdatedBy": undefined,
"next": {
"permalink": "/docs/Guides/guide5",
"title": "Guide 5",
},
"permalink": "/docs/Guides/guide4",
"previous": {
"permalink": "/docs/Guides/guide3",
"title": "Guide 3",
},
"sidebar": "defaultSidebar",
"sidebarPosition": undefined,
"slug": "/Guides/guide4",
"source": "@site/docs/Guides/a-guide4.md",
@ -2003,16 +1925,7 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha
"id": "Guides/guide5",
"lastUpdatedAt": undefined,
"lastUpdatedBy": undefined,
"next": {
"permalink": "/docs/API/api-overview",
"title": "API Overview",
},
"permalink": "/docs/Guides/guide5",
"previous": {
"permalink": "/docs/Guides/guide4",
"title": "Guide 4",
},
"sidebar": "defaultSidebar",
"sidebarPosition": undefined,
"slug": "/Guides/guide5",
"source": "@site/docs/Guides/b-guide5.md",
@ -2034,16 +1947,7 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha
"id": "API/api-overview",
"lastUpdatedAt": undefined,
"lastUpdatedBy": undefined,
"next": {
"permalink": "/docs/API/Core APIs/Client API",
"title": "Client API",
},
"permalink": "/docs/API/api-overview",
"previous": {
"permalink": "/docs/Guides/guide5",
"title": "Guide 5",
},
"sidebar": "defaultSidebar",
"sidebarPosition": 0,
"slug": "/API/api-overview",
"source": "@site/docs/3-API/00_api-overview.md",
@ -2065,16 +1969,7 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha
"id": "API/Core APIs/Client API",
"lastUpdatedAt": undefined,
"lastUpdatedBy": undefined,
"next": {
"permalink": "/docs/API/Core APIs/Server API",
"title": "Server API",
},
"permalink": "/docs/API/Core APIs/Client API",
"previous": {
"permalink": "/docs/API/api-overview",
"title": "API Overview",
},
"sidebar": "defaultSidebar",
"sidebarPosition": 0,
"slug": "/API/Core APIs/Client API",
"source": "@site/docs/3-API/01_Core APIs/0 --- Client API.md",
@ -2096,16 +1991,7 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha
"id": "API/Core APIs/Server API",
"lastUpdatedAt": undefined,
"lastUpdatedBy": undefined,
"next": {
"permalink": "/docs/API/Extension APIs/Plugin API",
"title": "Plugin API",
},
"permalink": "/docs/API/Core APIs/Server API",
"previous": {
"permalink": "/docs/API/Core APIs/Client API",
"title": "Client API",
},
"sidebar": "defaultSidebar",
"sidebarPosition": 1,
"slug": "/API/Core APIs/Server API",
"source": "@site/docs/3-API/01_Core APIs/1 --- Server API.md",
@ -2127,16 +2013,7 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha
"id": "API/Extension APIs/Plugin API",
"lastUpdatedAt": undefined,
"lastUpdatedBy": undefined,
"next": {
"permalink": "/docs/API/Extension APIs/Theme API",
"title": "Theme API",
},
"permalink": "/docs/API/Extension APIs/Plugin API",
"previous": {
"permalink": "/docs/API/Core APIs/Server API",
"title": "Server API",
},
"sidebar": "defaultSidebar",
"sidebarPosition": 0,
"slug": "/API/Extension APIs/Plugin API",
"source": "@site/docs/3-API/02_Extension APIs/0. Plugin API.md",
@ -2158,16 +2035,7 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha
"id": "API/Extension APIs/Theme API",
"lastUpdatedAt": undefined,
"lastUpdatedBy": undefined,
"next": {
"permalink": "/docs/API/api-end",
"title": "API End",
},
"permalink": "/docs/API/Extension APIs/Theme API",
"previous": {
"permalink": "/docs/API/Extension APIs/Plugin API",
"title": "Plugin API",
},
"sidebar": "defaultSidebar",
"sidebarPosition": 1,
"slug": "/API/Extension APIs/Theme API",
"source": "@site/docs/3-API/02_Extension APIs/1. Theme API.md",
@ -2189,13 +2057,7 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha
"id": "API/api-end",
"lastUpdatedAt": undefined,
"lastUpdatedBy": undefined,
"next": undefined,
"permalink": "/docs/API/api-end",
"previous": {
"permalink": "/docs/API/Extension APIs/Theme API",
"title": "Theme API",
},
"sidebar": "defaultSidebar",
"sidebarPosition": 3,
"slug": "/API/api-end",
"source": "@site/docs/3-API/03_api-end.md",
@ -2369,13 +2231,7 @@ exports[`site with partial autogenerated sidebars docs in partially generated si
"id": "API/api-end",
"lastUpdatedAt": undefined,
"lastUpdatedBy": undefined,
"next": {
"permalink": "/docs/API/api-overview",
"title": "API Overview",
},
"permalink": "/docs/API/api-end",
"previous": undefined,
"sidebar": "someSidebar",
"sidebarPosition": 3,
"slug": "/API/api-end",
"source": "@site/docs/3-API/03_api-end.md",
@ -2397,16 +2253,7 @@ exports[`site with partial autogenerated sidebars docs in partially generated si
"id": "API/api-overview",
"lastUpdatedAt": undefined,
"lastUpdatedBy": undefined,
"next": {
"permalink": "/docs/API/Extension APIs/Plugin API",
"title": "Plugin API",
},
"permalink": "/docs/API/api-overview",
"previous": {
"permalink": "/docs/API/api-end",
"title": "API End",
},
"sidebar": "someSidebar",
"sidebarPosition": 0,
"slug": "/API/api-overview",
"source": "@site/docs/3-API/00_api-overview.md",
@ -2428,16 +2275,7 @@ exports[`site with partial autogenerated sidebars docs in partially generated si
"id": "API/Extension APIs/Plugin API",
"lastUpdatedAt": undefined,
"lastUpdatedBy": undefined,
"next": {
"permalink": "/docs/API/Extension APIs/Theme API",
"title": "Theme API",
},
"permalink": "/docs/API/Extension APIs/Plugin API",
"previous": {
"permalink": "/docs/API/api-overview",
"title": "API Overview",
},
"sidebar": "someSidebar",
"sidebarPosition": 0,
"slug": "/API/Extension APIs/Plugin API",
"source": "@site/docs/3-API/02_Extension APIs/0. Plugin API.md",
@ -2459,13 +2297,7 @@ exports[`site with partial autogenerated sidebars docs in partially generated si
"id": "API/Extension APIs/Theme API",
"lastUpdatedAt": undefined,
"lastUpdatedBy": undefined,
"next": undefined,
"permalink": "/docs/API/Extension APIs/Theme API",
"previous": {
"permalink": "/docs/API/Extension APIs/Plugin API",
"title": "Plugin API",
},
"sidebar": "someSidebar",
"sidebarPosition": 1,
"slug": "/API/Extension APIs/Theme API",
"source": "@site/docs/3-API/02_Extension APIs/1. Theme API.md",
@ -2513,19 +2345,12 @@ exports[`versioned website (community) content 1`] = `
{
"description": "Team current version (translated)",
"draft": false,
"editUrl": undefined,
"formattedLastUpdatedAt": undefined,
"frontMatter": {
"title": "Team title translated",
},
"id": "team",
"lastUpdatedAt": undefined,
"lastUpdatedBy": undefined,
"next": undefined,
"permalink": "/community/next/team",
"previous": undefined,
"sidebar": "community",
"sidebarPosition": undefined,
"slug": "/team",
"source": "@site/i18n/en/docusaurus-plugin-content-docs-community/current/team.md",
"sourceDirName": ".",
@ -2538,26 +2363,21 @@ exports[`versioned website (community) content 1`] = `
exports[`versioned website (community) content 2`] = `
{
"description": "Team 1.0.0",
"description": "Team current version (translated)",
"draft": false,
"editUrl": undefined,
"formattedLastUpdatedAt": undefined,
"frontMatter": {},
"id": "version-1.0.0/team",
"lastUpdatedAt": undefined,
"lastUpdatedBy": undefined,
"next": undefined,
"permalink": "/community/team",
"previous": undefined,
"sidebar": "version-1.0.0/community",
"sidebarPosition": undefined,
"frontMatter": {
"title": "Team title translated",
},
"id": "team",
"permalink": "/community/next/team",
"sidebar": "community",
"slug": "/team",
"source": "@site/community_versioned_docs/version-1.0.0/team.md",
"source": "@site/i18n/en/docusaurus-plugin-content-docs-community/current/team.md",
"sourceDirName": ".",
"tags": [],
"title": "team",
"title": "Team title translated",
"unversionedId": "team",
"version": "1.0.0",
"version": "current",
}
`;
@ -2818,8 +2638,6 @@ exports[`versioned website content 1`] = `
{
"description": "This is next version of bar.",
"draft": false,
"editUrl": undefined,
"formattedLastUpdatedAt": undefined,
"frontMatter": {
"slug": "barSlug",
"tags": [
@ -2832,16 +2650,12 @@ exports[`versioned website content 1`] = `
],
},
"id": "foo/bar",
"lastUpdatedAt": undefined,
"lastUpdatedBy": undefined,
"next": {
"permalink": "/docs/next/",
"title": "hello",
},
"permalink": "/docs/next/foo/barSlug",
"previous": undefined,
"sidebar": "docs",
"sidebarPosition": undefined,
"slug": "/foo/barSlug",
"source": "@site/docs/foo/bar.md",
"sourceDirName": "foo",
@ -2867,52 +2681,18 @@ exports[`versioned website content 1`] = `
exports[`versioned website content 2`] = `
{
"description": "Bar 1.0.1 !",
"draft": false,
"editUrl": undefined,
"formattedLastUpdatedAt": undefined,
"frontMatter": {},
"id": "version-1.0.1/foo/bar",
"lastUpdatedAt": undefined,
"lastUpdatedBy": undefined,
"next": {
"permalink": "/docs/",
"title": "hello",
},
"permalink": "/docs/foo/bar",
"previous": undefined,
"sidebar": "VersionedSideBarNameDoesNotMatter/docs",
"sidebarPosition": undefined,
"slug": "/foo/bar",
"source": "@site/versioned_docs/version-1.0.1/foo/bar.md",
"sourceDirName": "foo",
"tags": [],
"title": "bar",
"unversionedId": "foo/bar",
"version": "1.0.1",
}
`;
exports[`versioned website content 3`] = `
{
"description": "Hello next !",
"draft": false,
"editUrl": undefined,
"formattedLastUpdatedAt": undefined,
"frontMatter": {
"slug": "/",
},
"id": "hello",
"lastUpdatedAt": undefined,
"lastUpdatedBy": undefined,
"next": undefined,
"permalink": "/docs/next/",
"previous": {
"permalink": "/docs/next/foo/barSlug",
"title": "bar",
},
"sidebar": "docs",
"sidebarPosition": undefined,
"slug": "/",
"source": "@site/docs/hello.md",
"sourceDirName": ".",
@ -2923,33 +2703,72 @@ exports[`versioned website content 3`] = `
}
`;
exports[`versioned website content 3`] = `
{
"description": "This is next version of bar.",
"draft": false,
"frontMatter": {
"slug": "barSlug",
"tags": [
"barTag 1",
"barTag-2",
{
"label": "barTag 3",
"permalink": "barTag-3-permalink",
},
],
},
"id": "foo/bar",
"next": {
"permalink": "/docs/next/",
"title": "hello",
},
"permalink": "/docs/next/foo/barSlug",
"sidebar": "docs",
"slug": "/foo/barSlug",
"source": "@site/docs/foo/bar.md",
"sourceDirName": "foo",
"tags": [
{
"label": "barTag 1",
"permalink": "/docs/next/tags/bar-tag-1",
},
{
"label": "barTag-2",
"permalink": "/docs/next/tags/bar-tag-2",
},
{
"label": "barTag 3",
"permalink": "/docs/next/tags/barTag-3-permalink",
},
],
"title": "bar",
"unversionedId": "foo/bar",
"version": "current",
}
`;
exports[`versioned website content 4`] = `
{
"description": "Hello 1.0.1 !",
"description": "Hello next !",
"draft": false,
"editUrl": undefined,
"formattedLastUpdatedAt": undefined,
"frontMatter": {
"slug": "/",
},
"id": "version-1.0.1/hello",
"lastUpdatedAt": undefined,
"lastUpdatedBy": undefined,
"next": undefined,
"permalink": "/docs/",
"id": "hello",
"permalink": "/docs/next/",
"previous": {
"permalink": "/docs/foo/bar",
"permalink": "/docs/next/foo/barSlug",
"title": "bar",
},
"sidebar": "VersionedSideBarNameDoesNotMatter/docs",
"sidebarPosition": undefined,
"sidebar": "docs",
"slug": "/",
"source": "@site/versioned_docs/version-1.0.1/hello.md",
"source": "@site/docs/hello.md",
"sourceDirName": ".",
"tags": [],
"title": "hello",
"unversionedId": "hello",
"version": "1.0.1",
"version": "current",
}
`;
@ -2957,12 +2776,8 @@ exports[`versioned website content 5`] = `
{
"description": "Baz 1.0.0 ! This will be deleted in next subsequent versions.",
"draft": false,
"editUrl": undefined,
"formattedLastUpdatedAt": undefined,
"frontMatter": {},
"id": "version-1.0.0/foo/baz",
"lastUpdatedAt": undefined,
"lastUpdatedBy": undefined,
"next": {
"permalink": "/docs/1.0.0/",
"title": "hello",
@ -2973,7 +2788,6 @@ exports[`versioned website content 5`] = `
"title": "bar",
},
"sidebar": "version-1.0.0/docs",
"sidebarPosition": undefined,
"slug": "/foo/baz",
"source": "@site/versioned_docs/version-1.0.0/foo/baz.md",
"sourceDirName": "foo",

View File

@ -223,6 +223,7 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
"drafts": [],
"isLast": true,
"label": "current label (translated)",
"noIndex": false,
"path": "/docs/",
"routePriority": undefined,
"sidebarFilePath": "any",
@ -399,6 +400,7 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
"drafts": [],
"isLast": true,
"label": "2.0.0 label (translated)",
"noIndex": false,
"path": "/docs/",
"routePriority": undefined,
"sidebarFilePath": "any",
@ -575,6 +577,7 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
"drafts": [],
"isLast": true,
"label": "1.0.0 label (translated)",
"noIndex": false,
"path": "/docs/",
"routePriority": undefined,
"sidebarFilePath": "any",

View File

@ -25,6 +25,7 @@ import {DisabledSidebars} from '../sidebars';
import * as cliDocs from '../cli';
import {validateOptions} from '../options';
import type {FullVersion} from '../types';
import type {RouteConfig, Validate, Plugin} from '@docusaurus/types';
import type {
LoadedVersion,
@ -81,19 +82,19 @@ const createFakeActions = (contentDir: string) => {
},
};
// Query by prefix, because files have a hash at the end so it's not
// Query by substring, because files have a hash at the end so it's not
// convenient to query by full filename
function getCreatedDataByPrefix(prefix: string) {
function searchCreatedData(search: string) {
const entry = Object.entries(dataContainer).find(([key]) =>
key.startsWith(prefix),
key.includes(search),
);
if (!entry) {
throw new Error(`No created entry found for prefix "${prefix}".
throw new Error(`No created entry found for substring "${search}".
Entries created:
- ${Object.keys(dataContainer).join('\n- ')}
`);
}
return JSON.parse(entry[1] as string) as PropSidebars;
return JSON.parse(entry[1] as string) as unknown;
}
// Extra fns useful for tests!
@ -101,14 +102,23 @@ Entries created:
getGlobalData: () => globalDataContainer,
getRouteConfigs: () => routeConfigs,
checkVersionMetadataPropCreated: (version: LoadedVersion | undefined) => {
checkVersionMetadataPropCreated: (
version: LoadedVersion | undefined,
docIds: string[],
) => {
if (!version) {
throw new Error('Version not found');
}
const versionMetadataProp = getCreatedDataByPrefix(
const versionMetadataProp = searchCreatedData(
`version-${_.kebabCase(version.versionName)}-metadata-prop`,
) as PropSidebars;
expect(versionMetadataProp.docsSidebars).toEqual(
toSidebarsProp(version as FullVersion),
);
expect(versionMetadataProp.docsSidebars).toEqual(toSidebarsProp(version));
docIds.forEach((id) => {
const docMetadataProp = searchCreatedData(_.kebabCase(id));
expect(docMetadataProp).toMatchSnapshot();
});
},
expectSnapshot: () => {
@ -142,7 +152,11 @@ describe('sidebar', () => {
},
}),
);
await expect(plugin.loadContent!()).rejects.toThrowErrorMatchingSnapshot();
const content = await plugin.loadContent!();
const {actions} = createFakeActions(siteDir);
await expect(
plugin.contentLoaded!({content, actions, allContent: {}}),
).rejects.toThrowErrorMatchingSnapshot();
});
it('site with wrong sidebar file path', async () => {
@ -327,12 +341,6 @@ describe('simple website', () => {
expect(content.loadedVersions).toHaveLength(1);
const [currentVersion] = content.loadedVersions;
expect(findDocById(currentVersion, 'foo/baz')).toMatchSnapshot();
expect(findDocById(currentVersion, 'hello')).toMatchSnapshot();
expect(getDocById(currentVersion, 'foo/bar')).toMatchSnapshot();
expect(currentVersion!.sidebars).toMatchSnapshot();
const {actions, utils} = createFakeActions(pluginContentDir);
@ -343,7 +351,11 @@ describe('simple website', () => {
allContent: {},
});
utils.checkVersionMetadataPropCreated(currentVersion);
utils.checkVersionMetadataPropCreated(currentVersion, [
'foo/baz',
'hello',
'foo/bar',
]);
utils.expectSnapshot();
@ -449,13 +461,6 @@ describe('versioned website', () => {
expect(findDocById(version101, 'foo/baz')).toBeUndefined();
expect(findDocById(versionWithSlugs, 'foo/baz')).toBeUndefined();
expect(getDocById(currentVersion, 'foo/bar')).toMatchSnapshot();
expect(getDocById(version101, 'foo/bar')).toMatchSnapshot();
expect(getDocById(currentVersion, 'hello')).toMatchSnapshot();
expect(getDocById(version101, 'hello')).toMatchSnapshot();
expect(getDocById(version100, 'foo/baz')).toMatchSnapshot();
expect(currentVersion!.sidebars).toMatchSnapshot(
'current version sidebars',
);
@ -472,10 +477,10 @@ describe('versioned website', () => {
allContent: {},
});
utils.checkVersionMetadataPropCreated(currentVersion);
utils.checkVersionMetadataPropCreated(version101);
utils.checkVersionMetadataPropCreated(version100);
utils.checkVersionMetadataPropCreated(versionWithSlugs);
utils.checkVersionMetadataPropCreated(currentVersion, ['foo/bar', 'hello']);
utils.checkVersionMetadataPropCreated(version101, ['foo/bar', 'hello']);
utils.checkVersionMetadataPropCreated(version100, ['foo/baz']);
utils.checkVersionMetadataPropCreated(versionWithSlugs, []);
utils.expectSnapshot();
});
@ -562,9 +567,6 @@ describe('versioned website (community)', () => {
expect(content.loadedVersions).toHaveLength(2);
const [currentVersion, version100] = content.loadedVersions;
expect(getDocById(currentVersion, 'team')).toMatchSnapshot();
expect(getDocById(version100, 'team')).toMatchSnapshot();
expect(currentVersion!.sidebars).toMatchSnapshot(
'current version sidebars',
);
@ -577,8 +579,8 @@ describe('versioned website (community)', () => {
allContent: {},
});
utils.checkVersionMetadataPropCreated(currentVersion);
utils.checkVersionMetadataPropCreated(version100);
utils.checkVersionMetadataPropCreated(currentVersion, ['team']);
utils.checkVersionMetadataPropCreated(version100, ['team']);
utils.expectSnapshot();
});
@ -608,7 +610,7 @@ describe('site with doc label', () => {
it('label in sidebar.json is used', async () => {
const {content} = await loadSite();
const loadedVersion = content.loadedVersions[0]!;
const sidebarProps = toSidebarsProp(loadedVersion);
const sidebarProps = toSidebarsProp(loadedVersion as FullVersion);
expect((sidebarProps.docs![0] as PropSidebarItemLink).label).toBe(
'Hello One',
@ -618,7 +620,7 @@ describe('site with doc label', () => {
it('sidebar_label in doc has higher precedence over label in sidebar.json', async () => {
const {content} = await loadSite();
const loadedVersion = content.loadedVersions[0]!;
const sidebarProps = toSidebarsProp(loadedVersion);
const sidebarProps = toSidebarsProp(loadedVersion as FullVersion);
expect((sidebarProps.docs![1] as PropSidebarItemLink).label).toBe(
'Hello 2 From Doc',

View File

@ -57,6 +57,7 @@ function createSampleVersion(
badge: true,
className: '',
drafts: [],
noIndex: false,
docs: [
createSampleDoc({id: 'doc1'}),
createSampleDoc({id: 'doc2'}),

View File

@ -36,7 +36,6 @@ import type {
LastUpdateData,
VersionMetadata,
DocFrontMatter,
LoadedVersion,
FileChange,
} from '@docusaurus/plugin-content-docs';
import type {LoadContext} from '@docusaurus/types';
@ -335,7 +334,7 @@ export function addDocNavigation(
docsBase: DocMetadataBase[],
sidebarsUtils: SidebarsUtils,
sidebarFilePath: string,
): LoadedVersion['docs'] {
): DocMetadata[] {
const docsById = createDocsByIdIndex(docsBase);
sidebarsUtils.checkSidebarsDocIds(

View File

@ -21,12 +21,7 @@ import {
} from '@docusaurus/utils';
import {loadSidebars, resolveSidebarPathOption} from './sidebars';
import {CategoryMetadataFilenamePattern} from './sidebars/generator';
import {
readVersionDocs,
processDocMetadata,
addDocNavigation,
type DocEnv,
} from './docs';
import {readVersionDocs, processDocMetadata, type DocEnv} from './docs';
import {readVersionsMetadata, toFullVersion} from './versions';
import {cliDocsVersionCommand} from './cli';
import {VERSIONS_JSON_FILE} from './constants';
@ -36,7 +31,6 @@ import {
getLoadedContentTranslationFiles,
} from './translations';
import {createAllRoutes} from './routes';
import {createSidebarsUtils} from './sidebars/utils';
import type {
PluginOptions,
@ -171,18 +165,7 @@ export default async function pluginContentDocs(
categoryLabelSlugger: createSlugger(),
});
const sidebarsUtils = createSidebarsUtils(sidebars);
return {
...versionMetadata,
docs: addDocNavigation(
docs,
sidebarsUtils,
versionMetadata.sidebarFilePath as string,
),
drafts,
sidebars,
};
return {...versionMetadata, docs, drafts, sidebars};
}
async function loadVersion(versionMetadata: VersionMetadata) {

View File

@ -559,8 +559,8 @@ declare module '@docusaurus/plugin-content-docs' {
};
export type LoadedVersion = VersionMetadata & {
docs: DocMetadata[];
drafts: DocMetadata[];
docs: DocMetadataBase[];
drafts: DocMetadataBase[];
sidebars: import('./sidebars/types').Sidebars;
};

View File

@ -7,7 +7,7 @@
import _ from 'lodash';
import {createDocsByIdIndex} from './docs';
import type {VersionTag, VersionTags} from './types';
import type {VersionTag, VersionTags, FullVersion} from './types';
import type {
SidebarItemDoc,
SidebarItem,
@ -25,10 +25,9 @@ import type {
PropSidebarItemLink,
PropVersionDocs,
DocMetadata,
LoadedVersion,
} from '@docusaurus/plugin-content-docs';
export function toSidebarsProp(loadedVersion: LoadedVersion): PropSidebars {
export function toSidebarsProp(loadedVersion: FullVersion): PropSidebars {
const docsById = createDocsByIdIndex(loadedVersion.docs);
function getDocById(docId: string): DocMetadata {
@ -119,7 +118,7 @@ Available document ids are:
);
}
function toVersionDocsProp(loadedVersion: LoadedVersion): PropVersionDocs {
function toVersionDocsProp(loadedVersion: FullVersion): PropVersionDocs {
return Object.fromEntries(
loadedVersion.docs.map((doc) => [
doc.unversionedId,
@ -135,7 +134,7 @@ function toVersionDocsProp(loadedVersion: LoadedVersion): PropVersionDocs {
export function toVersionMetadataProp(
pluginId: string,
loadedVersion: LoadedVersion,
loadedVersion: FullVersion,
): PropVersionMetadata {
return {
pluginId,

View File

@ -9,6 +9,7 @@ import type {BrokenMarkdownLink, Tag} from '@docusaurus/utils';
import type {
VersionMetadata,
LoadedVersion,
DocMetadata,
CategoryGeneratedIndexMetadata,
} from '@docusaurus/plugin-content-docs';
import type {SidebarsUtils} from './sidebars/utils';
@ -32,7 +33,9 @@ export type VersionTags = {
[permalink: string]: VersionTag;
};
export type FullVersion = LoadedVersion & {
export type FullVersion = Omit<LoadedVersion, 'docs' | 'drafts'> & {
docs: DocMetadata[];
drafts: DocMetadata[];
sidebarsUtils: SidebarsUtils;
categoryGeneratedIndices: CategoryGeneratedIndexMetadata[];
};

View File

@ -16,6 +16,7 @@ import {
} from './files';
import {createSidebarsUtils} from '../sidebars/utils';
import {getCategoryGeneratedIndexMetadataList} from '../categoryGeneratedIndex';
import {addDocNavigation} from '../docs';
import type {FullVersion} from '../types';
import type {LoadContext} from '@docusaurus/types';
import type {
@ -261,6 +262,11 @@ export function toFullVersion(version: LoadedVersion): FullVersion {
const sidebarsUtils = createSidebarsUtils(version.sidebars);
return {
...version,
docs: addDocNavigation(
version.docs,
sidebarsUtils,
version.sidebarFilePath as string,
),
sidebarsUtils,
categoryGeneratedIndices: getCategoryGeneratedIndexMetadataList({
docs: version.docs,