feat: doc tags (same as blog tags) (#3646)

* [v2] tags to doc, same as tags to blog - [IN PROGRESS]

- Addition of plugin-content-docs

- Addition of DocTagsListPage in `docusaurus-theme-classic`

! Error exists for this commit towards the theme aspect and help required.

Commit towards #3434

* docs: make tags list page work

* temp: disable onBrokenLinks

* theme bootstrap: create DocTagsListPage

* DocTagsPage added and functionality too

- individual doc tag page added to show docs for that specific tag

* Added all Docs Tags Link

* add some shared tag utils

* move tag tests to _dogfooding

* fix type

* fix some tests

* fix blog test

* refactor blog post tags handling

* better yaml tag examples

* better dogfood md files

* refactor and factorize theme tag components

* finish DocTagDocListPage

* Extract DocItemFooter + add inline tag list

* minor fix

* better typings

* fix versions.test.ts tests

* add tests for doc tags

* fix tests

* test toTagDocListProp

* move shared theme code to tagUtils

* Add new theme translation keys

* move common theme code to tagUtils + add tests

* update-code-translations should handle theme-common

* update french translation

* revert add translation

* fix pluralization problem in theme.docs.tagDocListPageTitle

* add theme component configuration options

* add more tags tests

* add documentation for docs tagging

Co-authored-by: slorber <lorber.sebastien@gmail.com>
This commit is contained in:
Isaac Philip 2021-08-19 14:01:15 +05:30 committed by GitHub
parent f666de7e59
commit f9c79cbd58
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
81 changed files with 1874 additions and 381 deletions

View file

@ -3,6 +3,11 @@ id: baz
title: baz
slug: bazSlug.html
pagination_label: baz pagination_label
tags:
- tag 1
- tag-1
- label: tag 2
permalink: tag2-custom-permalink
---
# Baz markdown title

View file

@ -2,6 +2,7 @@
id: hello
title: Hello, World !
sidebar_label: Hello sidebar_label
tags: [tag-1, tag 3]
---
Hi, Endilie here :)

View file

@ -1,4 +1,10 @@
---
slug: barSlug
tags:
- barTag 1
- barTag-2
- label: barTag 3
permalink: barTag-3-permalink
---
This is `next` version of bar.

View file

