import { usePageContext } from "vike-react/usePageContext"; import { Link } from "@/components/common/Link"; import { navigation } from "@/lib/navigation"; import React from "react"; 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 { urlPathname } = usePageContext(); const allLinks = navigation .flatMap((section) => section.links) .flatMap((link) => { return link.subitems ? [link, ...link.subitems] : link; }); const getNeighboringLinks = () => { const linkIndex = allLinks.findIndex((link) => link.href === urlPathname); if (linkIndex === -1) return [null, null]; const previousPage = allLinks[linkIndex - 1] || null; let nextPage = allLinks[linkIndex + 1] || null; // In case the next page is the same as the current page (in subitems), // we need to skip it to get the correct next page. if (nextPage?.href === urlPathname) { nextPage = allLinks[linkIndex + 2] || null; } return [previousPage, nextPage]; }; const [previousPage, nextPage] = getNeighboringLinks(); if (!nextPage && !previousPage) return null; return (
{previousPage && } {nextPage && }
); }