--- const allPosts = await Astro.glob("../../pages/blog/posts/*.md"); // Ensure posts have a date before sorting them const sortedPosts = allPosts .filter(post => post.frontmatter.pubDate) .sort((a, b) => new Date(b.frontmatter.pubDate).getTime() - new Date(a.frontmatter.pubDate).getTime()); const currentSlug = Astro.url.pathname.split("/").filter(Boolean).pop(); const currentIndex = sortedPosts.findIndex((post) => post.url && post.url.includes(currentSlug || "") ); const nextPost = currentIndex > 0 ? sortedPosts[currentIndex - 1] : null; const prevPost = currentIndex < sortedPosts.length - 1 ? sortedPosts[currentIndex + 1] : null; console.log({ prevPost, nextPost }); ---