✨ Breadcrumbs with navigation
All checks were successful
Build and deploy website / build (push) Successful in 38s
All checks were successful
Build and deploy website / build (push) Successful in 38s
This commit is contained in:
38
src/components/Breadcrumb.astro
Normal file
38
src/components/Breadcrumb.astro
Normal file
@ -0,0 +1,38 @@
|
||||
---
|
||||
import { type NavLink, resolvePathname } from "@/utils/linking"
|
||||
import LocaleLink from "@/components/links/LocaleLink.astro"
|
||||
|
||||
const pathname = resolvePathname(Astro.originPathname)
|
||||
|
||||
let paths: string[]
|
||||
if (pathname === "/") {
|
||||
paths = ["~"]
|
||||
} else {
|
||||
paths = ["~", ...pathname.split("/").slice(1)]
|
||||
}
|
||||
|
||||
function getLink(path: string): NavLink {
|
||||
switch (path) {
|
||||
case "~":
|
||||
return "/"
|
||||
default:
|
||||
return `/${path}` as NavLink
|
||||
}
|
||||
}
|
||||
---
|
||||
|
||||
<div>
|
||||
{
|
||||
paths.map((path, index) => (
|
||||
<span>
|
||||
{index != paths.length - 1 ? (
|
||||
<span>
|
||||
<LocaleLink to={getLink(path)}>{path}</LocaleLink>/
|
||||
</span>
|
||||
) : (
|
||||
path
|
||||
)}
|
||||
</span>
|
||||
))
|
||||
}
|
||||
</div>
|
Reference in New Issue
Block a user