--- import { SIDEBAR } from "../consts"; type Props = { currentPage: string; }; const { currentPage } = Astro.props; // Remove trailing slash if present, and remove leading slash const cleanPath = currentPage.replace(/\/$/, "").replace(/^\//, ""); const sidebar = SIDEBAR; const allLinks = Object.values(sidebar).flat(); const index = allLinks.findIndex((x) => x.link === cleanPath); // Guard against page not found in sidebar (index === -1) const prev = index > 0 ? allLinks[index - 1] : undefined; const next = index >= 0 && index < allLinks.length - 1 ? allLinks[index + 1] : undefined; ---