58 lines
2.1 KiB
PHP
58 lines
2.1 KiB
PHP
@props(['items' => []])
|
|
|
|
{{--
|
|
$items: array of ['label' => string, 'href' => string|null]
|
|
Home is always prepended here, so pages pass only their own trail.
|
|
Last item is the current page — no link, no href needed.
|
|
|
|
Example:
|
|
<x-breadcrumb :items="[
|
|
['label' => 'Jackets', 'href' => route('category.show', ['id' => 12])],
|
|
['label' => 'Leather Jacket'],
|
|
]" />
|
|
|
|
Also pushes matching BreadcrumbList JSON-LD to the layout's `seo` stack.
|
|
--}}
|
|
|
|
@php
|
|
// Untranslated collection names can arrive empty; skip them rather than
|
|
// render an empty crumb.
|
|
$items = array_values(array_filter([
|
|
['label' => __('storefront.nav.home'), 'href' => route('home')],
|
|
...$items,
|
|
], fn ($item) => filled($item['label'] ?? null)));
|
|
@endphp
|
|
|
|
@push('seo')
|
|
<script type="application/ld+json">
|
|
{!! json_encode([
|
|
'@@context' => 'https://schema.org', {{-- @@ escapes Blade's @context directive --}}
|
|
'@type' => 'BreadcrumbList',
|
|
'itemListElement' => collect($items)->map(fn ($item, $index) => array_filter([
|
|
'@type' => 'ListItem',
|
|
'position' => $index + 1,
|
|
'name' => $item['label'],
|
|
'item' => $item['href'] ?? null,
|
|
], fn ($value) => $value !== null))->values()->all(),
|
|
], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_TAG) !!}
|
|
</script>
|
|
@endpush
|
|
|
|
<nav aria-label="Breadcrumb">
|
|
<ol {{ $attributes->merge(['class' => 'flex items-center flex-wrap gap-1 text-base text-black']) }}>
|
|
@foreach ($items as $index => $item)
|
|
<li class="flex items-center gap-1">
|
|
@if (!$loop->first)
|
|
<span aria-hidden="true">/</span>
|
|
@endif
|
|
|
|
@if (!empty($item['href']))
|
|
<a href="{{ $item['href'] }}" class="underline-slide [--slide-h:1px]">{{ $item['label'] }}</a>
|
|
@else
|
|
<span class="pb-1" aria-current="page">{{ $item['label'] }}</span>
|
|
@endif
|
|
</li>
|
|
@endforeach
|
|
</ol>
|
|
</nav>
|