import clsx from "clsx"; import { SIDEBAR, SIDEBAR_HEADER_MAP, type OuterHeaders } from "../../consts"; import { getIsRtlFromLangCode, getLanguageFromURL } from "../../languages"; type SlugType = "" | "deployment" | "usage"; export default function BreadCrumbs() { const lang = getLanguageFromURL(window.location.href); const isRtl = getIsRtlFromLangCode(lang ?? "en"); const slugToEntryPath = (slug: SlugType): OuterHeaders => { switch (slug) { case "": return "Create Expo Stack"; case "usage": return "Usage"; case "deployment": return "Deployment"; } }; const pathname = window.location.pathname.endsWith("/") ? window.location.pathname.slice(0, -1) : window.location.pathname; const slug = pathname.slice(1).split("/").length > 2 ? pathname.slice(1).split("/")[1] : "" || ""; const actualEntries = SIDEBAR[lang][ slugToEntryPath( slug === undefined || slug === "" ? "" : (slug as SlugType), ) ]; const getPathNameFromLink = (link: string) => { return [...(actualEntries ?? [])].find((entry) => entry.link === link) ?.text; }; const getHeaderName = (header: OuterHeaders) => { if (lang === "en") return header; return SIDEBAR_HEADER_MAP[lang][header]; }; const breadcrumbs = pathname .split("/") .slice(pathname.split("/").length > 3 ? -2 : -1) .map((crumb) => { const path = pathname .split("/") .slice(0, pathname.split("/").indexOf(crumb) + 1) .join("/"); return { href: `${window.location.protocol}//${window.location.host}${path}`, key: crumb, text: getPathNameFromLink(path.slice(path.indexOf(lang))) ?? getHeaderName( `${crumb[0]?.toUpperCase()}${crumb.slice(1)}` as OuterHeaders, ), }; }); return (
{breadcrumbs.map((crumb, index) => (
{crumb.text} {index < breadcrumbs.length - 1 && ( )}
))}
); } function BreadCrumbsArrow(props: { isRtl: boolean }) { return ( ); }