Debian Codegraph @

www/src/components/Breadcrumbs.astro

raw
1 ---
2 import type {Breadcrumb} from '../lib/content';
3
4 interface Props {
5 breadcrumbs: Breadcrumb[];
6 }
7
8 const {breadcrumbs} = Astro.props;
9 const allCrumbs: Breadcrumb[] = [{label: 'Home', href: '/'}, ...breadcrumbs];
10 const isLast = (i: number) => i === allCrumbs.length - 1;
11 const parent = allCrumbs.slice(0, -1).reverse().find(c => c.href) || null;
12 ---
13
14 {allCrumbs.length > 1 && (
15 <nav aria-label="Breadcrumb">
16 {/* Mobile: show parent link only */}
17 {parent && (
18 <a href={parent.href} class="back-link">
19 <i class="icon-[mdi--chevron-left]" aria-hidden="true"></i>
20 <span set:html={parent.label}/>
21 </a>
22 )}
23
24 {/* Desktop: full breadcrumb trail */}
25 <ol role="list">
26 {allCrumbs.map((crumb, i) => (
27 <li>
28 {i > 0 && (
29 <span aria-hidden="true">/</span>
30 )}
31 {isLast(i) ? (
32 <span aria-current="page" set:html={crumb.label}/>
33 ) : crumb.href ? (
34 <a href={crumb.href} set:html={crumb.label}/>
35 ) : (
36 <span set:html={crumb.label}/>
37 )}
38 </li>
39 ))}
40 </ol>
41 </nav>
42 )}
43
44 <style>
45 .back-link {
46 display: inline-flex;
47 align-items: center;
48 gap: 0.125rem;
49 margin-left: -0.125rem;
50 padding: 0.25rem 0.5rem 0.25rem 0;
51 font-size: 0.75rem;
52 color: light-dark(var(--color-neutral-600), var(--color-neutral-400));
53 border-radius: 0.125rem;
54 text-decoration: none;
55
56 @media (min-width: 1024px) {
57 display: none;
58 }
59
60 @media (hover: hover) {
61 &:hover {
62 color: light-dark(var(--color-blue-700), var(--color-blue-300));
63 }
64 }
65
66 &:is(:focus-visible, :active) {
67 color: light-dark(var(--color-blue-700), var(--color-blue-300));
68 }
69
70 i {
71 font-size: 1rem;
72 flex-shrink: 0;
73 }
74
75 span {
76 overflow: hidden;
77 text-overflow: ellipsis;
78 white-space: nowrap;
79 max-width: 30ch;
80 }
81 }
82
83 [role="list"] {
84 display: none;
85 flex-wrap: wrap;
86 align-items: center;
87 column-gap: 0.75rem;
88 row-gap: 0.25rem;
89 font-size: 0.875rem;
90 color: light-dark(var(--color-neutral-600), var(--color-neutral-400));
91 list-style: none;
92 padding: 0;
93 margin: 0;
94
95 @media (min-width: 1024px) {
96 display: flex;
97 }
98
99 li {
100 display: flex;
101 align-items: center;
102 gap: 0.75rem;
103 }
104
105 [aria-hidden] {
106 color: light-dark(var(--color-neutral-300), var(--color-neutral-700));
107 user-select: none;
108 }
109
110 [aria-current="page"] {
111 font-weight: 600;
112 color: light-dark(var(--color-neutral-700), var(--color-neutral-300));
113 overflow: hidden;
114 text-overflow: ellipsis;
115 white-space: nowrap;
116 max-width: 40ch;
117 }
118
119 a {
120 text-decoration: none;
121
122 @media (hover: hover) {
123 &:hover {
124 text-decoration: underline;
125 color: light-dark(var(--color-blue-700), var(--color-blue-300));
126 }
127 }
128
129 &:is(:focus-visible, :active) {
130 text-decoration: underline;
131 color: light-dark(var(--color-blue-700), var(--color-blue-300));
132 }
133 }
134 }
135 </style>