💂♂️ fixed lint and prittier
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
'use client';
|
||||
'use client'
|
||||
|
||||
import Link from 'next/link';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { Fragment } from 'react';
|
||||
import { BreadcrumbsSchema } from './breadcrumbs-schema';
|
||||
import Link from 'next/link'
|
||||
import { usePathname } from 'next/navigation'
|
||||
import { Fragment } from 'react'
|
||||
import { BreadcrumbsSchema } from './breadcrumbs-schema'
|
||||
|
||||
interface BreadcrumbItem {
|
||||
label: string;
|
||||
href: string;
|
||||
current?: boolean;
|
||||
label: string
|
||||
href: string
|
||||
current?: boolean
|
||||
}
|
||||
|
||||
function HomeIcon({ className }: { className?: string }) {
|
||||
@@ -27,25 +27,15 @@ function HomeIcon({ className }: { className?: string }) {
|
||||
d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
function ChevronIcon({ className }: { className?: string }) {
|
||||
return (
|
||||
<svg
|
||||
className={className}
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M9 5l7 7-7 7"
|
||||
/>
|
||||
<svg className={className} fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 5l7 7-7 7" />
|
||||
</svg>
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
function formatSegmentLabel(segment: string): string {
|
||||
@@ -53,36 +43,36 @@ function formatSegmentLabel(segment: string): string {
|
||||
blog: 'Blog',
|
||||
tags: 'Tag-uri',
|
||||
about: 'Despre',
|
||||
};
|
||||
}
|
||||
|
||||
if (specialCases[segment]) {
|
||||
return specialCases[segment];
|
||||
return specialCases[segment]
|
||||
}
|
||||
|
||||
return segment
|
||||
.split('-')
|
||||
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
||||
.join(' ');
|
||||
.join(' ')
|
||||
}
|
||||
|
||||
export function Breadcrumbs({ items }: { items?: BreadcrumbItem[] }) {
|
||||
const pathname = usePathname();
|
||||
const pathname = usePathname()
|
||||
|
||||
let breadcrumbs: BreadcrumbItem[] = items || [];
|
||||
let breadcrumbs: BreadcrumbItem[] = items || []
|
||||
|
||||
if (!items) {
|
||||
const segments = pathname.split('/').filter(Boolean);
|
||||
const segments = pathname.split('/').filter(Boolean)
|
||||
breadcrumbs = segments.map((segment, index) => {
|
||||
const href = '/' + segments.slice(0, index + 1).join('/');
|
||||
const label = formatSegmentLabel(segment);
|
||||
const current = index === segments.length - 1;
|
||||
const href = '/' + segments.slice(0, index + 1).join('/')
|
||||
const label = formatSegmentLabel(segment)
|
||||
const current = index === segments.length - 1
|
||||
|
||||
return { label, href, current };
|
||||
});
|
||||
return { label, href, current }
|
||||
})
|
||||
}
|
||||
|
||||
if (pathname === '/') {
|
||||
return null;
|
||||
return null
|
||||
}
|
||||
|
||||
const schemaItems = [
|
||||
@@ -92,7 +82,7 @@ export function Breadcrumbs({ items }: { items?: BreadcrumbItem[] }) {
|
||||
name: item.label,
|
||||
item: item.href,
|
||||
})),
|
||||
];
|
||||
]
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -112,7 +102,7 @@ export function Breadcrumbs({ items }: { items?: BreadcrumbItem[] }) {
|
||||
</Link>
|
||||
</li>
|
||||
|
||||
{breadcrumbs.map((item) => (
|
||||
{breadcrumbs.map(item => (
|
||||
<Fragment key={item.href}>
|
||||
<li className="text-gray-400 flex-shrink-0">
|
||||
<ChevronIcon className="w-4 h-4" />
|
||||
@@ -141,5 +131,5 @@ export function Breadcrumbs({ items }: { items?: BreadcrumbItem[] }) {
|
||||
</nav>
|
||||
<BreadcrumbsSchema items={schemaItems} />
|
||||
</>
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
interface BreadcrumbSchemaItem {
|
||||
position: number;
|
||||
name: string;
|
||||
item: string;
|
||||
position: number
|
||||
name: string
|
||||
item: string
|
||||
}
|
||||
|
||||
export function BreadcrumbsSchema({ items }: { items: BreadcrumbSchemaItem[] }) {
|
||||
const structuredData = {
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'BreadcrumbList',
|
||||
itemListElement: items.map((item) => ({
|
||||
itemListElement: items.map(item => ({
|
||||
'@type': 'ListItem',
|
||||
position: item.position,
|
||||
name: item.name,
|
||||
item: `http://localhost:3000${item.item}`,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
return (
|
||||
<script
|
||||
type="application/ld+json"
|
||||
dangerouslySetInnerHTML={{ __html: JSON.stringify(structuredData) }}
|
||||
/>
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user