@ -177,6 +177,7 @@ Object {
\\"sourceDirName\\": \\"foo\\",
\\"slug\\": \\"/foo/bar\\",
\\"permalink\\": \\"/docs/foo/bar\\",
\\"tags\\": [],
\\"version\\": \\"current\\",
\\"frontMatter\\": {
\\"id\\": \\"bar\\",
@ -199,12 +200,30 @@ Object {
\\"sourceDirName\\": \\"foo\\",
\\"slug\\": \\"/foo/bazSlug.html\\",
\\"permalink\\": \\"/docs/foo/bazSlug.html\\",
\\"tags\\": [
{
\\"label\\": \\"tag 1\\",
\\"permalink\\": \\"/docs/tags/tag-1\\"
},
{
\\"label\\": \\"tag 2\\",
\\"permalink\\": \\"/docs/tags/tag2-custom-permalink\\"
}
],
\\"version\\": \\"current\\",
\\"frontMatter\\": {
\\"id\\": \\"baz\\",
\\"title\\": \\"baz\\",
\\"slug\\": \\"bazSlug.html\\",
\\"pagination_label\\": \\"baz pagination_label\\"
\\"pagination_label\\": \\"baz pagination_label\\",
\\"tags\\": [
\\"tag 1\\",
\\"tag-1\\",
{
\\"label\\": \\"tag 2\\",
\\"permalink\\": \\"tag2-custom-permalink\\"
}
]
},
\\"sidebar\\": \\"docs\\",
\\"previous\\": {
@ -226,6 +245,7 @@ Object {
\\"sourceDirName\\": \\".\\",
\\"slug\\": \\"/headingAsTitle\\",
\\"permalink\\": \\"/docs/headingAsTitle\\",
\\"tags\\": [],
\\"version\\": \\"current\\",
\\"frontMatter\\": {}
}",
@ -239,11 +259,25 @@ Object {
\\"sourceDirName\\": \\".\\",
\\"slug\\": \\"/\\",
\\"permalink\\": \\"/docs/\\",
\\"tags\\": [
{
\\"label\\": \\"tag-1\\",
\\"permalink\\": \\"/docs/tags/tag-1\\"
},
{
\\"label\\": \\"tag 3\\",
\\"permalink\\": \\"/docs/tags/tag-3\\"
}
],
\\"version\\": \\"current\\",
\\"frontMatter\\": {
\\"id\\": \\"hello\\",
\\"title\\": \\"Hello, World !\\",
\\"sidebar_label\\": \\"Hello sidebar_label\\"
\\"sidebar_label\\": \\"Hello sidebar_label\\",
\\"tags\\": [
\\"tag-1\\",
\\"tag 3\\"
]
},
\\"sidebar\\": \\"docs\\",
\\"previous\\": {
@ -262,6 +296,7 @@ Object {
\\"slug\\": \\"/ipsum\\",
\\"permalink\\": \\"/docs/ipsum\\",
\\"editUrl\\": null,
\\"tags\\": [],
\\"version\\": \\"current\\",
\\"frontMatter\\": {
\\"custom_edit_url\\": null
@ -278,6 +313,7 @@ Object {
\\"slug\\": \\"/lorem\\",
\\"permalink\\": \\"/docs/lorem\\",
\\"editUrl\\": \\"https://github.com/customUrl/docs/lorem.md\\",
\\"tags\\": [],
\\"version\\": \\"current\\",
\\"frontMatter\\": {
\\"custom_edit_url\\": \\"https://github.com/customUrl/docs/lorem.md\\",
@ -294,6 +330,7 @@ Object {
\\"sourceDirName\\": \\".\\",
\\"slug\\": \\"/rootAbsoluteSlug\\",
\\"permalink\\": \\"/docs/rootAbsoluteSlug\\",
\\"tags\\": [],
\\"version\\": \\"current\\",
\\"frontMatter\\": {
\\"slug\\": \\"/rootAbsoluteSlug\\"
@ -309,6 +346,7 @@ Object {
\\"sourceDirName\\": \\".\\",
\\"slug\\": \\"/rootRelativeSlug\\",
\\"permalink\\": \\"/docs/rootRelativeSlug\\",
\\"tags\\": [],
\\"version\\": \\"current\\",
\\"frontMatter\\": {
\\"slug\\": \\"rootRelativeSlug\\"
@ -324,6 +362,7 @@ Object {
\\"sourceDirName\\": \\".\\",
\\"slug\\": \\"/hey/rootResolvedSlug\\",
\\"permalink\\": \\"/docs/hey/rootResolvedSlug\\",
\\"tags\\": [],
\\"version\\": \\"current\\",
\\"frontMatter\\": {
\\"slug\\": \\"./hey/ho/../rootResolvedSlug\\"
@ -339,6 +378,7 @@ Object {
\\"sourceDirName\\": \\".\\",
\\"slug\\": \\"/rootTryToEscapeSlug\\",
\\"permalink\\": \\"/docs/rootTryToEscapeSlug\\",
\\"tags\\": [],
\\"version\\": \\"current\\",
\\"frontMatter\\": {
\\"slug\\": \\"../../../../../../../../rootTryToEscapeSlug\\"
@ -354,6 +394,7 @@ Object {
\\"sourceDirName\\": \\"slugs\\",
\\"slug\\": \\"/absoluteSlug\\",
\\"permalink\\": \\"/docs/absoluteSlug\\",
\\"tags\\": [],
\\"version\\": \\"current\\",
\\"frontMatter\\": {
\\"slug\\": \\"/absoluteSlug\\"
@ -369,6 +410,7 @@ Object {
\\"sourceDirName\\": \\"slugs\\",
\\"slug\\": \\"/slugs/relativeSlug\\",
\\"permalink\\": \\"/docs/slugs/relativeSlug\\",
\\"tags\\": [],
\\"version\\": \\"current\\",
\\"frontMatter\\": {
\\"slug\\": \\"relativeSlug\\"
@ -384,6 +426,7 @@ Object {
\\"sourceDirName\\": \\"slugs\\",
\\"slug\\": \\"/slugs/hey/resolvedSlug\\",
\\"permalink\\": \\"/docs/slugs/hey/resolvedSlug\\",
\\"tags\\": [],
\\"version\\": \\"current\\",
\\"frontMatter\\": {
\\"slug\\": \\"./hey/ho/../resolvedSlug\\"
@ -399,11 +442,74 @@ Object {
\\"sourceDirName\\": \\"slugs\\",
\\"slug\\": \\"/tryToEscapeSlug\\",
\\"permalink\\": \\"/docs/tryToEscapeSlug\\",
\\"tags\\": [],
\\"version\\": \\"current\\",
\\"frontMatter\\": {
\\"slug\\": \\"../../../../../../../../tryToEscapeSlug\\"
}
}",
"tag-docs-tags-tag-1-b3f.json": "{
\\"name\\": \\"tag 1\\",
\\"permalink\\": \\"/docs/tags/tag-1\\",
\\"docs\\": [
{
\\"id\\": \\"foo/baz\\",
\\"title\\": \\"baz\\",
\\"description\\": \\"Images\\",
\\"permalink\\": \\"/docs/foo/bazSlug.html\\"
},
{
\\"id\\": \\"hello\\",
\\"title\\": \\"Hello, World !\\",
\\"description\\": \\"Hi, Endilie here :)\\",
\\"permalink\\": \\"/docs/\\"
}
],
\\"allTagsPath\\": \\"/docs/tags\\"
}",
"tag-docs-tags-tag-2-custom-permalink-825.json": "{
\\"name\\": \\"tag 2\\",
\\"permalink\\": \\"/docs/tags/tag2-custom-permalink\\",
\\"docs\\": [
{
\\"id\\": \\"foo/baz\\",
\\"title\\": \\"baz\\",
\\"description\\": \\"Images\\",
\\"permalink\\": \\"/docs/foo/bazSlug.html\\"
}
],
\\"allTagsPath\\": \\"/docs/tags\\"
}",
"tag-docs-tags-tag-3-ab5.json": "{
\\"name\\": \\"tag 3\\",
\\"permalink\\": \\"/docs/tags/tag-3\\",
\\"docs\\": [
{
\\"id\\": \\"hello\\",
\\"title\\": \\"Hello, World !\\",
\\"description\\": \\"Hi, Endilie here :)\\",
\\"permalink\\": \\"/docs/\\"
}
],
\\"allTagsPath\\": \\"/docs/tags\\"
}",
"tags-list-current-prop-15a.json": "[
{
\\"name\\": \\"tag 1\\",
\\"permalink\\": \\"/docs/tags/tag-1\\",
\\"count\\": 2
},
{
\\"name\\": \\"tag 2\\",
\\"permalink\\": \\"/docs/tags/tag2-custom-permalink\\",
\\"count\\": 1
},
{
\\"name\\": \\"tag 3\\",
\\"permalink\\": \\"/docs/tags/tag-3\\",
\\"count\\": 1
}
]",
"version-current-metadata-prop-751.json": "{
\\"pluginId\\": \\"default\\",
\\"version\\": \\"current\\",
@ -560,6 +666,38 @@ Object {
exports[`simple website content: route config 1`] = `
Array [
Object {
"component": "@theme/DocTagsListPage",
"exact": true,
"modules": Object {
"tags": "~docs/tags-list-current-prop-15a.json",
},
"path": "/docs/tags",
},
Object {
"component": "@theme/DocTagDocListPage",
"exact": true,
"modules": Object {
"tag": "~docs/tag-docs-tags-tag-1-b3f.json",
},
"path": "/docs/tags/tag-1",
},
Object {
"component": "@theme/DocTagDocListPage",
"exact": true,
"modules": Object {
"tag": "~docs/tag-docs-tags-tag-3-ab5.json",
},
"path": "/docs/tags/tag-3",
},
Object {
"component": "@theme/DocTagDocListPage",
"exact": true,
"modules": Object {
"tag": "~docs/tag-docs-tags-tag-2-custom-permalink-825.json",
},
"path": "/docs/tags/tag2-custom-permalink",
},
Object {
"component": "@theme/DocPage",
"exact": false,
@ -857,6 +995,7 @@ Object {
\\"sourceDirName\\": \\".\\",
\\"slug\\": \\"/team\\",
\\"permalink\\": \\"/community/team\\",
\\"tags\\": [],
\\"version\\": \\"1.0.0\\",
\\"frontMatter\\": {},
\\"sidebar\\": \\"version-1.0.0/community\\"
@ -871,12 +1010,15 @@ Object {
\\"sourceDirName\\": \\".\\",
\\"slug\\": \\"/team\\",
\\"permalink\\": \\"/community/next/team\\",
\\"tags\\": [],
\\"version\\": \\"current\\",
\\"frontMatter\\": {
\\"title\\": \\"Team title translated\\"
},
\\"sidebar\\": \\"community\\"
}",
"tags-list-1-0-0-prop-483.json": "[]",
"tags-list-current-prop-15a.json": "[]",
"version-1-0-0-metadata-prop-608.json": "{
\\"pluginId\\": \\"community\\",
\\"version\\": \\"1.0.0\\",
@ -954,6 +1096,22 @@ Object {
exports[`versioned website (community) content: route config 1`] = `
Array [
Object {
"component": "@theme/DocTagsListPage",
"exact": true,
"modules": Object {
"tags": "~docs/tags-list-current-prop-15a.json",
},
"path": "/community/next/tags",
},
Object {
"component": "@theme/DocTagsListPage",
"exact": true,
"modules": Object {
"tags": "~docs/tags-list-1-0-0-prop-483.json",
},
"path": "/community/tags",
},
Object {
"component": "@theme/DocPage",
"exact": false,
@ -1106,9 +1264,31 @@ Object {
\\"sourceDirName\\": \\"foo\\",
\\"slug\\": \\"/foo/barSlug\\",
\\"permalink\\": \\"/docs/next/foo/barSlug\\",
\\"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\\"
}
],
\\"version\\": \\"current\\",
\\"frontMatter\\": {
\\"slug\\": \\"barSlug\\"
\\"slug\\": \\"barSlug\\",
\\"tags\\": [
\\"barTag 1\\",
\\"barTag-2\\",
{
\\"label\\": \\"barTag 3\\",
\\"permalink\\": \\"barTag-3-permalink\\"
}
]
},
\\"sidebar\\": \\"docs\\",
\\"next\\": {
@ -1126,6 +1306,7 @@ Object {
\\"sourceDirName\\": \\".\\",
\\"slug\\": \\"/\\",
\\"permalink\\": \\"/docs/next/\\",
\\"tags\\": [],
\\"version\\": \\"current\\",
\\"frontMatter\\": {},
\\"sidebar\\": \\"docs\\",
@ -1144,6 +1325,7 @@ Object {
\\"sourceDirName\\": \\"slugs\\",
\\"slug\\": \\"/absoluteSlug\\",
\\"permalink\\": \\"/docs/next/absoluteSlug\\",
\\"tags\\": [],
\\"version\\": \\"current\\",
\\"frontMatter\\": {
\\"slug\\": \\"/absoluteSlug\\"
@ -1159,6 +1341,7 @@ Object {
\\"sourceDirName\\": \\"slugs\\",
\\"slug\\": \\"/slugs/relativeSlug\\",
\\"permalink\\": \\"/docs/next/slugs/relativeSlug\\",
\\"tags\\": [],
\\"version\\": \\"current\\",
\\"frontMatter\\": {
\\"slug\\": \\"relativeSlug\\"
@ -1174,6 +1357,7 @@ Object {
\\"sourceDirName\\": \\"slugs\\",
\\"slug\\": \\"/slugs/hey/resolvedSlug\\",
\\"permalink\\": \\"/docs/next/slugs/hey/resolvedSlug\\",
\\"tags\\": [],
\\"version\\": \\"current\\",
\\"frontMatter\\": {
\\"slug\\": \\"./hey/ho/../resolvedSlug\\"
@ -1189,6 +1373,7 @@ Object {
\\"sourceDirName\\": \\"slugs\\",
\\"slug\\": \\"/tryToEscapeSlug\\",
\\"permalink\\": \\"/docs/next/tryToEscapeSlug\\",
\\"tags\\": [],
\\"version\\": \\"current\\",
\\"frontMatter\\": {
\\"slug\\": \\"../../../../../../../../tryToEscapeSlug\\"
@ -1204,6 +1389,7 @@ Object {
\\"sourceDirName\\": \\".\\",
\\"slug\\": \\"/\\",
\\"permalink\\": \\"/docs/1.0.0/\\",
\\"tags\\": [],
\\"version\\": \\"1.0.0\\",
\\"frontMatter\\": {},
\\"sidebar\\": \\"version-1.0.0/docs\\",
@ -1222,6 +1408,7 @@ Object {
\\"sourceDirName\\": \\"foo\\",
\\"slug\\": \\"/foo/barSlug\\",
\\"permalink\\": \\"/docs/1.0.0/foo/barSlug\\",
\\"tags\\": [],
\\"version\\": \\"1.0.0\\",
\\"frontMatter\\": {
\\"slug\\": \\"barSlug\\"
@ -1242,6 +1429,7 @@ Object {
\\"sourceDirName\\": \\"foo\\",
\\"slug\\": \\"/foo/baz\\",
\\"permalink\\": \\"/docs/1.0.0/foo/baz\\",
\\"tags\\": [],
\\"version\\": \\"1.0.0\\",
\\"frontMatter\\": {},
\\"sidebar\\": \\"version-1.0.0/docs\\",
@ -1264,6 +1452,7 @@ Object {
\\"sourceDirName\\": \\"foo\\",
\\"slug\\": \\"/foo/bar\\",
\\"permalink\\": \\"/docs/foo/bar\\",
\\"tags\\": [],
\\"version\\": \\"1.0.1\\",
\\"frontMatter\\": {},
\\"sidebar\\": \\"version-1.0.1/docs\\",
@ -1282,6 +1471,7 @@ Object {
\\"sourceDirName\\": \\".\\",
\\"slug\\": \\"/\\",
\\"permalink\\": \\"/docs/\\",
\\"tags\\": [],
\\"version\\": \\"1.0.1\\",
\\"frontMatter\\": {},
\\"sidebar\\": \\"version-1.0.1/docs\\",
@ -1300,6 +1490,7 @@ Object {
\\"sourceDirName\\": \\".\\",
\\"slug\\": \\"/rootAbsoluteSlug\\",
\\"permalink\\": \\"/docs/withSlugs/rootAbsoluteSlug\\",
\\"tags\\": [],
\\"version\\": \\"withSlugs\\",
\\"frontMatter\\": {
\\"slug\\": \\"/rootAbsoluteSlug\\"
@ -1316,6 +1507,7 @@ Object {
\\"sourceDirName\\": \\".\\",
\\"slug\\": \\"/rootRelativeSlug\\",
\\"permalink\\": \\"/docs/withSlugs/rootRelativeSlug\\",
\\"tags\\": [],
\\"version\\": \\"withSlugs\\",
\\"frontMatter\\": {
\\"slug\\": \\"rootRelativeSlug\\"
@ -1331,6 +1523,7 @@ Object {
\\"sourceDirName\\": \\".\\",
\\"slug\\": \\"/hey/rootResolvedSlug\\",
\\"permalink\\": \\"/docs/withSlugs/hey/rootResolvedSlug\\",
\\"tags\\": [],
\\"version\\": \\"withSlugs\\",
\\"frontMatter\\": {
\\"slug\\": \\"./hey/ho/../rootResolvedSlug\\"
@ -1346,6 +1539,7 @@ Object {
\\"sourceDirName\\": \\".\\",
\\"slug\\": \\"/rootTryToEscapeSlug\\",
\\"permalink\\": \\"/docs/withSlugs/rootTryToEscapeSlug\\",
\\"tags\\": [],
\\"version\\": \\"withSlugs\\",
\\"frontMatter\\": {
\\"slug\\": \\"../../../../../../../../rootTryToEscapeSlug\\"
@ -1361,6 +1555,7 @@ Object {
\\"sourceDirName\\": \\"slugs\\",
\\"slug\\": \\"/absoluteSlug\\",
\\"permalink\\": \\"/docs/withSlugs/absoluteSlug\\",
\\"tags\\": [],
\\"version\\": \\"withSlugs\\",
\\"frontMatter\\": {
\\"slug\\": \\"/absoluteSlug\\"
@ -1376,6 +1571,7 @@ Object {
\\"sourceDirName\\": \\"slugs\\",
\\"slug\\": \\"/slugs/relativeSlug\\",
\\"permalink\\": \\"/docs/withSlugs/slugs/relativeSlug\\",
\\"tags\\": [],
\\"version\\": \\"withSlugs\\",
\\"frontMatter\\": {
\\"slug\\": \\"relativeSlug\\"
@ -1391,6 +1587,7 @@ Object {
\\"sourceDirName\\": \\"slugs\\",
\\"slug\\": \\"/slugs/hey/resolvedSlug\\",
\\"permalink\\": \\"/docs/withSlugs/slugs/hey/resolvedSlug\\",
\\"tags\\": [],
\\"version\\": \\"withSlugs\\",
\\"frontMatter\\": {
\\"slug\\": \\"./hey/ho/../resolvedSlug\\"
@ -1406,11 +1603,71 @@ Object {
\\"sourceDirName\\": \\"slugs\\",
\\"slug\\": \\"/tryToEscapeSlug\\",
\\"permalink\\": \\"/docs/withSlugs/tryToEscapeSlug\\",
\\"tags\\": [],
\\"version\\": \\"withSlugs\\",
\\"frontMatter\\": {
\\"slug\\": \\"../../../../../../../../tryToEscapeSlug\\"
}
}",
"tag-docs-next-tags-bar-tag-1-a8f.json": "{
\\"name\\": \\"barTag 1\\",
\\"permalink\\": \\"/docs/next/tags/bar-tag-1\\",
\\"docs\\": [
{
\\"id\\": \\"foo/bar\\",
\\"title\\": \\"bar\\",
\\"description\\": \\"This is next version of bar.\\",
\\"permalink\\": \\"/docs/next/foo/barSlug\\"
}
],
\\"allTagsPath\\": \\"/docs/next/tags\\"
}",
"tag-docs-next-tags-bar-tag-2-216.json": "{
\\"name\\": \\"barTag-2\\",
\\"permalink\\": \\"/docs/next/tags/bar-tag-2\\",
\\"docs\\": [
{
\\"id\\": \\"foo/bar\\",
\\"title\\": \\"bar\\",
\\"description\\": \\"This is next version of bar.\\",
\\"permalink\\": \\"/docs/next/foo/barSlug\\"
}
],
\\"allTagsPath\\": \\"/docs/next/tags\\"
}",
"tag-docs-next-tags-bar-tag-3-permalink-94a.json": "{
\\"name\\": \\"barTag 3\\",
\\"permalink\\": \\"/docs/next/tags/barTag-3-permalink\\",
\\"docs\\": [
{
\\"id\\": \\"foo/bar\\",
\\"title\\": \\"bar\\",
\\"description\\": \\"This is next version of bar.\\",
\\"permalink\\": \\"/docs/next/foo/barSlug\\"
}
],
\\"allTagsPath\\": \\"/docs/next/tags\\"
}",
"tags-list-1-0-0-prop-483.json": "[]",
"tags-list-1-0-1-prop-c39.json": "[]",
"tags-list-current-prop-15a.json": "[
{
\\"name\\": \\"barTag 1\\",
\\"permalink\\": \\"/docs/next/tags/bar-tag-1\\",
\\"count\\": 1
},
{
\\"name\\": \\"barTag-2\\",
\\"permalink\\": \\"/docs/next/tags/bar-tag-2\\",
\\"count\\": 1
},
{
\\"name\\": \\"barTag 3\\",
\\"permalink\\": \\"/docs/next/tags/barTag-3-permalink\\",
\\"count\\": 1
}
]",
"tags-list-with-slugs-prop-1ca.json": "[]",
"version-1-0-0-metadata-prop-608.json": "{
\\"pluginId\\": \\"default\\",
\\"version\\": \\"1.0.0\\",
@ -1699,6 +1956,62 @@ Object {
exports[`versioned website content: route config 1`] = `
Array [
Object {
"component": "@theme/DocTagsListPage",
"exact": true,
"modules": Object {
"tags": "~docs/tags-list-1-0-0-prop-483.json",
},
"path": "/docs/1.0.0/tags",
},
Object {
"component": "@theme/DocTagsListPage",
"exact": true,
"modules": Object {
"tags": "~docs/tags-list-current-prop-15a.json",
},
"path": "/docs/next/tags",
},
Object {
"component": "@theme/DocTagDocListPage",
"exact": true,
"modules": Object {
"tag": "~docs/tag-docs-next-tags-bar-tag-1-a8f.json",
},
"path": "/docs/next/tags/bar-tag-1",
},
Object {
"component": "@theme/DocTagDocListPage",
"exact": true,
"modules": Object {
"tag": "~docs/tag-docs-next-tags-bar-tag-2-216.json",
},
"path": "/docs/next/tags/bar-tag-2",
},
Object {
"component": "@theme/DocTagDocListPage",
"exact": true,
"modules": Object {
"tag": "~docs/tag-docs-next-tags-bar-tag-3-permalink-94a.json",
},
"path": "/docs/next/tags/barTag-3-permalink",
},
Object {
"component": "@theme/DocTagsListPage",
"exact": true,
"modules": Object {
"tags": "~docs/tags-list-1-0-1-prop-c39.json",
},
"path": "/docs/tags",
},
Object {
"component": "@theme/DocTagsListPage",
"exact": true,
"modules": Object {
"tags": "~docs/tags-list-with-slugs-prop-1ca.json",
},
"path": "/docs/withSlugs/tags",
},
Object {
"component": "@theme/DocPage",
"exact": false,

View file

@ -187,6 +187,7 @@ describe('simple site', () => {
id: 'bar',
title: 'Bar',
},
tags: [],
});
await defaultTestUtils.testMeta(path.join('hello.md'), {
version: 'current',
@ -202,7 +203,18 @@ describe('simple site', () => {
id: 'hello',
title: 'Hello, World !',
sidebar_label: 'Hello sidebar_label',
tags: ['tag-1', 'tag 3'],
},
tags: [
{
label: 'tag-1',
permalink: '/docs/tags/tag-1',
},
{
label: 'tag 3',
permalink: '/docs/tags/tag-3',
},
],
});
});
@ -232,7 +244,18 @@ describe('simple site', () => {
id: 'hello',
title: 'Hello, World !',
sidebar_label: 'Hello sidebar_label',
tags: ['tag-1', 'tag 3'],
},
tags: [
{
label: 'tag-1',
permalink: '/docs/tags/tag-1',
},
{
label: 'tag 3',
permalink: '/docs/tags/tag-3',
},
],
});
});
@ -263,6 +286,7 @@ describe('simple site', () => {
id: 'bar',
title: 'Bar',
},
tags: [],
});
});
@ -297,7 +321,22 @@ describe('simple site', () => {
slug: 'bazSlug.html',
title: 'baz',
pagination_label: 'baz pagination_label',
tags: [
'tag 1',
'tag-1',
{label: 'tag 2', permalink: 'tag2-custom-permalink'},
],
},
tags: [
{
label: 'tag 1',
permalink: '/docs/tags/tag-1',
},
{
label: 'tag 2',
permalink: '/docs/tags/tag2-custom-permalink',
},
],
});
});
@ -319,6 +358,7 @@ describe('simple site', () => {
custom_edit_url: 'https://github.com/customUrl/docs/lorem.md',
unrelated_frontmatter: "won't be part of metadata",
},
tags: [],
});
});
@ -356,7 +396,22 @@ describe('simple site', () => {
slug: 'bazSlug.html',
title: 'baz',
pagination_label: 'baz pagination_label',
tags: [
'tag 1',
'tag-1',
{label: 'tag 2', permalink: 'tag2-custom-permalink'},
],
},
tags: [
{
label: 'tag 1',
permalink: '/docs/tags/tag-1',
},
{
label: 'tag 2',
permalink: '/docs/tags/tag2-custom-permalink',
},
],
});
expect(editUrlFunction).toHaveBeenCalledTimes(1);
@ -402,6 +457,7 @@ describe('simple site', () => {
lastUpdatedAt: 1539502055,
formattedLastUpdatedAt: '10/14/2018',
lastUpdatedBy: 'Author',
tags: [],
});
});
@ -559,6 +615,7 @@ describe('versioned site', () => {
await currentVersionTestUtils.testMeta(path.join('foo', 'bar.md'), {
id: 'foo/bar',
version: 'current',
unversionedId: 'foo/bar',
sourceDirName: 'foo',
isDocsHomePage: false,
@ -566,11 +623,35 @@ describe('versioned site', () => {
slug: '/foo/barSlug',
title: 'bar',
description: 'This is next version of bar.',
frontMatter: {slug: 'barSlug'},
version: 'current',
frontMatter: {
slug: 'barSlug',
tags: [
'barTag 1',
'barTag-2',
{
label: 'barTag 3',
permalink: 'barTag-3-permalink',
},
],
},
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',
},
],
});
await currentVersionTestUtils.testMeta(path.join('hello.md'), {
id: 'hello',
version: 'current',
unversionedId: 'hello',
sourceDirName: '.',
isDocsHomePage: false,
@ -579,7 +660,7 @@ describe('versioned site', () => {
title: 'hello',
description: 'Hello next !',
frontMatter: {},
version: 'current',
tags: [],
});
});
@ -597,6 +678,7 @@ describe('versioned site', () => {
description: 'Bar 1.0.0 !',
frontMatter: {slug: 'barSlug'},
version: '1.0.0',
tags: [],
});
await version100TestUtils.testMeta(path.join('hello.md'), {
id: 'version-1.0.0/hello',
@ -611,6 +693,7 @@ describe('versioned site', () => {
version: '1.0.0',
source:
'@site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md',
tags: [],
});
await version101TestUtils.testMeta(path.join('foo', 'bar.md'), {
id: 'version-1.0.1/foo/bar',
@ -623,6 +706,7 @@ describe('versioned site', () => {
description: 'Bar 1.0.1 !',
version: '1.0.1',
frontMatter: {},
tags: [],
});
await version101TestUtils.testMeta(path.join('hello.md'), {
id: 'version-1.0.1/hello',
@ -635,6 +719,7 @@ describe('versioned site', () => {
description: 'Hello 1.0.1 !',
version: '1.0.1',
frontMatter: {},
tags: [],
});
});
@ -729,6 +814,7 @@ describe('versioned site', () => {
source:
'@site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md',
editUrl: hardcodedEditUrl,
tags: [],
});
expect(editUrlFunction).toHaveBeenCalledTimes(1);
@ -771,6 +857,7 @@ describe('versioned site', () => {
'@site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md',
editUrl:
'https://github.com/facebook/docusaurus/edit/main/website/versioned_docs/version-1.0.0/hello.md',
tags: [],
});
});
@ -804,6 +891,7 @@ describe('versioned site', () => {
'@site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md',
editUrl:
'https://github.com/facebook/docusaurus/edit/main/website/docs/hello.md',
tags: [],
});
});
@ -838,6 +926,7 @@ describe('versioned site', () => {
'@site/i18n/fr/docusaurus-plugin-content-docs/version-1.0.0/hello.md',
editUrl:
'https://github.com/facebook/docusaurus/edit/main/website/i18n/fr/docusaurus-plugin-content-docs/version-1.0.0/hello.md',
tags: [],
});
});
@ -873,6 +962,7 @@ describe('versioned site', () => {
'@site/i18n/fr/docusaurus-plugin-content-docs/version-1.0.0/hello.md',
editUrl:
'https://github.com/facebook/docusaurus/edit/main/website/i18n/fr/docusaurus-plugin-content-docs/current/hello.md',
tags: [],
});
});
});

View file

@ -60,6 +60,7 @@ const defaultDocMetadata: Partial<DocMetadata> = {
lastUpdatedAt: undefined,
lastUpdatedBy: undefined,
formattedLastUpdatedAt: undefined,
tags: [],
};
const createFakeActions = (contentDir: string) => {
@ -364,7 +365,23 @@ describe('simple website', () => {
title: 'baz',
slug: 'bazSlug.html',
pagination_label: 'baz pagination_label',
tags: [
'tag 1',
'tag-1', // This one will be de-duplicated as it would lead to the same permalink as the first
{label: 'tag 2', permalink: 'tag2-custom-permalink'},
],
},
tags: [
{
label: 'tag 1',
permalink: '/docs/tags/tag-1',
},
{
label: 'tag 2',
permalink: '/docs/tags/tag2-custom-permalink',
},
],
});
expect(findDocById(currentVersion, 'hello')).toEqual({
@ -392,7 +409,18 @@ describe('simple website', () => {
id: 'hello',
title: 'Hello, World !',
sidebar_label: 'Hello sidebar_label',
tags: ['tag-1', 'tag 3'],
},
tags: [
{
label: 'tag-1',
permalink: '/docs/tags/tag-1',
},
{
label: 'tag 3',
permalink: '/docs/tags/tag-3',
},
],
});
expect(getDocById(currentVersion, 'foo/bar')).toEqual({
@ -579,6 +607,11 @@ describe('versioned website', () => {
description: 'This is next version of bar.',
frontMatter: {
slug: 'barSlug',
tags: [
'barTag 1',
'barTag-2',
{label: 'barTag 3', permalink: 'barTag-3-permalink'},
],
},
version: 'current',
sidebar: 'docs',
@ -586,6 +619,11 @@ describe('versioned website', () => {
title: 'hello',
permalink: '/docs/next/',
},
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'},
],
});
expect(getDocById(currentVersion, 'hello')).toEqual({
...defaultDocMetadata,

View file

@ -48,6 +48,8 @@ describe('normalizeDocsPluginOptions', () => {
numberPrefixParser: DefaultNumberPrefixParser,
docLayoutComponent: '@theme/DocPage',
docItemComponent: '@theme/DocItem',
docTagDocListComponent: '@theme/DocTagDocListPage',
docTagsListComponent: '@theme/DocTagsListPage',
remarkPlugins: [markdownPluginsObjectStub],
rehypePlugins: [markdownPluginsFunctionStub],
beforeDefaultRehypePlugins: [],

View file

@ -0,0 +1,62 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import {toTagDocListProp} from '../props';
describe('toTagDocListProp', () => {
type Params = Parameters<typeof toTagDocListProp>[0];
type Tag = Params['tag'];
type Doc = Params['docs'][number];
const allTagsPath = '/all/tags';
test('should work', () => {
const tag: Tag = {
name: 'tag1',
permalink: '/tag1',
docIds: ['id1', 'id3'],
};
const doc1: Doc = {
id: 'id1',
title: 'ZZZ 1',
description: 'Description 1',
permalink: '/doc1',
};
const doc2: Doc = {
id: 'id2',
title: 'XXX 2',
description: 'Description 2',
permalink: '/doc2',
};
const doc3: Doc = {
id: 'id3',
title: 'AAA 3',
description: 'Description 3',
permalink: '/doc3',
};
const doc4: Doc = {
id: 'id4',
title: 'UUU 4',
description: 'Description 4',
permalink: '/doc4',
};
const result = toTagDocListProp({
allTagsPath,
tag,
docs: [doc1, doc2, doc3, doc4],
});
expect(result).toEqual({
allTagsPath,
name: tag.name,
permalink: tag.permalink,
docs: [doc3, doc1], // docs sorted by title, ignore "id5" absence
});
});
});

View file

@ -77,6 +77,7 @@ describe('simple site', () => {
isLast: true,
routePriority: -1,
sidebarFilePath: undefined,
tagsPath: '/docs/tags',
versionLabel: 'Next',
versionName: 'current',
versionPath: '/docs',
@ -111,6 +112,7 @@ describe('simple site', () => {
{
...vCurrent,
versionPath: '/myBaseUrl/docs',
tagsPath: '/myBaseUrl/docs/tags',
},
]);
});
@ -141,6 +143,7 @@ describe('simple site', () => {
versionLabel: 'current-label',
routePriority: undefined,
sidebarFilePath: undefined,
tagsPath: '/myBaseUrl/docs/current-path/tags',
versionEditUrl: undefined,
versionEditUrlLocalized: undefined,
},
@ -232,6 +235,7 @@ describe('versioned site, pluginId=default', () => {
isLast: false,
routePriority: undefined,
sidebarFilePath: path.join(versionedSiteDir, 'sidebars.json'),
tagsPath: '/docs/next/tags',
versionLabel: 'Next',
versionName: 'current',
versionPath: '/docs/next',
@ -250,6 +254,7 @@ describe('versioned site, pluginId=default', () => {
versionedSiteDir,
'versioned_sidebars/version-1.0.1-sidebars.json',
),
tagsPath: '/docs/tags',
versionLabel: '1.0.1',
versionName: '1.0.1',
versionPath: '/docs',
@ -268,6 +273,7 @@ describe('versioned site, pluginId=default', () => {
versionedSiteDir,
'versioned_sidebars/version-1.0.0-sidebars.json',
),
tagsPath: '/docs/1.0.0/tags',
versionLabel: '1.0.0',
versionName: '1.0.0',
versionPath: '/docs/1.0.0',
@ -289,6 +295,7 @@ describe('versioned site, pluginId=default', () => {
versionedSiteDir,
'versioned_sidebars/version-withSlugs-sidebars.json',
),
tagsPath: '/docs/withSlugs/tags',
versionLabel: 'withSlugs',
versionName: 'withSlugs',
versionPath: '/docs/withSlugs',
@ -377,6 +384,7 @@ describe('versioned site, pluginId=default', () => {
expect(versionsMetadata).toEqual([
{
...vCurrent,
tagsPath: '/docs/current-path/tags',
versionPath: '/docs/current-path',
versionBanner: 'unmaintained',
},
@ -384,6 +392,7 @@ describe('versioned site, pluginId=default', () => {
...v101,
isLast: false,
routePriority: undefined,
tagsPath: '/docs/1.0.1/tags',
versionPath: '/docs/1.0.1',
versionBanner: 'unreleased',
},
@ -391,6 +400,7 @@ describe('versioned site, pluginId=default', () => {
...v100,
isLast: true,
routePriority: -1,
tagsPath: '/docs/tags',
versionLabel: '1.0.0-label',
versionPath: '/docs',
versionBanner: 'unreleased',
@ -528,6 +538,7 @@ describe('versioned site, pluginId=default', () => {
...vCurrent,
isLast: true,
routePriority: -1,
tagsPath: '/docs/tags',
versionPath: '/docs',
versionBanner: 'none',
},
@ -648,6 +659,7 @@ describe('versioned site, pluginId=community', () => {
isLast: false,
routePriority: undefined,
sidebarFilePath: path.join(versionedSiteDir, 'sidebars.json'),
tagsPath: '/communityBasePath/next/tags',
versionLabel: 'Next',
versionName: 'current',
versionPath: '/communityBasePath/next',
@ -669,6 +681,7 @@ describe('versioned site, pluginId=community', () => {
versionedSiteDir,
'community_versioned_sidebars/version-1.0.0-sidebars.json',
),
tagsPath: '/communityBasePath/tags',
versionLabel: '1.0.0',
versionName: '1.0.0',
versionPath: '/communityBasePath',
@ -716,6 +729,7 @@ describe('versioned site, pluginId=community', () => {
...vCurrent,
isLast: true,
routePriority: -1,
tagsPath: '/communityBasePath/tags',
versionPath: '/communityBasePath',
versionBanner: 'none',
},

View file

@ -15,6 +15,7 @@ import {
parseMarkdownString,
posixPath,
Globby,
normalizeFrontMatterTags,
} from '@docusaurus/utils';
import {LoadContext} from '@docusaurus/types';
@ -252,6 +253,7 @@ function doProcessDocMetadata({
slug: docSlug,
permalink,
editUrl: customEditURL !== undefined ? customEditURL : getDocEditUrl(),
tags: normalizeFrontMatterTags(versionMetadata.tagsPath, frontMatter.tags),
version: versionMetadata.versionName,
lastUpdatedBy: lastUpdate.lastUpdatedBy,
lastUpdatedAt: lastUpdate.lastUpdatedAt,

View file

@ -37,19 +37,22 @@ import {
LoadedVersion,
DocFile,
DocsMarkdownOption,
VersionTag,
} from './types';
import {RuleSetRule} from 'webpack';
import {cliDocsVersionCommand} from './cli';
import {VERSIONS_JSON_FILE} from './constants';
import {flatten, keyBy, compact, mapValues} from 'lodash';
import {toGlobalDataVersion} from './globalData';
import {toVersionMetadataProp} from './props';
import {toTagDocListProp, toVersionMetadataProp} from './props';
import {
translateLoadedContent,
getLoadedContentTranslationFiles,
} from './translations';
import {CategoryMetadataFilenamePattern} from './sidebarItemsGenerator';
import chalk from 'chalk';
import {getVersionTags} from './tags';
import {PropTagsListPage} from '@docusaurus/plugin-content-docs-types';
export default function pluginContentDocs(
context: LoadContext,
@ -314,9 +317,60 @@ export default function pluginContentDocs(
return routes.sort((a, b) => a.path.localeCompare(b.path));
};
async function createVersionTagsRoutes(loadedVersion: LoadedVersion) {
const versionTags = getVersionTags(loadedVersion.docs);
async function createTagsListPage() {
const tagsProp: PropTagsListPage['tags'] = Object.values(
versionTags,
).map((tagValue) => ({
name: tagValue.name,
permalink: tagValue.permalink,
count: tagValue.docIds.length,
}));
const tagsPropPath = await createData(
`${docuHash(`tags-list-${loadedVersion.versionName}-prop`)}.json`,
JSON.stringify(tagsProp, null, 2),
);
addRoute({
path: loadedVersion.tagsPath,
exact: true,
component: options.docTagsListComponent,
modules: {
tags: aliasedSource(tagsPropPath),
},
});
}
async function createTagDocListPage(tag: VersionTag) {
const tagProps = toTagDocListProp({
allTagsPath: loadedVersion.tagsPath,
tag,
docs: loadedVersion.docs,
});
const tagPropPath = await createData(
`${docuHash(`tag-${tag.permalink}`)}.json`,
JSON.stringify(tagProps, null, 2),
);
addRoute({
path: tag.permalink,
component: options.docTagDocListComponent,
exact: true,
modules: {
tag: aliasedSource(tagPropPath),
},
});
}
await createTagsListPage();
await Promise.all(Object.values(versionTags).map(createTagDocListPage));
}
async function doCreateVersionRoutes(
loadedVersion: LoadedVersion,
): Promise<void> {
await createVersionTagsRoutes(loadedVersion);
const versionMetadata = toVersionMetadataProp(pluginId, loadedVersion);
const versionMetadataPropPath = await createData(
`${docuHash(

View file

@ -33,6 +33,8 @@ export const DEFAULT_OPTIONS: Omit<PluginOptions, 'id' | 'sidebarPath'> = {
numberPrefixParser: DefaultNumberPrefixParser,
docLayoutComponent: '@theme/DocPage',
docItemComponent: '@theme/DocItem',
docTagDocListComponent: '@theme/DocTagDocListPage',
docTagsListComponent: '@theme/DocTagsListPage',
remarkPlugins: [],
rehypePlugins: [],
beforeDefaultRemarkPlugins: [],
@ -94,6 +96,12 @@ export const OptionsSchema = Joi.object({
.default(() => DEFAULT_OPTIONS.numberPrefixParser),
docLayoutComponent: Joi.string().default(DEFAULT_OPTIONS.docLayoutComponent),
docItemComponent: Joi.string().default(DEFAULT_OPTIONS.docItemComponent),
docTagsListComponent: Joi.string().default(
DEFAULT_OPTIONS.docTagsListComponent,
),
docTagDocListComponent: Joi.string().default(
DEFAULT_OPTIONS.docTagDocListComponent,
),
remarkPlugins: RemarkPluginsSchema.default(DEFAULT_OPTIONS.remarkPlugins),
rehypePlugins: RehypePluginsSchema.default(DEFAULT_OPTIONS.rehypePlugins),
beforeDefaultRemarkPlugins: RemarkPluginsSchema.default(

View file

@ -9,6 +9,9 @@ declare module '@docusaurus/plugin-content-docs-types' {
type VersionBanner = import('./types').VersionBanner;
type GlobalDataVersion = import('./types').GlobalVersion;
type GlobalDataDoc = import('./types').GlobalDoc;
type VersionTag = import('./types').VersionTag;
export type {GlobalDataVersion, GlobalDataDoc};
export type PropVersionMetadata = {
pluginId: string;
@ -43,7 +46,26 @@ declare module '@docusaurus/plugin-content-docs-types' {
[sidebarId: string]: PropSidebarItem[];
};
export type {GlobalDataVersion, GlobalDataDoc};
export type PropTagDocListDoc = {
id: string;
title: string;
description: string;
permalink: string;
};
export type PropTagDocList = {
allTagsPath: string;
name: string; // normalized name/label of the tag
permalink: string; // pathname of the tag
docs: PropTagDocListDoc[];
};
export type PropTagsListPage = {
tags: {
name: string;
permalink: string;
count: number;
}[];
};
}
declare module '@theme/DocItem' {
@ -79,6 +101,10 @@ declare module '@theme/DocItem' {
readonly version?: string;
readonly previous?: {readonly permalink: string; readonly title: string};
readonly next?: {readonly permalink: string; readonly title: string};
readonly tags: readonly {
readonly label: string;
readonly permalink: string;
}[];
};
export type Props = {
@ -97,6 +123,19 @@ declare module '@theme/DocItem' {
export default DocItem;
}
declare module '@theme/DocItemFooter' {
import type {Props} from '@theme/DocItem';
export default function DocItemFooter(props: Props): JSX.Element;
}
declare module '@theme/DocTagsListPage' {
import type {PropTagsListPage} from '@docusaurus/plugin-content-docs-types';
export type Props = PropTagsListPage;
export default function DocItemFooter(props: Props): JSX.Element;
}
declare module '@theme/DocVersionBanner' {
import type {PropVersionMetadata} from '@docusaurus/plugin-content-docs-types';

View file

@ -10,13 +10,17 @@ import {
SidebarItemDoc,
SidebarItemLink,
SidebarItem,
VersionTag,
DocMetadata,
} from './types';
import {
import type {
PropSidebars,
PropVersionMetadata,
PropSidebarItem,
PropTagDocList,
PropTagDocListDoc,
} from '@docusaurus/plugin-content-docs-types';
import {keyBy, mapValues} from 'lodash';
import {compact, keyBy, mapValues} from 'lodash';
export function toSidebarsProp(loadedVersion: LoadedVersion): PropSidebars {
const docsById = keyBy(loadedVersion.docs, (doc) => doc.id);
@ -79,3 +83,34 @@ export function toVersionMetadataProp(
docsSidebars: toSidebarsProp(loadedVersion),
};
}
export function toTagDocListProp({
allTagsPath,
tag,
docs,
}: {
allTagsPath: string;
tag: VersionTag;
docs: Pick<DocMetadata, 'id' | 'title' | 'description' | 'permalink'>[];
}): PropTagDocList {
function toDocListProp(): PropTagDocListDoc[] {
const list = compact(
tag.docIds.map((id) => docs.find((doc) => doc.id === id)),
);
// Sort docs by title
list.sort((doc1, doc2) => doc1.title.localeCompare(doc2.title));
return list.map((doc) => ({
id: doc.id,
title: doc.title,
description: doc.description,
permalink: doc.permalink,
}));
}
return {
name: tag.name,
permalink: tag.permalink,
docs: toDocListProp(),
allTagsPath,
};
}

View file

@ -0,0 +1,21 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import {groupTaggedItems} from '@docusaurus/utils';
import {VersionTags, DocMetadata} from './types';
import {mapValues} from 'lodash';
export function getVersionTags(docs: DocMetadata[]): VersionTags {
const groups = groupTaggedItems(docs, (doc) => doc.tags);
return mapValues(groups, (group) => {
return {
name: group.tag.label,
docIds: group.items.map((item) => item.id),
permalink: group.tag.permalink,
};
});
}

View file

@ -9,7 +9,8 @@
/// <reference types="@docusaurus/module-type-aliases" />
import type {RemarkAndRehypePluginOptions} from '@docusaurus/mdx-loader';
import {
import type {Tag, FrontMatterTag} from '@docusaurus/utils';
import type {
BrokenMarkdownLink as IBrokenMarkdownLink,
ContentPaths,
} from '@docusaurus/utils/lib/markdownLinks';
@ -28,6 +29,7 @@ export type VersionMetadata = ContentPaths & {
versionName: VersionName; // 1.0.0
versionLabel: string; // Version 1.0.0
versionPath: string; // /baseUrl/docs/1.0.0
tagsPath: string;
versionEditUrl?: string | undefined;
versionEditUrlLocalized?: string | undefined;
versionBanner: VersionBanner;
@ -90,6 +92,8 @@ export type PluginOptions = MetadataOptions &
exclude: string[];
docLayoutComponent: string;
docItemComponent: string;
docTagDocListComponent: string;
docTagsListComponent: string;
admonitions: Record<string, unknown>;
disableVersioning: boolean;
includeCurrentVersion: boolean;
@ -200,6 +204,7 @@ export type DocFrontMatter = {
/* eslint-disable camelcase */
id?: string;
title?: string;
tags?: FrontMatterTag[];
hide_title?: boolean;
hide_table_of_contents?: boolean;
keywords?: string[];
@ -227,6 +232,7 @@ export type DocMetadataBase = LastUpdateData & {
permalink: string;
sidebarPosition?: number;
editUrl?: string | null;
tags: Tag[];
frontMatter: DocFrontMatter & Record<string, unknown>;
};
@ -244,6 +250,16 @@ export type DocMetadata = DocMetadataBase & {
export type SourceToPermalink = {
[source: string]: string;
};
export type VersionTag = {
name: string; // normalized name/label of the tag
docIds: string[]; // all doc ids having this tag
permalink: string; // pathname of the tag
};
export type VersionTags = {
[key: string]: VersionTag;
};
export type LoadedVersion = VersionMetadata & {
versionPath: string;
mainDocId: string;

View file

@ -370,10 +370,15 @@ function createVersionMetadata({
// Because /docs/:route` should always be after `/docs/versionName/:route`.
const routePriority = versionPathPart === '' ? -1 : undefined;
// the path that will be used to refer the docs tags
// example below will be using /docs/tags
const tagsPath = normalizeUrl([versionPath, 'tags']);
return {
versionName,
versionLabel,
versionPath,
tagsPath,
versionEditUrl: versionEditUrls?.versionEditUrl,
versionEditUrlLocalized: versionEditUrls?.versionEditUrlLocalized,
versionBanner: getVersionBanner({