28 lines
837 B
TypeScript
28 lines
837 B
TypeScript
// utils/getBreadcrumbs.ts
|
|
import {breadcrumbMap} from '@/lib/breadcrumb-map';
|
|
|
|
export type Breadcrumb = {
|
|
label: string;
|
|
href: string;
|
|
isCurrentPage?: boolean;
|
|
};
|
|
|
|
export function getBreadcrumbs(path: string): Breadcrumb[] {
|
|
const pathSegments = path.split('/').filter(Boolean);
|
|
|
|
return pathSegments.map((segment, index) => {
|
|
const href = `/${pathSegments.slice(0, index + 1).join('/')}`;
|
|
// Use the mapping if it exists, otherwise format the segment
|
|
const label = breadcrumbMap[segment.toLowerCase()] ||
|
|
segment
|
|
.split('-')
|
|
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
|
.join(' ');
|
|
|
|
return {
|
|
label,
|
|
href,
|
|
isCurrentPage: index === pathSegments.length - 1
|
|
};
|
|
});
|
|
} |