Skip to content

Commit e66e045

Browse files
authored
fix(docs): create tags route if only tags exists (#5606)
1 parent 81877d7 commit e66e045

2 files changed

Lines changed: 16 additions & 57 deletions

File tree

packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/index.test.ts.snap

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,8 +1019,6 @@ Object {
10191019
},
10201020
\\"sidebar\\": \\"community\\"
10211021
}",
1022-
"tags-list-1-0-0-prop-483.json": "[]",
1023-
"tags-list-current-prop-15a.json": "[]",
10241022
"version-1-0-0-metadata-prop-608.json": "{
10251023
\\"pluginId\\": \\"community\\",
10261024
\\"version\\": \\"1.0.0\\",
@@ -1102,22 +1100,6 @@ Object {
11021100

11031101
exports[`versioned website (community) content: route config 1`] = `
11041102
Array [
1105-
Object {
1106-
"component": "@theme/DocTagsListPage",
1107-
"exact": true,
1108-
"modules": Object {
1109-
"tags": "~docs/tags-list-current-prop-15a.json",
1110-
},
1111-
"path": "/community/next/tags",
1112-
},
1113-
Object {
1114-
"component": "@theme/DocTagsListPage",
1115-
"exact": true,
1116-
"modules": Object {
1117-
"tags": "~docs/tags-list-1-0-0-prop-483.json",
1118-
},
1119-
"path": "/community/tags",
1120-
},
11211103
Object {
11221104
"component": "@theme/DocPage",
11231105
"exact": false,
@@ -1654,8 +1636,6 @@ Object {
16541636
],
16551637
\\"allTagsPath\\": \\"/docs/next/tags\\"
16561638
}",
1657-
"tags-list-1-0-0-prop-483.json": "[]",
1658-
"tags-list-1-0-1-prop-c39.json": "[]",
16591639
"tags-list-current-prop-15a.json": "[
16601640
{
16611641
\\"name\\": \\"barTag 1\\",
@@ -1673,7 +1653,6 @@ Object {
16731653
\\"count\\": 1
16741654
}
16751655
]",
1676-
"tags-list-with-slugs-prop-1ca.json": "[]",
16771656
"version-1-0-0-metadata-prop-608.json": "{
16781657
\\"pluginId\\": \\"default\\",
16791658
\\"version\\": \\"1.0.0\\",
@@ -1970,14 +1949,6 @@ Object {
19701949

19711950
exports[`versioned website content: route config 1`] = `
19721951
Array [
1973-
Object {
1974-
"component": "@theme/DocTagsListPage",
1975-
"exact": true,
1976-
"modules": Object {
1977-
"tags": "~docs/tags-list-1-0-0-prop-483.json",
1978-
},
1979-
"path": "/docs/1.0.0/tags",
1980-
},
19811952
Object {
19821953
"component": "@theme/DocTagsListPage",
19831954
"exact": true,
@@ -2010,22 +1981,6 @@ Array [
20101981
},
20111982
"path": "/docs/next/tags/barTag-3-permalink",
20121983
},
2013-
Object {
2014-
"component": "@theme/DocTagsListPage",
2015-
"exact": true,
2016-
"modules": Object {
2017-
"tags": "~docs/tags-list-1-0-1-prop-c39.json",
2018-
},
2019-
"path": "/docs/tags",
2020-
},
2021-
Object {
2022-
"component": "@theme/DocTagsListPage",
2023-
"exact": true,
2024-
"modules": Object {
2025-
"tags": "~docs/tags-list-with-slugs-prop-1ca.json",
2026-
},
2027-
"path": "/docs/withSlugs/tags",
2028-
},
20291984
Object {
20301985
"component": "@theme/DocPage",
20311986
"exact": false,

packages/docusaurus-plugin-content-docs/src/index.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -328,18 +328,22 @@ export default function pluginContentDocs(
328328
permalink: tagValue.permalink,
329329
count: tagValue.docIds.length,
330330
}));
331-
const tagsPropPath = await createData(
332-
`${docuHash(`tags-list-${loadedVersion.versionName}-prop`)}.json`,
333-
JSON.stringify(tagsProp, null, 2),
334-
);
335-
addRoute({
336-
path: loadedVersion.tagsPath,
337-
exact: true,
338-
component: options.docTagsListComponent,
339-
modules: {
340-
tags: aliasedSource(tagsPropPath),
341-
},
342-
});
331+
332+
// Only create /tags page if there are tags.
333+
if (Object.keys(tagsProp).length > 0) {
334+
const tagsPropPath = await createData(
335+
`${docuHash(`tags-list-${loadedVersion.versionName}-prop`)}.json`,
336+
JSON.stringify(tagsProp, null, 2),
337+
);
338+
addRoute({
339+
path: loadedVersion.tagsPath,
340+
exact: true,
341+
component: options.docTagsListComponent,
342+
modules: {
343+
tags: aliasedSource(tagsPropPath),
344+
},
345+
});
346+
}
343347
}
344348

345349
async function createTagDocListPage(tag: VersionTag) {

0 commit comments

Comments
 (0)