Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed Apr 6, 2022
1 parent c6c5355 commit 7127b4d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
21 changes: 11 additions & 10 deletions packages/docusaurus-plugin-content-docs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
createSlugger,
DEFAULT_PLUGIN_ID,
} from '@docusaurus/utils';
import type {LoadContext, Plugin, TagsListItem} from '@docusaurus/types';
import type {LoadContext, Plugin} from '@docusaurus/types';
import {loadSidebars} from './sidebars';
import {CategoryMetadataFilenamePattern} from './sidebars/generator';
import {
Expand Down Expand Up @@ -50,6 +50,7 @@ import logger from '@docusaurus/logger';
import {getVersionTags} from './tags';
import {createVersionRoutes} from './routes';
import type {
PropTagsListPage,
PluginOptions,
DocMetadataBase,
VersionMetadata,
Expand Down Expand Up @@ -224,13 +225,13 @@ export default async function pluginContentDocs(

// TODO tags should be a sub route of the version route
async function createTagsListPage() {
const tagsProp: TagsListItem[] = Object.values(versionTags).map(
(tag) => ({
label: tag.label,
permalink: tag.permalink,
count: tag.docIds.length,
}),
);
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) {
Expand All @@ -251,14 +252,14 @@ export default async function pluginContentDocs(

// TODO tags should be a sub route of the version route
async function createTagDocListPage(tag: VersionTag) {
const tagItemsProp = toTagDocListProp({
const tagProps = toTagDocListProp({
allTagsPath: version.tagsPath,
tag,
docs: version.docs,
});
const tagPropPath = await createData(
`${docuHash(`tag-${tag.permalink}`)}.json`,
JSON.stringify(tagItemsProp, null, 2),
JSON.stringify(tagProps, null, 2),
);
addRoute({
path: tag.permalink,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,7 @@ declare module '@docusaurus/plugin-content-docs' {
DocMetadata,
'id' | 'title' | 'description' | 'permalink'
>;
export type PropTagDocList = {
tag: TagModule & {items: PropTagDocListDoc[]};
};
export type PropTagDocList = TagModule & {items: PropTagDocListDoc[]};

export type PropTagsListPage = {
tags: TagsListItem[];
Expand Down Expand Up @@ -551,7 +549,9 @@ declare module '@theme/DocTagsListPage' {
declare module '@theme/DocTagDocListPage' {
import type {PropTagDocList} from '@docusaurus/plugin-content-docs';

export interface Props extends PropTagDocList {}
export interface Props {
readonly tag: PropTagDocList;
}
export default function DocTagDocListPage(props: Props): JSX.Element;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-content-docs/src/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export function toTagDocListProp({
allTagsPath: string;
tag: VersionTag;
docs: DocMetadata[];
}): PropTagDocList['tag'] {
}): PropTagDocList {
function toDocListProp(): PropTagDocListDoc[] {
const list = _.compact(
tag.docIds.map((id) => docs.find((doc) => doc.id === id)),
Expand Down

0 comments on commit 7127b4d

Please sign in to comment.