breadcrumbs && jsonGenerator updated

This commit is contained in:
Al Murad Uzzaman
2024-05-14 16:23:32 +06:00
parent ac6fa96c9c
commit b92a4a4c6a
3 changed files with 78 additions and 37 deletions
+14 -4
View File
@@ -1,19 +1,28 @@
---
import { humanize } from "@/lib/utils/textConverter";
import config from "@/config/config.json";
const { supported } = config.language;
const { className }: { className?: string } = Astro.props;
const paths = Astro.url.pathname.split("/").filter((x) => x);
let lang = "";
if (supported.includes(paths[0])) {
lang = paths.shift()!;
}
let parts = [
{
label: "Home",
href: "/",
"aria-label": Astro.url.pathname === "/" ? "page" : undefined,
href: `/${lang}`,
"aria-label": Astro.url.pathname === `/${lang}` || Astro.url.pathname === `/${lang}/` ? "page" : undefined,
},
];
paths.forEach((label: string, i: number) => {
const href = `/${paths.slice(0, i + 1).join("/")}`;
const href = `/${lang}/${paths.slice(0, i + 1).join("/")}`;
label !== "page" &&
parts.push({
label: humanize(label.replace(".html", "").replace(/[-_]/g, " ")) || "",
@@ -21,6 +30,7 @@ paths.forEach((label: string, i: number) => {
"aria-label": Astro.url.pathname === href ? "page" : undefined,
});
});
---
<nav aria-label="Breadcrumb" class={className}>
@@ -28,7 +38,7 @@ paths.forEach((label: string, i: number) => {
{
parts.map(({ label, ...attrs }, index) => (
<li class="mx-1 capitalize" role="listitem">
{index > 0 && <span class="inlin-block mr-1">/</span>}
{index > 0 && <span class="inline-block mr-1">/</span>}
{index !== parts.length - 1 ? (
<a class="text-primary dark:text-darkmode-primary" {...attrs}>
{label}