Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed Mar 7, 2022
1 parent 7365954 commit 3ec32b4
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ function BreadcrumbsItemLink({
function BreadcrumbsItem({
children,
active,
index,
}: {
children: ReactNode;
active?: boolean;
index: number;
}): JSX.Element {
return (
<li
Expand All @@ -53,16 +55,18 @@ function BreadcrumbsItem({
'breadcrumbs__item--active': active,
})}>
{children}
<meta itemProp="position" content={String(index + 1)} />
</li>
);
}

function HomeBreadcrumbItem() {
const homeHref = useBaseUrl('/');
return (
<li className="breadcrumbs__item">
<Link
className={clsx('breadcrumbs__link', styles.breadcrumbsItemLink)}
href={useBaseUrl('/')}>
href={homeHref}>
🏠
</Link>
</li>
Expand Down Expand Up @@ -90,11 +94,13 @@ export default function DocBreadcrumbs(): JSX.Element | null {
itemType="https://schema.org/BreadcrumbList">
{homePageRoute && <HomeBreadcrumbItem />}
{breadcrumbs.map((item, idx) => (
<BreadcrumbsItem key={idx} active={idx === breadcrumbs.length - 1}>
<BreadcrumbsItem
key={idx}
active={idx === breadcrumbs.length - 1}
index={idx}>
<BreadcrumbsItemLink href={item.href}>
{item.label}
</BreadcrumbsItemLink>
<meta itemProp="position" content={String(idx + 1)} />
</BreadcrumbsItem>
))}
</ul>
Expand Down

0 comments on commit 3ec32b4

Please sign in to comment.