This commit is contained in:
50
resources/views/partials/breadcrumbs.blade.php
Normal file
50
resources/views/partials/breadcrumbs.blade.php
Normal file
@@ -0,0 +1,50 @@
|
||||
@if (!empty($items))
|
||||
@php
|
||||
$breadcrumbSchemaItems = collect($items)
|
||||
->values()
|
||||
->map(function ($item, $index) {
|
||||
if (!is_array($item)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$label = trim((string) ($item['label'] ?? ''));
|
||||
if ($label === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$url = !empty($item['url']) ? (string) $item['url'] : url()->current();
|
||||
|
||||
return [
|
||||
'@type' => 'ListItem',
|
||||
'position' => $index + 1,
|
||||
'name' => $label,
|
||||
'item' => $url,
|
||||
];
|
||||
})
|
||||
->filter()
|
||||
->values()
|
||||
->all();
|
||||
$breadcrumbSchema = [
|
||||
'@context' => 'https://schema.org',
|
||||
'@type' => 'BreadcrumbList',
|
||||
'itemListElement' => $breadcrumbSchemaItems,
|
||||
];
|
||||
@endphp
|
||||
|
||||
<nav class="pc-breadcrumbs" aria-label="Хлебные крошки">
|
||||
@foreach ($items as $item)
|
||||
@if (!$loop->last && !empty($item['url']))
|
||||
<a href="{{ $item['url'] }}">{{ $item['label'] }}</a>
|
||||
<span class="pc-breadcrumbs-sep">/</span>
|
||||
@else
|
||||
<span class="pc-breadcrumbs-current">{{ $item['label'] }}</span>
|
||||
@endif
|
||||
@endforeach
|
||||
</nav>
|
||||
|
||||
@if (!empty($breadcrumbSchemaItems))
|
||||
<script type="application/ld+json">
|
||||
@json($breadcrumbSchema, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)
|
||||
</script>
|
||||
@endif
|
||||
@endif
|
||||
Reference in New Issue
Block a user