Skip to content

Commit

Permalink
add hideCurrent option for breadcrumbs
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitchell Christ committed Sep 23, 2024
1 parent 12104af commit 433c8d4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sanitypress",
"version": "4.7.2",
"version": "4.7.3",
"description": "A Next.js + Sanity.io Starter Template",
"author": "nuotsu <mitchell@nuotsu.dev> (https://nuotsu.dev)",
"license": "ISC",
Expand Down
6 changes: 6 additions & 0 deletions sanity/schemas/modules/breadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ export default defineType({
of: [{ type: 'link', initialValue: { type: 'internal' } }],
description: 'Current page is automatically included',
}),
defineField({
name: 'hideCurrent',
title: 'Hide current page',
type: 'boolean',
initialValue: false,
}),
],
preview: {
select: {
Expand Down
16 changes: 11 additions & 5 deletions src/ui/modules/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { stegaClean } from '@sanity/client/stega'

export default async function Breadcrumbs({
crumbs,
hideCurrent,
currentPage,
}: Partial<{
crumbs: Sanity.Link[]
hideCurrent?: boolean
currentPage: Sanity.Page | Sanity.BlogPost
}>) {
return (
Expand All @@ -20,13 +22,15 @@ export default async function Breadcrumbs({
<Fragment key={key}>
<Crumb link={crumb} position={key + 1} />

<li className="opacity-20" role="presentation">
/
</li>
{(key < crumbs.length - 1 || !hideCurrent) && (
<li className="opacity-20" role="presentation">
/
</li>
)}
</Fragment>
))}

<Crumb position={(crumbs?.length || 0) + 2}>
<Crumb position={(crumbs?.length || 0) + 2} hidden={hideCurrent}>
{currentPage?.title || currentPage?.metadata.title}
</Crumb>
</ol>
Expand All @@ -38,13 +42,15 @@ function Crumb({
link,
position,
children,
hidden,
}: {
link?: Omit<Sanity.Link, '_type'>
position: number
hide?: boolean
} & React.ComponentProps<'li'>) {
const content = (
<>
<span itemProp="name">
<span itemProp="name" hidden={hidden}>
{stegaClean(
children || link?.label || link?.internal?.title || link?.external,
)}
Expand Down

0 comments on commit 433c8d4

Please sign in to comment.