import { navigation, NavigationLink, type NavigationSubItem } from "@/lib/navigation"; import { usePageContext } from "vike-react/usePageContext"; import { Link } from "@/components/common/Link"; import clsx from "clsx"; function ArrowIcon(props: React.ComponentPropsWithoutRef<"svg">) { return ( ); } function PageLink({ title, href, dir = "next", ...props }: Omit, "dir" | "title"> & { title: string; href: string; dir?: "previous" | "next"; }) { const pageCategory = navigation.find((section) => { return section.links.some((link) => link.href === href || link.subitems.some((subitem) => subitem.href === href)); }); return ( {dir === "next" ? "Suivant" : "Précédent"} {pageCategory && ( {pageCategory.title} )} {title} ); } export function PrevNextLinks() { const allLinks = navigation.flatMap((section) => section.links); const { urlPathname } = usePageContext(); let subItemElement: undefined | NavigationSubItem; const findLinkIndex = (pathname = urlPathname) => { for (let i = 0; i < allLinks.length; i++) { const link = allLinks[i]; if (link.href === urlPathname) { return i; } if (link.subitems) { const subitemIndex = link.subitems.findIndex((subitem) => subitem.href === urlPathname); if (subitemIndex !== -1) { subItemElement = link.subitems[subitemIndex]; return i; } } } }; const linkIndex = findLinkIndex(); if (linkIndex === undefined) return null; let previousPage: NavigationSubItem | NavigationLink | null = linkIndex > -1 ? allLinks[linkIndex - 1] : null; let nextPage: NavigationSubItem | NavigationLink | null = linkIndex > -1 ? allLinks[linkIndex + 1] : null; if (subItemElement !== undefined) { const subItemIndex = findLinkIndex(subItemElement.href)!; const currentPage = allLinks[subItemIndex]; const subItemIndexInLink = currentPage.subitems?.findIndex((subitem) => subitem.href === urlPathname); if (subItemIndexInLink !== undefined && subItemIndexInLink > -1) { previousPage = currentPage.subitems[subItemIndexInLink - 1]; nextPage = currentPage.subitems[subItemIndexInLink + 1]; } } if (!nextPage && !previousPage) { return null; } return ( {previousPage && } {nextPage && } ); }
{pageCategory && ( {pageCategory.title} )} {title}