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

@ -2,97 +2,103 @@ import React from 'react';
import clsx from 'clsx';
import Link from '@docusaurus/Link';
import {
useDocById,
findFirstSidebarItemLink,
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();
return (count) =>
selectMessage(
count,
translate(
{
message: '1 item|{count} items',
id: 'theme.docs.DocCard.categoryDescription.plurals',
description:
'The default description for a category card in the generated index about how many items this category includes',
},
{count},
),
const { selectMessage } = usePluralForm();
return (count) =>
selectMessage(
count,
translate(
{
message: '1 item|{count} items',
id: 'theme.docs.DocCard.categoryDescription.plurals',
description:
'The default description for a category card in the generated index about how many items this category includes',
},
{ count },
),
);
}
function CardContainer({ className, href, children }) {
return (
<Link
href={href}
className={clsx('card padding--lg', styles.cardContainer, className)}>
{children}
</Link>
);
}
function CardContainer({className, href, children}) {
return (
<Link
href={href}
className={clsx('card padding--lg', styles.cardContainer, className)}>
{children}
</Link>
);
function CardLayout({ className, href, icon, title, description }) {
return (
<CardContainer href={href} className={className}>
<Heading
as="h2"
className={clsx('text--truncate', styles.cardTitle)}
title={title}>
{icon} {title}
</Heading>
{description && (
<p
className={clsx('text--truncate', styles.cardDescription)}
title={description}>
{description}
</p>
)}
</CardContainer>
);
}
function CardLayout({className, href, icon, title, description}) {
return (
<CardContainer href={href} className={className}>
<Heading
as="h2"
className={clsx('text--truncate', styles.cardTitle)}
title={title}>
{icon} {title}
</Heading>
{description && (
<p
className={clsx('text--truncate', styles.cardDescription)}
title={description}>
{description}
</p>
)}
</CardContainer>
);
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 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)}
/>
);
}
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);
return (
<CardLayout
className={item.className}
href={href}
icon="🗃️"
title={item.label}
description={item.description ?? doc.description ?? categoryItemsPlural(item.items.length)}
/>
);
function CardLink({ item }) {
const icon = isInternalUrl(item.href) ? '📄️' : '🔗';
const doc = useDocById(item.docId ?? undefined);
return (
<CardLayout
className={item.className}
href={item.href}
icon={icon}
title={item.label}
description={item.description ?? doc?.description}
/>
);
}
function CardLink({item}) {
const icon = isInternalUrl(item.href) ? '📄️' : '🔗';
const doc = useDocById(item.docId ?? undefined);
return (
<CardLayout
className={item.className}
href={item.href}
icon={icon}
title={item.label}
description={item.description ?? doc?.description}
/>
);
}
export default function DocCard({item}) {
switch (item.type) {
case 'link':
return <CardLink item={item} />;
case 'category':
return <CardCategory item={item} />;
default:
throw new Error(`unknown item type ${JSON.stringify(item)}`);
}
export default function DocCard({ item }) {
switch (item.type) {
case 'link':
return <CardLink item={item} />;
case 'category':
return <CardCategory item={item} />;
default:
throw new Error(`unknown item type ${JSON.stringify(item)}`);
}
}