fix(build): build error caused by non-exsisting readme

This commit is contained in:
KirisameVanilla 2025-09-28 10:19:17 +08:00
parent 34c949d43f
commit f2ceda77aa
No known key found for this signature in database
GPG Key ID: A68EE6C617D68238
1 changed files with 89 additions and 83 deletions

View File

@ -5,13 +5,13 @@ import {
useDocById,
findFirstSidebarItemLink,
} from '@docusaurus/plugin-content-docs/client';
import {usePluralForm} from '@docusaurus/theme-common';
import { usePluralForm } from '@docusaurus/theme-common';
import isInternalUrl from '@docusaurus/isInternalUrl';
import {translate} from '@docusaurus/Translate';
import { translate } from '@docusaurus/Translate';
import Heading from '@theme/Heading';
import styles from './styles.module.css';
function useCategoryItemsPlural() {
const {selectMessage} = usePluralForm();
const { selectMessage } = usePluralForm();
return (count) =>
selectMessage(
count,
@ -22,11 +22,11 @@ function useCategoryItemsPlural() {
description:
'The default description for a category card in the generated index about how many items this category includes',
},
{count},
{ count },
),
);
}
function CardContainer({className, href, children}) {
function CardContainer({ className, href, children }) {
return (
<Link
href={href}
@ -35,7 +35,7 @@ function CardContainer({className, href, children}) {
</Link>
);
}
function CardLayout({className, href, icon, title, description}) {
function CardLayout({ className, href, icon, title, description }) {
return (
<CardContainer href={href} className={className}>
<Heading
@ -54,26 +54,32 @@ function CardLayout({className, href, icon, title, description}) {
</CardContainer>
);
}
function CardCategory({item}) {
function CardCategory({ item }) {
const href = findFirstSidebarItemLink(item);
const categoryItemsPlural = useCategoryItemsPlural();
// Unexpected: categories that don't have a link have been filtered upfront
if (!href) {
return null;
}
const docId = href.substring(6) + 'README';
const doc = useDocById(docId ?? undefined);
const ReadMeSubfix = href.endsWith('/') ? 'README' : '/README';
const docId = href.substring(6) + ReadMeSubfix;
let doc;
try {
doc = useDocById(docId ?? undefined);
} catch (e) {
doc = null;
}
return (
<CardLayout
className={item.className}
href={href}
icon="🗃️"
title={item.label}
description={item.description ?? doc.description ?? categoryItemsPlural(item.items.length)}
description={item.description ?? doc?.description ?? categoryItemsPlural(item.items.length)}
/>
);
}
function CardLink({item}) {
function CardLink({ item }) {
const icon = isInternalUrl(item.href) ? '📄️' : '🔗';
const doc = useDocById(item.docId ?? undefined);
return (
@ -86,7 +92,7 @@ function CardLink({item}) {
/>
);
}
export default function DocCard({item}) {
export default function DocCard({ item }) {
switch (item.type) {
case 'link':
return <CardLink item={item} />;