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