-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
686 additions
and
636 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { Fragment } from "react"; | ||
import Link from "next/link"; | ||
import { | ||
Breadcrumb, | ||
BreadcrumbItem, | ||
BreadcrumbLink, | ||
BreadcrumbList, | ||
BreadcrumbPage, | ||
BreadcrumbSeparator, | ||
} from "@/components/ui/breadcrumb"; | ||
|
||
interface Props { | ||
params: { | ||
slug: string[]; | ||
}; | ||
} | ||
|
||
interface BreadcrumbItem { | ||
href: string; | ||
label: string; | ||
isLastItem: boolean; | ||
} | ||
|
||
const BREADCRUMB_MAP: Record<string, string> = { | ||
coe: "COE", | ||
}; | ||
|
||
const capitaliseWords = (text: string): string => | ||
text | ||
.split("-") | ||
.map((word) => word.charAt(0).toUpperCase() + word.slice(1)) | ||
.join(" "); | ||
|
||
const generateBreadcrumbs = (slug: string[]): BreadcrumbItem[] => | ||
slug.map((segment, index) => ({ | ||
href: `/${slug.slice(0, index + 1).join("/")}`, | ||
label: BREADCRUMB_MAP[segment] ?? capitaliseWords(segment), | ||
isLastItem: index === slug.length - 1, | ||
})); | ||
|
||
const Breadcrumbs = ({ params }: Props) => { | ||
const breadcrumbs = generateBreadcrumbs(params.slug); | ||
|
||
return ( | ||
<Breadcrumb> | ||
<BreadcrumbList> | ||
<BreadcrumbItem> | ||
<BreadcrumbLink asChild> | ||
<Link href="/">Home</Link> | ||
</BreadcrumbLink> | ||
</BreadcrumbItem> | ||
{breadcrumbs.map(({ isLastItem, href, label }) => ( | ||
<Fragment key={href}> | ||
<BreadcrumbSeparator /> | ||
<BreadcrumbItem> | ||
{isLastItem ? ( | ||
<BreadcrumbPage>{label}</BreadcrumbPage> | ||
) : ( | ||
<BreadcrumbLink asChild> | ||
<Link href={href}>{label}</Link> | ||
</BreadcrumbLink> | ||
)} | ||
</BreadcrumbItem> | ||
</Fragment> | ||
))} | ||
</BreadcrumbList> | ||
</Breadcrumb> | ||
); | ||
}; | ||
|
||
export default Breadcrumbs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { | ||
Breadcrumb, | ||
BreadcrumbItem, | ||
BreadcrumbList, | ||
BreadcrumbPage, | ||
} from "@/components/ui/breadcrumb"; | ||
|
||
const DefaultBreadcrumb = () => { | ||
return ( | ||
<Breadcrumb> | ||
<BreadcrumbList> | ||
<BreadcrumbItem> | ||
<BreadcrumbPage>Home</BreadcrumbPage> | ||
</BreadcrumbItem> | ||
</BreadcrumbList> | ||
</Breadcrumb> | ||
); | ||
}; | ||
|
||
export default DefaultBreadcrumb; |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.