Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add SEO microdata for doc breadcrumbs #6697

Merged
merged 4 commits into from
Mar 14, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ function BreadcrumbsItemLink({
}): JSX.Element {
const className = clsx('breadcrumbs__link', styles.breadcrumbsItemLink);
return href ? (
<Link className={className} href={href}>
{children}
<Link className={className} href={href} itemProp="item">
<span itemProp="name">{children}</span>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need the extra span here and why?

Can't we apply "name" to the link directly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I've experimented. Without the span, the name is not correctly recognized.

</Link>
) : (
<span className={className}>{children}</span>
<span className={className} itemProp="item name">
{children}
</span>
);
}

Expand All @@ -40,6 +42,9 @@ function BreadcrumbsItem({
}): JSX.Element {
return (
<li
itemScope
itemProp="itemListElement"
itemType="https://schema.org/ListItem"
className={clsx('breadcrumbs__item', {
'breadcrumbs__item--active': active,
})}>
Expand All @@ -49,11 +54,14 @@ function BreadcrumbsItem({
}

function HomeBreadcrumbItem() {
const homeHref = useBaseUrl('/');
return (
<BreadcrumbsItem>
<BreadcrumbsItemLink href={homeHref}>🏠</BreadcrumbsItemLink>
</BreadcrumbsItem>
<li className="breadcrumbs__item">
Josh-Cena marked this conversation as resolved.
Show resolved Hide resolved
<Link
className={clsx('breadcrumbs__link', styles.breadcrumbsItemLink)}
href={useBaseUrl('/')}>
Josh-Cena marked this conversation as resolved.
Show resolved Hide resolved
🏠
</Link>
</li>
);
}

Expand All @@ -71,13 +79,17 @@ export default function DocBreadcrumbs(): JSX.Element | null {
styles.breadcrumbsContainer,
)}
aria-label="breadcrumbs">
<ul className="breadcrumbs">
<ul
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similarly, I didn't do it yet but this must be encapsulated under a <Breadcrumbs> component

className="breadcrumbs"
itemScope
itemType="https://schema.org/BreadcrumbList">
<HomeBreadcrumbItem />
{breadcrumbs.map((item, idx) => (
<BreadcrumbsItem key={idx} active={idx === breadcrumbs.length - 1}>
<BreadcrumbsItemLink href={item.href}>
{item.label}
</BreadcrumbsItemLink>
<meta itemProp="position" content={String(idx + 1)} />
Josh-Cena marked this conversation as resolved.
Show resolved Hide resolved
</BreadcrumbsItem>
))}
</ul>
Expand Down