Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1083,38 +1083,6 @@ exports[`simple website content: global data 1`] = `

exports[`simple website content: route config 1`] = `
[
{
"component": "@theme/DocTagsListPage",
"exact": true,
"modules": {
"tags": "~docs/tags-list-current-prop-15a.json",
},
"path": "/docs/tags",
},
{
"component": "@theme/DocTagDocListPage",
"exact": true,
"modules": {
"tag": "~docs/tag-docs-tags-tag-1-b3f.json",
},
"path": "/docs/tags/tag-1",
},
{
"component": "@theme/DocTagDocListPage",
"exact": true,
"modules": {
"tag": "~docs/tag-docs-tags-tag-3-ab5.json",
},
"path": "/docs/tags/tag-3",
},
{
"component": "@theme/DocTagDocListPage",
"exact": true,
"modules": {
"tag": "~docs/tag-docs-tags-tag-2-custom-permalink-825.json",
},
"path": "/docs/tags/tag2-custom-permalink",
},
{
"component": "@theme/DocPage",
"exact": false,
Expand Down Expand Up @@ -1253,6 +1221,38 @@ exports[`simple website content: route config 1`] = `
},
"path": "/docs/slugs/relativeSlug",
},
{
"component": "@theme/DocTagsListPage",
"exact": true,
"modules": {
"tags": "~docs/tags-list-current-prop-15a.json",
},
"path": "/docs/tags",
},
{
"component": "@theme/DocTagDocListPage",
"exact": true,
"modules": {
"tag": "~docs/tag-docs-tags-tag-1-b3f.json",
},
"path": "/docs/tags/tag-1",
},
{
"component": "@theme/DocTagDocListPage",
"exact": true,
"modules": {
"tag": "~docs/tag-docs-tags-tag-3-ab5.json",
},
"path": "/docs/tags/tag-3",
},
{
"component": "@theme/DocTagDocListPage",
"exact": true,
"modules": {
"tag": "~docs/tag-docs-tags-tag-2-custom-permalink-825.json",
},
"path": "/docs/tags/tag2-custom-permalink",
},
{
"component": "@theme/DocItem",
"exact": true,
Expand Down Expand Up @@ -3681,38 +3681,6 @@ exports[`versioned website content: global data 1`] = `

exports[`versioned website content: route config 1`] = `
[
{
"component": "@theme/DocTagsListPage",
"exact": true,
"modules": {
"tags": "~docs/tags-list-current-prop-15a.json",
},
"path": "/docs/next/tags",
},
{
"component": "@theme/DocTagDocListPage",
"exact": true,
"modules": {
"tag": "~docs/tag-docs-next-tags-bar-tag-1-a8f.json",
},
"path": "/docs/next/tags/bar-tag-1",
},
{
"component": "@theme/DocTagDocListPage",
"exact": true,
"modules": {
"tag": "~docs/tag-docs-next-tags-bar-tag-2-216.json",
},
"path": "/docs/next/tags/bar-tag-2",
},
{
"component": "@theme/DocTagDocListPage",
"exact": true,
"modules": {
"tag": "~docs/tag-docs-next-tags-bar-tag-3-permalink-94a.json",
},
"path": "/docs/next/tags/barTag-3-permalink",
},
{
"component": "@theme/DocPage",
"exact": false,
Expand Down Expand Up @@ -3802,6 +3770,38 @@ exports[`versioned website content: route config 1`] = `
},
"path": "/docs/next/slugs/relativeSlug",
},
{
"component": "@theme/DocTagsListPage",
"exact": true,
"modules": {
"tags": "~docs/tags-list-current-prop-15a.json",
},
"path": "/docs/next/tags",
},
{
"component": "@theme/DocTagDocListPage",
"exact": true,
"modules": {
"tag": "~docs/tag-docs-next-tags-bar-tag-1-a8f.json",
},
"path": "/docs/next/tags/bar-tag-1",
},
{
"component": "@theme/DocTagDocListPage",
"exact": true,
"modules": {
"tag": "~docs/tag-docs-next-tags-bar-tag-2-216.json",
},
"path": "/docs/next/tags/bar-tag-2",
},
{
"component": "@theme/DocTagDocListPage",
"exact": true,
"modules": {
"tag": "~docs/tag-docs-next-tags-bar-tag-3-permalink-94a.json",
},
"path": "/docs/next/tags/barTag-3-permalink",
},
{
"component": "@theme/DocItem",
"exact": true,
Expand Down
68 changes: 5 additions & 63 deletions packages/docusaurus-plugin-content-docs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,18 @@ import type {
LoadedVersion,
DocFile,
DocsMarkdownOption,
VersionTag,
} from './types';
import type {RuleSetRule} from 'webpack';
import {cliDocsVersionCommand} from './cli';
import {VERSIONS_JSON_FILE} from './constants';
import {toGlobalDataVersion} from './globalData';
import {toTagDocListProp} from './props';
import {
translateLoadedContent,
getLoadedContentTranslationFiles,
} from './translations';
import logger from '@docusaurus/logger';
import {getVersionTags} from './tags';
import {createVersionRoutes} from './routes';
import type {
PropTagsListPage,
PluginOptions,
DocMetadataBase,
VersionMetadata,
Expand Down Expand Up @@ -213,64 +209,11 @@ export default async function pluginContentDocs(
docLayoutComponent,
docItemComponent,
docCategoryGeneratedIndexComponent,
docTagsListComponent,
docTagDocListComponent,
breadcrumbs,
} = options;
const {addRoute, createData, setGlobalData} = actions;

async function createVersionTagsRoutes(version: LoadedVersion) {
const versionTags = getVersionTags(version.docs);

// TODO tags should be a sub route of the version route
async function createTagsListPage() {
const tagsProp: PropTagsListPage['tags'] = Object.values(
versionTags,
).map((tagValue) => ({
label: tagValue.label,
permalink: tagValue.permalink,
count: tagValue.docIds.length,
}));

// Only create /tags page if there are tags.
if (tagsProp.length > 0) {
const tagsPropPath = await createData(
`${docuHash(`tags-list-${version.versionName}-prop`)}.json`,
JSON.stringify(tagsProp, null, 2),
);
addRoute({
path: version.tagsPath,
exact: true,
component: options.docTagsListComponent,
modules: {
tags: aliasedSource(tagsPropPath),
},
});
}
}

// TODO tags should be a sub route of the version route
async function createTagDocListPage(tag: VersionTag) {
const tagProps = toTagDocListProp({
allTagsPath: version.tagsPath,
tag,
docs: version.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));
}
const {setGlobalData} = actions;

await Promise.all(
loadedVersions.map((loadedVersion) =>
Expand All @@ -279,16 +222,15 @@ export default async function pluginContentDocs(
docItemComponent,
docLayoutComponent,
docCategoryGeneratedIndexComponent,
docTagsListComponent,
docTagDocListComponent,
pluginId,
aliasedSource,
actions,
}),
),
);

// TODO tags should be a sub route of the version route
await Promise.all(loadedVersions.map(createVersionTagsRoutes));

setGlobalData({
path: normalizeUrl([baseUrl, options.routeBasePath]),
versions: loadedVersions.map(toGlobalDataVersion),
Expand Down
Loading