mirror of
https://github.com/facebook/docusaurus.git
synced 2025-04-29 02:08:36 +02:00
fix(theme-classic): remove breadcrumb items without href from microdata (#7304)
This commit is contained in:
parent
3a7e6665ad
commit
b3feb01009
2 changed files with 19 additions and 7 deletions
|
@ -40,9 +40,12 @@ function BreadcrumbsItemLink({
|
|||
<span itemProp="name">{children}</span>
|
||||
</Link>
|
||||
) : (
|
||||
<span className={className} itemProp="item name">
|
||||
{children}
|
||||
</span>
|
||||
// TODO Google search console doesn't like breadcrumb items without href.
|
||||
// The schema doesn't seem to require `id` for each `item`, although Google
|
||||
// insist to infer one, even if it's invalid. Removing `itemProp="item
|
||||
// name"` for now, since I don't know how to properly fix it.
|
||||
// See https://github.com/facebook/docusaurus/issues/7241
|
||||
<span className={className}>{children}</span>
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -51,16 +54,20 @@ function BreadcrumbsItem({
|
|||
children,
|
||||
active,
|
||||
index,
|
||||
addMicrodata,
|
||||
}: {
|
||||
children: ReactNode;
|
||||
active?: boolean;
|
||||
index: number;
|
||||
addMicrodata: boolean;
|
||||
}): JSX.Element {
|
||||
return (
|
||||
<li
|
||||
itemScope
|
||||
itemProp="itemListElement"
|
||||
itemType="https://schema.org/ListItem"
|
||||
{...(addMicrodata && {
|
||||
itemScope: true,
|
||||
itemProp: 'itemListElement',
|
||||
itemType: 'https://schema.org/ListItem',
|
||||
})}
|
||||
className={clsx('breadcrumbs__item', {
|
||||
'breadcrumbs__item--active': active,
|
||||
})}>
|
||||
|
@ -106,7 +113,11 @@ export default function DocBreadcrumbs(): JSX.Element | null {
|
|||
{breadcrumbs.map((item, idx) => {
|
||||
const isLast = idx === breadcrumbs.length - 1;
|
||||
return (
|
||||
<BreadcrumbsItem key={idx} active={isLast} index={idx}>
|
||||
<BreadcrumbsItem
|
||||
key={idx}
|
||||
active={isLast}
|
||||
index={idx}
|
||||
addMicrodata={!!item.href}>
|
||||
<BreadcrumbsItemLink href={item.href} isLast={isLast}>
|
||||
{item.label}
|
||||
</BreadcrumbsItemLink>
|
||||
|
|
|
@ -158,6 +158,7 @@ mdxast
|
|||
mdxhast
|
||||
metadatum
|
||||
metastring
|
||||
microdata
|
||||
middlewares
|
||||
minifier
|
||||
mkcert
|
||||
|
|
Loading…
Add table
Reference in a new issue