mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-18 02:32:28 +02:00
refactor(content-docs): deduplicate types, JSDoc for some APIs (#7027)
* refactor(content-docs): deduplicate types, JSDoc for some APIs * little refactor
This commit is contained in:
parent
b842197ac6
commit
2bcac29cd4
38 changed files with 715 additions and 521 deletions
|
@ -7,12 +7,11 @@
|
|||
|
||||
import type {PluginContentLoadedActions, RouteConfig} from '@docusaurus/types';
|
||||
import {docuHash, createSlugger} from '@docusaurus/utils';
|
||||
import type {LoadedVersion} from './types';
|
||||
import type {
|
||||
CategoryGeneratedIndexMetadata,
|
||||
DocMetadata,
|
||||
LoadedVersion,
|
||||
} from './types';
|
||||
import type {PropCategoryGeneratedIndex} from '@docusaurus/plugin-content-docs';
|
||||
} from '@docusaurus/plugin-content-docs';
|
||||
import {toVersionMetadataProp} from './props';
|
||||
import logger from '@docusaurus/logger';
|
||||
|
||||
|
@ -32,42 +31,19 @@ export async function createCategoryGeneratedIndexRoutes({
|
|||
async function createCategoryGeneratedIndexRoute(
|
||||
categoryGeneratedIndex: CategoryGeneratedIndexMetadata,
|
||||
): Promise<RouteConfig> {
|
||||
const {
|
||||
sidebar,
|
||||
title,
|
||||
description,
|
||||
slug,
|
||||
permalink,
|
||||
previous,
|
||||
next,
|
||||
image,
|
||||
keywords,
|
||||
} = categoryGeneratedIndex;
|
||||
const {sidebar, ...prop} = categoryGeneratedIndex;
|
||||
|
||||
const propFileName = slugs.slug(
|
||||
`${version.versionPath}-${categoryGeneratedIndex.sidebar}-category-${categoryGeneratedIndex.title}`,
|
||||
`${version.path}-${categoryGeneratedIndex.sidebar}-category-${categoryGeneratedIndex.title}`,
|
||||
);
|
||||
|
||||
const prop: PropCategoryGeneratedIndex = {
|
||||
title,
|
||||
description,
|
||||
slug,
|
||||
permalink,
|
||||
image,
|
||||
keywords,
|
||||
navigation: {
|
||||
previous,
|
||||
next,
|
||||
},
|
||||
};
|
||||
|
||||
const propData = await actions.createData(
|
||||
`${docuHash(`category/${propFileName}`)}.json`,
|
||||
JSON.stringify(prop, null, 2),
|
||||
);
|
||||
|
||||
return {
|
||||
path: permalink,
|
||||
path: categoryGeneratedIndex.permalink,
|
||||
component: docCategoryGeneratedIndexComponent,
|
||||
exact: true,
|
||||
modules: {
|
||||
|
@ -162,7 +138,7 @@ export async function createVersionRoutes({
|
|||
}
|
||||
|
||||
actions.addRoute({
|
||||
path: version.versionPath,
|
||||
path: version.path,
|
||||
// allow matching /docs/* as well
|
||||
exact: false,
|
||||
// main docs component (DocPage)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue