feat(content-docs): sidebar category linking to document or auto-generated index page (#5830)

Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
Co-authored-by: Armano <armano2@users.noreply.github.com>
Co-authored-by: Alexey Pyltsyn <lex61rus@gmail.com>
This commit is contained in:
Sébastien Lorber 2021-12-03 14:44:59 +01:00 committed by GitHub
parent 95f911efef
commit cfae5d0933
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
105 changed files with 3904 additions and 816 deletions

View file

@ -1,7 +1,7 @@
{
"version-1.0.1/docs": {
"VersionedSideBarNameDoesNotMatter/docs": {
"Test": [
"version-1.0.1/foo/bar"
"foo/bar"
],
"Guides": [
"version-1.0.1/hello"

View file

@ -2,122 +2,64 @@
exports[`docsVersion first time versioning 1`] = `
Object {
"version-1.0.0/docs": Array [
Object {
"collapsed": true,
"collapsible": true,
"items": Array [
Object {
"collapsed": true,
"collapsible": true,
"items": Array [
Object {
"id": "version-1.0.0/foo/bar",
"type": "doc",
},
Object {
"id": "version-1.0.0/foo/baz",
"type": "doc",
},
],
"label": "foo",
"type": "category",
},
Object {
"collapsed": true,
"collapsible": true,
"items": Array [
Object {
"id": "version-1.0.0/rootAbsoluteSlug",
"type": "doc",
},
Object {
"id": "version-1.0.0/rootRelativeSlug",
"type": "doc",
},
Object {
"id": "version-1.0.0/rootResolvedSlug",
"type": "doc",
},
Object {
"id": "version-1.0.0/rootTryToEscapeSlug",
"type": "doc",
},
],
"label": "Slugs",
"type": "category",
},
Object {
"id": "version-1.0.0/headingAsTitle",
"type": "doc",
},
Object {
"href": "https://github.com",
"label": "Github",
"type": "link",
},
Object {
"id": "version-1.0.0/hello",
"type": "ref",
},
],
"label": "Test",
"type": "category",
},
Object {
"collapsed": true,
"collapsible": true,
"items": Array [
Object {
"id": "version-1.0.0/hello",
"type": "doc",
},
],
"label": "Guides",
"type": "category",
},
],
"docs": Object {
"Guides": Array [
"hello",
],
"Test": Array [
Object {
"items": Array [
"foo/bar",
"foo/baz",
],
"label": "foo",
"type": "category",
},
Object {
"items": Array [
"rootAbsoluteSlug",
"rootRelativeSlug",
"rootResolvedSlug",
"rootTryToEscapeSlug",
],
"label": "Slugs",
"type": "category",
},
Object {
"id": "headingAsTitle",
"type": "doc",
},
Object {
"href": "https://github.com",
"label": "Github",
"type": "link",
},
Object {
"id": "hello",
"type": "ref",
},
],
},
}
`;
exports[`docsVersion not the first time versioning 1`] = `
Object {
"version-2.0.0/docs": Array [
Object {
"collapsed": true,
"collapsible": true,
"items": Array [
Object {
"id": "version-2.0.0/foo/bar",
"type": "doc",
},
],
"label": "Test",
"type": "category",
},
Object {
"collapsed": true,
"collapsible": true,
"items": Array [
Object {
"id": "version-2.0.0/hello",
"type": "doc",
},
],
"label": "Guides",
"type": "category",
},
],
"docs": Object {
"Guides": Array [
"hello",
],
"Test": Array [
"foo/bar",
],
},
}
`;
exports[`docsVersion second docs instance versioning 1`] = `
Object {
"version-2.0.0/community": Array [
Object {
"id": "version-2.0.0/team",
"type": "doc",
},
"community": Array [
"team",
],
}
`;

View file

@ -43,6 +43,7 @@ Object {
},
],
"label": "foo",
"link": undefined,
"type": "category",
},
Object {
@ -67,6 +68,7 @@ Object {
},
],
"label": "Slugs",
"link": undefined,
"type": "category",
},
Object {
@ -84,6 +86,7 @@ Object {
},
],
"label": "Test",
"link": undefined,
"type": "category",
},
Object {
@ -96,6 +99,7 @@ Object {
},
],
"label": "Guides",
"link": undefined,
"type": "category",
},
],
@ -614,12 +618,14 @@ Object {
{
\\"type\\": \\"link\\",
\\"label\\": \\"Bar\\",
\\"href\\": \\"/docs/foo/bar\\"
\\"href\\": \\"/docs/foo/bar\\",
\\"docId\\": \\"foo/bar\\"
},
{
\\"type\\": \\"link\\",
\\"label\\": \\"baz\\",
\\"href\\": \\"/docs/foo/bazSlug.html\\"
\\"href\\": \\"/docs/foo/bazSlug.html\\",
\\"docId\\": \\"foo/baz\\"
}
],
\\"collapsible\\": true,
@ -632,22 +638,26 @@ Object {
{
\\"type\\": \\"link\\",
\\"label\\": \\"rootAbsoluteSlug\\",
\\"href\\": \\"/docs/rootAbsoluteSlug\\"
\\"href\\": \\"/docs/rootAbsoluteSlug\\",
\\"docId\\": \\"rootAbsoluteSlug\\"
},
{
\\"type\\": \\"link\\",
\\"label\\": \\"rootRelativeSlug\\",
\\"href\\": \\"/docs/rootRelativeSlug\\"
\\"href\\": \\"/docs/rootRelativeSlug\\",
\\"docId\\": \\"rootRelativeSlug\\"
},
{
\\"type\\": \\"link\\",
\\"label\\": \\"rootResolvedSlug\\",
\\"href\\": \\"/docs/hey/rootResolvedSlug\\"
\\"href\\": \\"/docs/hey/rootResolvedSlug\\",
\\"docId\\": \\"rootResolvedSlug\\"
},
{
\\"type\\": \\"link\\",
\\"label\\": \\"rootTryToEscapeSlug\\",
\\"href\\": \\"/docs/rootTryToEscapeSlug\\"
\\"href\\": \\"/docs/rootTryToEscapeSlug\\",
\\"docId\\": \\"rootTryToEscapeSlug\\"
}
],
\\"collapsible\\": true,
@ -656,7 +666,8 @@ Object {
{
\\"type\\": \\"link\\",
\\"label\\": \\"My heading as title\\",
\\"href\\": \\"/docs/headingAsTitle\\"
\\"href\\": \\"/docs/headingAsTitle\\",
\\"docId\\": \\"headingAsTitle\\"
},
{
\\"type\\": \\"link\\",
@ -666,7 +677,8 @@ Object {
{
\\"type\\": \\"link\\",
\\"label\\": \\"Hello sidebar_label\\",
\\"href\\": \\"/docs/\\"
\\"href\\": \\"/docs/\\",
\\"docId\\": \\"hello\\"
}
]
},
@ -679,11 +691,92 @@ Object {
{
\\"type\\": \\"link\\",
\\"label\\": \\"Hello sidebar_label\\",
\\"href\\": \\"/docs/\\"
\\"href\\": \\"/docs/\\",
\\"docId\\": \\"hello\\"
}
]
}
]
},
\\"docs\\": {
\\"foo/bar\\": {
\\"id\\": \\"foo/bar\\",
\\"title\\": \\"Bar\\",
\\"description\\": \\"This is custom description\\",
\\"sidebar\\": \\"docs\\"
},
\\"foo/baz\\": {
\\"id\\": \\"foo/baz\\",
\\"title\\": \\"baz\\",
\\"description\\": \\"Images\\",
\\"sidebar\\": \\"docs\\"
},
\\"headingAsTitle\\": {
\\"id\\": \\"headingAsTitle\\",
\\"title\\": \\"My heading as title\\",
\\"description\\": \\"\\",
\\"sidebar\\": \\"docs\\"
},
\\"hello\\": {
\\"id\\": \\"hello\\",
\\"title\\": \\"Hello, World !\\",
\\"description\\": \\"Hi, Endilie here :)\\",
\\"sidebar\\": \\"docs\\"
},
\\"ipsum\\": {
\\"id\\": \\"ipsum\\",
\\"title\\": \\"ipsum\\",
\\"description\\": \\"Lorem ipsum.\\"
},
\\"lorem\\": {
\\"id\\": \\"lorem\\",
\\"title\\": \\"lorem\\",
\\"description\\": \\"Lorem ipsum.\\"
},
\\"rootAbsoluteSlug\\": {
\\"id\\": \\"rootAbsoluteSlug\\",
\\"title\\": \\"rootAbsoluteSlug\\",
\\"description\\": \\"Lorem\\",
\\"sidebar\\": \\"docs\\"
},
\\"rootRelativeSlug\\": {
\\"id\\": \\"rootRelativeSlug\\",
\\"title\\": \\"rootRelativeSlug\\",
\\"description\\": \\"Lorem\\",
\\"sidebar\\": \\"docs\\"
},
\\"rootResolvedSlug\\": {
\\"id\\": \\"rootResolvedSlug\\",
\\"title\\": \\"rootResolvedSlug\\",
\\"description\\": \\"Lorem\\",
\\"sidebar\\": \\"docs\\"
},
\\"rootTryToEscapeSlug\\": {
\\"id\\": \\"rootTryToEscapeSlug\\",
\\"title\\": \\"rootTryToEscapeSlug\\",
\\"description\\": \\"Lorem\\",
\\"sidebar\\": \\"docs\\"
},
\\"slugs/absoluteSlug\\": {
\\"id\\": \\"slugs/absoluteSlug\\",
\\"title\\": \\"absoluteSlug\\",
\\"description\\": \\"Lorem\\"
},
\\"slugs/relativeSlug\\": {
\\"id\\": \\"slugs/relativeSlug\\",
\\"title\\": \\"relativeSlug\\",
\\"description\\": \\"Lorem\\"
},
\\"slugs/resolvedSlug\\": {
\\"id\\": \\"slugs/resolvedSlug\\",
\\"title\\": \\"resolvedSlug\\",
\\"description\\": \\"Lorem\\"
},
\\"slugs/tryToEscapeSlug\\": {
\\"id\\": \\"slugs/tryToEscapeSlug\\",
\\"title\\": \\"tryToEscapeSlug\\",
\\"description\\": \\"Lorem\\"
}
}
}",
}
@ -958,6 +1051,7 @@ Object {
"sidebarPosition": 0,
"source": "@site/docs/3-API/01_Core APIs/0 --- Client API.md",
"sourceDirName": "3-API/01_Core APIs",
"unversionedId": "API/Core APIs/Client API",
},
Object {
"frontMatter": Object {},
@ -965,6 +1059,7 @@ Object {
"sidebarPosition": 1,
"source": "@site/docs/3-API/01_Core APIs/1 --- Server API.md",
"sourceDirName": "3-API/01_Core APIs",
"unversionedId": "API/Core APIs/Server API",
},
Object {
"frontMatter": Object {},
@ -972,6 +1067,7 @@ Object {
"sidebarPosition": 0,
"source": "@site/docs/3-API/02_Extension APIs/0. Plugin API.md",
"sourceDirName": "3-API/02_Extension APIs",
"unversionedId": "API/Extension APIs/Plugin API",
},
Object {
"frontMatter": Object {},
@ -979,6 +1075,7 @@ Object {
"sidebarPosition": 1,
"source": "@site/docs/3-API/02_Extension APIs/1. Theme API.md",
"sourceDirName": "3-API/02_Extension APIs",
"unversionedId": "API/Extension APIs/Theme API",
},
Object {
"frontMatter": Object {},
@ -986,6 +1083,7 @@ Object {
"sidebarPosition": 3,
"source": "@site/docs/3-API/03_api-end.md",
"sourceDirName": "3-API",
"unversionedId": "API/api-end",
},
Object {
"frontMatter": Object {},
@ -993,6 +1091,7 @@ Object {
"sidebarPosition": 0,
"source": "@site/docs/3-API/00_api-overview.md",
"sourceDirName": "3-API",
"unversionedId": "API/api-overview",
},
Object {
"frontMatter": Object {
@ -1003,6 +1102,7 @@ Object {
"sidebarPosition": 1,
"source": "@site/docs/Guides/z-guide1.md",
"sourceDirName": "Guides",
"unversionedId": "Guides/guide1",
},
Object {
"frontMatter": Object {
@ -1012,6 +1112,7 @@ Object {
"sidebarPosition": 2,
"source": "@site/docs/Guides/02-guide2.md",
"sourceDirName": "Guides",
"unversionedId": "Guides/guide2",
},
Object {
"frontMatter": Object {
@ -1022,6 +1123,7 @@ Object {
"sidebarPosition": 2.5,
"source": "@site/docs/Guides/0-guide2.5.md",
"sourceDirName": "Guides",
"unversionedId": "Guides/guide2.5",
},
Object {
"frontMatter": Object {
@ -1032,6 +1134,7 @@ Object {
"sidebarPosition": 3,
"source": "@site/docs/Guides/guide3.md",
"sourceDirName": "Guides",
"unversionedId": "Guides/guide3",
},
Object {
"frontMatter": Object {
@ -1041,6 +1144,7 @@ Object {
"sidebarPosition": undefined,
"source": "@site/docs/Guides/a-guide4.md",
"sourceDirName": "Guides",
"unversionedId": "Guides/guide4",
},
Object {
"frontMatter": Object {
@ -1050,6 +1154,7 @@ Object {
"sidebarPosition": undefined,
"source": "@site/docs/Guides/b-guide5.md",
"sourceDirName": "Guides",
"unversionedId": "Guides/guide5",
},
Object {
"frontMatter": Object {},
@ -1057,6 +1162,7 @@ Object {
"sidebarPosition": 0,
"source": "@site/docs/0-getting-started.md",
"sourceDirName": ".",
"unversionedId": "getting-started",
},
Object {
"frontMatter": Object {},
@ -1064,6 +1170,7 @@ Object {
"sidebarPosition": 1,
"source": "@site/docs/1-installation.md",
"sourceDirName": ".",
"unversionedId": "installation",
},
],
"item": Object {
@ -1151,9 +1258,18 @@ Object {
{
\\"type\\": \\"link\\",
\\"label\\": \\"team\\",
\\"href\\": \\"/community/team\\"
\\"href\\": \\"/community/team\\",
\\"docId\\": \\"team\\"
}
]
},
\\"docs\\": {
\\"team\\": {
\\"id\\": \\"team\\",
\\"title\\": \\"team\\",
\\"description\\": \\"Team 1.0.0\\",
\\"sidebar\\": \\"version-1.0.0/community\\"
}
}
}",
"version-current-metadata-prop-751.json": "{
@ -1169,9 +1285,18 @@ Object {
{
\\"type\\": \\"link\\",
\\"label\\": \\"Team title translated\\",
\\"href\\": \\"/community/next/team\\"
\\"href\\": \\"/community/next/team\\",
\\"docId\\": \\"team\\"
}
]
},
\\"docs\\": {
\\"team\\": {
\\"id\\": \\"team\\",
\\"title\\": \\"Team title translated\\",
\\"description\\": \\"Team current version (translated)\\",
\\"sidebar\\": \\"community\\"
}
}
}",
}
@ -1279,6 +1404,7 @@ Object {
},
],
"label": "Test",
"link": undefined,
"type": "category",
},
Object {
@ -1291,6 +1417,7 @@ Object {
},
],
"label": "Guides",
"link": undefined,
"type": "category",
},
],
@ -1299,17 +1426,18 @@ Object {
exports[`versioned website content: 101 version sidebars 1`] = `
Object {
"version-1.0.1/docs": Array [
"VersionedSideBarNameDoesNotMatter/docs": Array [
Object {
"collapsed": true,
"collapsible": true,
"items": Array [
Object {
"id": "version-1.0.1/foo/bar",
"id": "foo/bar",
"type": "doc",
},
],
"label": "Test",
"link": undefined,
"type": "category",
},
Object {
@ -1322,6 +1450,7 @@ Object {
},
],
"label": "Guides",
"link": undefined,
"type": "category",
},
],
@ -1341,6 +1470,7 @@ Object {
},
],
"label": "Test",
"link": undefined,
"type": "category",
},
Object {
@ -1353,6 +1483,7 @@ Object {
},
],
"label": "Guides",
"link": undefined,
"type": "category",
},
],
@ -1562,7 +1693,7 @@ Object {
\\"tags\\": [],
\\"version\\": \\"1.0.1\\",
\\"frontMatter\\": {},
\\"sidebar\\": \\"version-1.0.1/docs\\",
\\"sidebar\\": \\"VersionedSideBarNameDoesNotMatter/docs\\",
\\"next\\": {
\\"title\\": \\"hello\\",
\\"permalink\\": \\"/docs/\\"
@ -1581,7 +1712,7 @@ Object {
\\"tags\\": [],
\\"version\\": \\"1.0.1\\",
\\"frontMatter\\": {},
\\"sidebar\\": \\"version-1.0.1/docs\\",
\\"sidebar\\": \\"VersionedSideBarNameDoesNotMatter/docs\\",
\\"previous\\": {
\\"title\\": \\"bar\\",
\\"permalink\\": \\"/docs/foo/bar\\"
@ -1791,12 +1922,14 @@ Object {
{
\\"type\\": \\"link\\",
\\"label\\": \\"bar\\",
\\"href\\": \\"/docs/1.0.0/foo/barSlug\\"
\\"href\\": \\"/docs/1.0.0/foo/barSlug\\",
\\"docId\\": \\"foo/bar\\"
},
{
\\"type\\": \\"link\\",
\\"label\\": \\"baz\\",
\\"href\\": \\"/docs/1.0.0/foo/baz\\"
\\"href\\": \\"/docs/1.0.0/foo/baz\\",
\\"docId\\": \\"foo/baz\\"
}
]
},
@ -1809,11 +1942,32 @@ Object {
{
\\"type\\": \\"link\\",
\\"label\\": \\"hello\\",
\\"href\\": \\"/docs/1.0.0/\\"
\\"href\\": \\"/docs/1.0.0/\\",
\\"docId\\": \\"hello\\"
}
]
}
]
},
\\"docs\\": {
\\"foo/bar\\": {
\\"id\\": \\"foo/bar\\",
\\"title\\": \\"bar\\",
\\"description\\": \\"Bar 1.0.0 !\\",
\\"sidebar\\": \\"version-1.0.0/docs\\"
},
\\"foo/baz\\": {
\\"id\\": \\"foo/baz\\",
\\"title\\": \\"baz\\",
\\"description\\": \\"Baz 1.0.0 ! This will be deleted in next subsequent versions.\\",
\\"sidebar\\": \\"version-1.0.0/docs\\"
},
\\"hello\\": {
\\"id\\": \\"hello\\",
\\"title\\": \\"hello\\",
\\"description\\": \\"Hello 1.0.0 ! (translated en)\\",
\\"sidebar\\": \\"version-1.0.0/docs\\"
}
}
}",
"version-1-0-1-metadata-prop-e87.json": "{
@ -1825,7 +1979,7 @@ Object {
\\"className\\": \\"docs-version-1.0.1\\",
\\"isLast\\": true,
\\"docsSidebars\\": {
\\"version-1.0.1/docs\\": [
\\"VersionedSideBarNameDoesNotMatter/docs\\": [
{
\\"type\\": \\"category\\",
\\"collapsed\\": true,
@ -1835,7 +1989,8 @@ Object {
{
\\"type\\": \\"link\\",
\\"label\\": \\"bar\\",
\\"href\\": \\"/docs/foo/bar\\"
\\"href\\": \\"/docs/foo/bar\\",
\\"docId\\": \\"foo/bar\\"
}
]
},
@ -1848,11 +2003,26 @@ Object {
{
\\"type\\": \\"link\\",
\\"label\\": \\"hello\\",
\\"href\\": \\"/docs/\\"
\\"href\\": \\"/docs/\\",
\\"docId\\": \\"hello\\"
}
]
}
]
},
\\"docs\\": {
\\"foo/bar\\": {
\\"id\\": \\"foo/bar\\",
\\"title\\": \\"bar\\",
\\"description\\": \\"Bar 1.0.1 !\\",
\\"sidebar\\": \\"VersionedSideBarNameDoesNotMatter/docs\\"
},
\\"hello\\": {
\\"id\\": \\"hello\\",
\\"title\\": \\"hello\\",
\\"description\\": \\"Hello 1.0.1 !\\",
\\"sidebar\\": \\"VersionedSideBarNameDoesNotMatter/docs\\"
}
}
}",
"version-current-metadata-prop-751.json": "{
@ -1874,7 +2044,8 @@ Object {
{
\\"type\\": \\"link\\",
\\"label\\": \\"bar\\",
\\"href\\": \\"/docs/next/foo/barSlug\\"
\\"href\\": \\"/docs/next/foo/barSlug\\",
\\"docId\\": \\"foo/bar\\"
}
]
},
@ -1887,11 +2058,46 @@ Object {
{
\\"type\\": \\"link\\",
\\"label\\": \\"hello\\",
\\"href\\": \\"/docs/next/\\"
\\"href\\": \\"/docs/next/\\",
\\"docId\\": \\"hello\\"
}
]
}
]
},
\\"docs\\": {
\\"foo/bar\\": {
\\"id\\": \\"foo/bar\\",
\\"title\\": \\"bar\\",
\\"description\\": \\"This is next version of bar.\\",
\\"sidebar\\": \\"docs\\"
},
\\"hello\\": {
\\"id\\": \\"hello\\",
\\"title\\": \\"hello\\",
\\"description\\": \\"Hello next !\\",
\\"sidebar\\": \\"docs\\"
},
\\"slugs/absoluteSlug\\": {
\\"id\\": \\"slugs/absoluteSlug\\",
\\"title\\": \\"absoluteSlug\\",
\\"description\\": \\"Lorem\\"
},
\\"slugs/relativeSlug\\": {
\\"id\\": \\"slugs/relativeSlug\\",
\\"title\\": \\"relativeSlug\\",
\\"description\\": \\"Lorem\\"
},
\\"slugs/resolvedSlug\\": {
\\"id\\": \\"slugs/resolvedSlug\\",
\\"title\\": \\"resolvedSlug\\",
\\"description\\": \\"Lorem\\"
},
\\"slugs/tryToEscapeSlug\\": {
\\"id\\": \\"slugs/tryToEscapeSlug\\",
\\"title\\": \\"tryToEscapeSlug\\",
\\"description\\": \\"Lorem\\"
}
}
}",
"version-with-slugs-metadata-prop-2bf.json": "{
@ -1913,11 +2119,55 @@ Object {
{
\\"type\\": \\"link\\",
\\"label\\": \\"rootAbsoluteSlug\\",
\\"href\\": \\"/docs/withSlugs/rootAbsoluteSlug\\"
\\"href\\": \\"/docs/withSlugs/rootAbsoluteSlug\\",
\\"docId\\": \\"rootAbsoluteSlug\\"
}
]
}
]
},
\\"docs\\": {
\\"rootAbsoluteSlug\\": {
\\"id\\": \\"rootAbsoluteSlug\\",
\\"title\\": \\"rootAbsoluteSlug\\",
\\"description\\": \\"Lorem\\",
\\"sidebar\\": \\"version-1.0.1/docs\\"
},
\\"rootRelativeSlug\\": {
\\"id\\": \\"rootRelativeSlug\\",
\\"title\\": \\"rootRelativeSlug\\",
\\"description\\": \\"Lorem\\"
},
\\"rootResolvedSlug\\": {
\\"id\\": \\"rootResolvedSlug\\",
\\"title\\": \\"rootResolvedSlug\\",
\\"description\\": \\"Lorem\\"
},
\\"rootTryToEscapeSlug\\": {
\\"id\\": \\"rootTryToEscapeSlug\\",
\\"title\\": \\"rootTryToEscapeSlug\\",
\\"description\\": \\"Lorem\\"
},
\\"slugs/absoluteSlug\\": {
\\"id\\": \\"slugs/absoluteSlug\\",
\\"title\\": \\"absoluteSlug\\",
\\"description\\": \\"Lorem\\"
},
\\"slugs/relativeSlug\\": {
\\"id\\": \\"slugs/relativeSlug\\",
\\"title\\": \\"relativeSlug\\",
\\"description\\": \\"Lorem\\"
},
\\"slugs/resolvedSlug\\": {
\\"id\\": \\"slugs/resolvedSlug\\",
\\"title\\": \\"resolvedSlug\\",
\\"description\\": \\"Lorem\\"
},
\\"slugs/tryToEscapeSlug\\": {
\\"id\\": \\"slugs/tryToEscapeSlug\\",
\\"title\\": \\"tryToEscapeSlug\\",
\\"description\\": \\"Lorem\\"
}
}
}",
}
@ -1973,12 +2223,12 @@ Object {
Object {
"id": "foo/bar",
"path": "/docs/foo/bar",
"sidebar": "version-1.0.1/docs",
"sidebar": "VersionedSideBarNameDoesNotMatter/docs",
},
Object {
"id": "hello",
"path": "/docs/",
"sidebar": "version-1.0.1/docs",
"sidebar": "VersionedSideBarNameDoesNotMatter/docs",
},
],
"isLast": true,
@ -2291,7 +2541,7 @@ Array [
"content": "@site/versioned_docs/version-1.0.1/hello.md",
},
"path": "/docs/",
"sidebar": "version-1.0.1/docs",
"sidebar": "VersionedSideBarNameDoesNotMatter/docs",
},
Object {
"component": "@theme/DocItem",
@ -2300,7 +2550,7 @@ Array [
"content": "@site/versioned_docs/version-1.0.1/foo/bar.md",
},
"path": "/docs/foo/bar",
"sidebar": "version-1.0.1/docs",
"sidebar": "VersionedSideBarNameDoesNotMatter/docs",
},
],
},
@ -2320,6 +2570,7 @@ Object {
},
],
"label": "Test",
"link": undefined,
"type": "category",
},
],

View file

@ -8,6 +8,14 @@ Array [
"description": "The label for category Getting started in sidebar docs",
"message": "Getting started",
},
"sidebar.docs.category.Getting started.link.generated-index.description": Object {
"description": "The generated-index page description for category Getting started in sidebar docs",
"message": "Getting started index description",
},
"sidebar.docs.category.Getting started.link.generated-index.title": Object {
"description": "The generated-index page title for category Getting started in sidebar docs",
"message": "Getting started index title",
},
"sidebar.docs.link.Link label": Object {
"description": "The label for link Link label in sidebar docs, linking to https://facebook.com",
"message": "Link label",
@ -25,6 +33,14 @@ Array [
"description": "The label for category Getting started in sidebar docs",
"message": "Getting started",
},
"sidebar.docs.category.Getting started.link.generated-index.description": Object {
"description": "The generated-index page description for category Getting started in sidebar docs",
"message": "Getting started index description",
},
"sidebar.docs.category.Getting started.link.generated-index.title": Object {
"description": "The generated-index page title for category Getting started in sidebar docs",
"message": "Getting started index title",
},
"sidebar.docs.link.Link label": Object {
"description": "The label for link Link label in sidebar docs, linking to https://facebook.com",
"message": "Link label",
@ -42,6 +58,14 @@ Array [
"description": "The label for category Getting started in sidebar docs",
"message": "Getting started",
},
"sidebar.docs.category.Getting started.link.generated-index.description": Object {
"description": "The generated-index page description for category Getting started in sidebar docs",
"message": "Getting started index description",
},
"sidebar.docs.category.Getting started.link.generated-index.title": Object {
"description": "The generated-index page title for category Getting started in sidebar docs",
"message": "Getting started index title",
},
"sidebar.docs.link.Link label": Object {
"description": "The label for link Link label in sidebar docs, linking to https://facebook.com",
"message": "Link label",
@ -177,6 +201,13 @@ Object {
},
],
"label": "Getting started (translated)",
"link": Object {
"description": "Getting started index description (translated)",
"permalink": "/docs/category/getting-started-index-slug",
"slug": "/category/getting-started-index-slug",
"title": "Getting started index title (translated)",
"type": "generated-index",
},
"type": "category",
},
Object {
@ -317,6 +348,13 @@ Object {
},
],
"label": "Getting started (translated)",
"link": Object {
"description": "Getting started index description (translated)",
"permalink": "/docs/category/getting-started-index-slug",
"slug": "/category/getting-started-index-slug",
"title": "Getting started index title (translated)",
"type": "generated-index",
},
"type": "category",
},
Object {
@ -457,6 +495,13 @@ Object {
},
],
"label": "Getting started (translated)",
"link": Object {
"description": "Getting started index description (translated)",
"permalink": "/docs/category/getting-started-index-slug",
"slug": "/category/getting-started-index-slug",
"title": "Getting started index title (translated)",
"type": "generated-index",
},
"type": "category",
},
Object {

View file

@ -11,7 +11,8 @@ import {
processDocMetadata,
readVersionDocs,
readDocFile,
handleNavigation,
addDocNavigation,
isConventionalDocIndex,
} from '../docs';
import {loadSidebars} from '../sidebars';
import {readVersionsMetadata} from '../versions';
@ -28,7 +29,8 @@ import type {LoadContext} from '@docusaurus/types';
import {DEFAULT_PLUGIN_ID} from '@docusaurus/core/lib/constants';
import {DEFAULT_OPTIONS} from '../options';
import {Optional} from 'utility-types';
import {posixPath} from '@docusaurus/utils';
import {createSlugger, posixPath} from '@docusaurus/utils';
import {createSidebarsUtils} from '../sidebars/utils';
const fixtureDir = path.join(__dirname, '__fixtures__');
@ -119,7 +121,7 @@ function createTestUtils({
async function generateNavigation(
docFiles: DocFile[],
): Promise<[DocNavLink, DocNavLink][]> {
): Promise<[DocNavLink | undefined, DocNavLink | undefined][]> {
const rawDocs = await Promise.all(
docFiles.map((docFile) =>
processDocMetadata({
@ -136,16 +138,19 @@ function createTestUtils({
numberPrefixParser: options.numberPrefixParser,
docs: rawDocs,
version: versionMetadata,
options: {
sidebarOptions: {
sidebarCollapsed: false,
sidebarCollapsible: true,
},
categoryLabelSlugger: createSlugger(),
});
return handleNavigation(
const sidebarsUtils = createSidebarsUtils(sidebars);
return addDocNavigation(
rawDocs,
sidebars,
sidebarsUtils,
versionMetadata.sidebarFilePath as string,
).docs.map((doc) => [doc.previous, doc.next]);
).map((doc) => [doc.previous, doc.next]);
}
return {processDocFile, testMeta, testSlug, generateNavigation};
@ -1022,3 +1027,113 @@ describe('versioned site', () => {
});
});
});
describe('isConventionalDocIndex', () => {
test('supports readme', () => {
expect(
isConventionalDocIndex({
sourceDirName: 'doesNotMatter',
source: 'readme.md',
}),
).toEqual(true);
expect(
isConventionalDocIndex({
sourceDirName: 'doesNotMatter',
source: 'readme.mdx',
}),
).toEqual(true);
expect(
isConventionalDocIndex({
sourceDirName: 'doesNotMatter',
source: 'README.md',
}),
).toEqual(true);
expect(
isConventionalDocIndex({
sourceDirName: 'doesNotMatter',
source: 'parent/ReAdMe',
}),
).toEqual(true);
});
test('supports index', () => {
expect(
isConventionalDocIndex({
sourceDirName: 'doesNotMatter',
source: 'index.md',
}),
).toEqual(true);
expect(
isConventionalDocIndex({
sourceDirName: 'doesNotMatter',
source: 'index.mdx',
}),
).toEqual(true);
expect(
isConventionalDocIndex({
sourceDirName: 'doesNotMatter',
source: 'INDEX.md',
}),
).toEqual(true);
expect(
isConventionalDocIndex({
sourceDirName: 'doesNotMatter',
source: 'parent/InDeX',
}),
).toEqual(true);
});
test('supports <categoryName>/<categoryName>.md', () => {
expect(
isConventionalDocIndex({
sourceDirName: 'someCategory',
source: 'someCategory',
}),
).toEqual(true);
expect(
isConventionalDocIndex({
sourceDirName: 'someCategory',
source: 'someCategory.md',
}),
).toEqual(true);
expect(
isConventionalDocIndex({
sourceDirName: 'someCategory',
source: 'someCategory.mdx',
}),
).toEqual(true);
expect(
isConventionalDocIndex({
sourceDirName: 'some_category',
source: 'SOME_CATEGORY.md',
}),
).toEqual(true);
expect(
isConventionalDocIndex({
sourceDirName: 'some_category',
source: 'parent/some_category',
}),
).toEqual(true);
});
test('reject other cases', () => {
expect(
isConventionalDocIndex({
sourceDirName: 'someCategory',
source: 'some_Category',
}),
).toEqual(false);
expect(
isConventionalDocIndex({
sourceDirName: 'doesNotMatter',
source: 'read_me',
}),
).toEqual(false);
expect(
isConventionalDocIndex({
sourceDirName: 'doesNotMatter',
source: 'the index',
}),
).toEqual(false);
});
});

View file

@ -619,6 +619,32 @@ describe('versioned website', () => {
{label: 'barTag 3', permalink: '/docs/next/tags/barTag-3-permalink'},
],
});
expect(getDocById(version101, 'foo/bar')).toEqual({
...defaultDocMetadata,
id: 'version-1.0.1/foo/bar',
unversionedId: 'foo/bar',
sourceDirName: 'foo',
isDocsHomePage: false,
permalink: '/docs/foo/bar',
slug: '/foo/bar',
source: path.posix.join(
'@site',
posixPath(path.relative(siteDir, version101.contentPath)),
'foo',
'bar.md',
),
title: 'bar',
description: 'Bar 1.0.1 !',
frontMatter: {},
version: '1.0.1',
sidebar: 'VersionedSideBarNameDoesNotMatter/docs',
next: {
title: 'hello',
permalink: '/docs/',
},
tags: [],
});
expect(getDocById(currentVersion, 'hello')).toEqual({
...defaultDocMetadata,
id: 'hello',
@ -659,7 +685,7 @@ describe('versioned website', () => {
description: 'Hello 1.0.1 !',
frontMatter: {},
version: '1.0.1',
sidebar: 'version-1.0.1/docs',
sidebar: 'VersionedSideBarNameDoesNotMatter/docs',
previous: {
title: 'bar',
permalink: '/docs/foo/bar',

View file

@ -51,6 +51,8 @@ describe('normalizeDocsPluginOptions', () => {
docItemComponent: '@theme/DocItem',
docTagDocListComponent: '@theme/DocTagDocListPage',
docTagsListComponent: '@theme/DocTagsListPage',
docCategoryGeneratedIndexComponent:
'@theme/DocCategoryGeneratedIndexPage',
remarkPlugins: [markdownPluginsObjectStub],
rehypePlugins: [markdownPluginsFunctionStub],
beforeDefaultRehypePlugins: [],

View file

@ -9,24 +9,92 @@ import getSlug from '../slug';
describe('getSlug', () => {
test('should default to dirname/id', () => {
expect(getSlug({baseID: 'doc', dirName: '/dir'})).toEqual('/dir/doc');
expect(getSlug({baseID: 'doc', dirName: '/dir/subdir'})).toEqual(
'/dir/subdir/doc',
);
expect(
getSlug({
baseID: 'doc',
source: '@site/docs/dir/doc.md',
sourceDirName: '/dir',
}),
).toEqual('/dir/doc');
expect(
getSlug({
baseID: 'doc',
source: '@site/docs/dir/subdir/doc.md',
sourceDirName: '/dir/subdir',
}),
).toEqual('/dir/subdir/doc');
});
test('should handle conventional doc indexes', () => {
expect(
getSlug({
baseID: 'doc',
source: '@site/docs/dir/subdir/index.md',
sourceDirName: '/dir/subdir',
}),
).toEqual('/dir/subdir/');
expect(
getSlug({
baseID: 'doc',
source: '@site/docs/dir/subdir/inDEx.mdx',
sourceDirName: '/dir/subdir',
}),
).toEqual('/dir/subdir/');
expect(
getSlug({
baseID: 'doc',
source: '@site/docs/dir/subdir/readme.md',
sourceDirName: '/dir/subdir',
}),
).toEqual('/dir/subdir/');
expect(
getSlug({
baseID: 'doc',
source: '@site/docs/dir/subdir/reADMe.mdx',
sourceDirName: '/dir/subdir',
}),
).toEqual('/dir/subdir/');
expect(
getSlug({
baseID: 'doc',
source: '@site/docs/dir/subdir/subdir.md',
sourceDirName: '/dir/subdir',
}),
).toEqual('/dir/subdir/');
expect(
getSlug({
baseID: 'doc',
source: '@site/docs/dir/subdir/suBDir.mdx',
sourceDirName: '/dir/subdir',
}),
).toEqual('/dir/subdir/');
});
test('should ignore conventional doc index when explicit slug frontmatter is provided', () => {
expect(
getSlug({
baseID: 'doc',
source: '@site/docs/dir/subdir/index.md',
sourceDirName: '/dir/subdir',
frontmatterSlug: '/my/frontMatterSlug',
}),
).toEqual('/my/frontMatterSlug');
});
test('can strip dir number prefixes', () => {
expect(
getSlug({
baseID: 'doc',
dirName: '/001-dir1/002-dir2',
source: '@site/docs/001-dir1/002-dir2/doc.md',
sourceDirName: '/001-dir1/002-dir2',
stripDirNumberPrefixes: true,
}),
).toEqual('/dir1/dir2/doc');
expect(
getSlug({
baseID: 'doc',
dirName: '/001-dir1/002-dir2',
source: '@site/docs/001-dir1/002-dir2/doc.md',
sourceDirName: '/001-dir1/002-dir2',
stripDirNumberPrefixes: false,
}),
).toEqual('/001-dir1/002-dir2/doc');
@ -35,26 +103,45 @@ describe('getSlug', () => {
// See https://github.com/facebook/docusaurus/issues/3223
test('should handle special chars in doc path', () => {
expect(
getSlug({baseID: 'my dôc', dirName: '/dir with spâce/hey $hello'}),
getSlug({
baseID: 'my dôc',
source: '@site/docs/dir with spâce/hey $hello/doc.md',
sourceDirName: '/dir with spâce/hey $hello',
}),
).toEqual('/dir with spâce/hey $hello/my dôc');
});
test('should handle current dir', () => {
expect(getSlug({baseID: 'doc', dirName: '.'})).toEqual('/doc');
expect(getSlug({baseID: 'doc', dirName: '/'})).toEqual('/doc');
expect(
getSlug({baseID: 'doc', source: '@site/docs/doc.md', sourceDirName: '.'}),
).toEqual('/doc');
expect(
getSlug({baseID: 'doc', source: '@site/docs/doc.md', sourceDirName: '/'}),
).toEqual('/doc');
});
test('should resolve absolute slug frontmatter', () => {
expect(
getSlug({baseID: 'any', dirName: '.', frontmatterSlug: '/abc/def'}),
).toEqual('/abc/def');
expect(
getSlug({baseID: 'any', dirName: './any', frontmatterSlug: '/abc/def'}),
getSlug({
baseID: 'any',
source: '@site/docs/doc.md',
sourceDirName: '.',
frontmatterSlug: '/abc/def',
}),
).toEqual('/abc/def');
expect(
getSlug({
baseID: 'any',
dirName: './any/any',
source: '@site/docs/any/doc.md',
sourceDirName: './any',
frontmatterSlug: '/abc/def',
}),
).toEqual('/abc/def');
expect(
getSlug({
baseID: 'any',
source: '@site/docs/any/any/doc.md',
sourceDirName: './any/any',
frontmatterSlug: '/abc/def',
}),
).toEqual('/abc/def');
@ -62,46 +149,66 @@ describe('getSlug', () => {
test('should resolve relative slug frontmatter', () => {
expect(
getSlug({baseID: 'any', dirName: '.', frontmatterSlug: 'abc/def'}),
getSlug({
baseID: 'any',
source: '@site/docs/doc.md',
sourceDirName: '.',
frontmatterSlug: 'abc/def',
}),
).toEqual('/abc/def');
expect(
getSlug({baseID: 'any', dirName: '/dir', frontmatterSlug: 'abc/def'}),
getSlug({
baseID: 'any',
source: '@site/docs/dir/doc.md',
sourceDirName: '/dir',
frontmatterSlug: 'abc/def',
}),
).toEqual('/dir/abc/def');
expect(
getSlug({
baseID: 'any',
dirName: 'unslashedDir',
source: '@site/docs/unslashedDir/doc.md',
sourceDirName: 'unslashedDir',
frontmatterSlug: 'abc/def',
}),
).toEqual('/unslashedDir/abc/def');
expect(
getSlug({
baseID: 'any',
dirName: 'dir/subdir',
source: '@site/docs/dir/subdir/doc.md',
sourceDirName: 'dir/subdir',
frontmatterSlug: 'abc/def',
}),
).toEqual('/dir/subdir/abc/def');
expect(
getSlug({baseID: 'any', dirName: '/dir', frontmatterSlug: './abc/def'}),
getSlug({
baseID: 'any',
source: '@site/docs/dir/doc.md',
sourceDirName: '/dir',
frontmatterSlug: './abc/def',
}),
).toEqual('/dir/abc/def');
expect(
getSlug({
baseID: 'any',
dirName: '/dir',
source: '@site/docs/dir/doc.md',
sourceDirName: '/dir',
frontmatterSlug: './abc/../def',
}),
).toEqual('/dir/def');
expect(
getSlug({
baseID: 'any',
dirName: '/dir/subdir',
source: '@site/docs/dir/subdir/doc.md',
sourceDirName: '/dir/subdir',
frontmatterSlug: '../abc/def',
}),
).toEqual('/dir/abc/def');
expect(
getSlug({
baseID: 'any',
dirName: '/dir/subdir',
source: '@site/docs/dir/subdirdoc.md',
sourceDirName: '/dir/subdir',
frontmatterSlug: '../../../../../abc/../def',
}),
).toEqual('/def');

View file

@ -68,6 +68,13 @@ function createSampleVersion(
type: 'category',
label: 'Getting started',
collapsed: false,
link: {
type: 'generated-index',
slug: '/category/getting-started-index-slug',
permalink: '/docs/category/getting-started-index-slug',
title: 'Getting started index title',
description: 'Getting started index description',
},
items: [
{
type: 'doc',