--- // Import necessary components and utilities import MainLayout from "@/layouts/MainLayout.astro"; import AvatarBlogLarge from "@components/ui/avatars/AvatarBlogLarge.astro"; import CardRelated from "@components/ui/cards/CardRelated.astro"; import Bookmark from "@components/ui/buttons/Bookmark.astro"; import SocialShare from "@components/ui/buttons/SocialShare.astro"; import PostFeedback from "@components/ui/feedback/PostFeedback.astro"; import { Image } from "astro:assets"; import { capitalize, formatDate } from "@utils/utils"; import { getCollection } from "astro:content"; import type { CollectionEntry } from "astro:content"; import { SITE } from "@data/constants"; // getStaticPaths is used to pre-render all routes based on the blog posts export async function getStaticPaths() { const blogPosts = await getCollection("blog", ({ id }) => { return id.startsWith("fr/"); }); return blogPosts.map((post) => ({ params: { slug: post.slug }, props: { post }, })); } // Get the current post's data const { post } = Astro.props; // Get all blog posts const blogPosts: CollectionEntry<"blog">[] = await getCollection("blog", ({ id }) => { return id.startsWith("fr/"); } ); // Filter out the current post to get related posts // Note: This is a very basic way of choosing related posts, just for the purpose of the example. // In a production site, you might want to implement a more robust algorithm, choosing related posts based on tags, categories, dates, authors, or keywords. // See example: https://blog.codybrunner.com/2024/adding-related-articles-with-astro-content-collections/ const relatedPosts: CollectionEntry<"blog">[] = blogPosts.filter( (blogEntry) => blogEntry.slug !== post.slug ); const pageTitle: string = `${post.data.title} | ${SITE.title}`; ---
{post.data.author}
  • {formatDate(post.data.pubDate)}
  • {post.data.readTime} min read

{post.data.title}

{ post.data.contents.map((content: string, index: any) => index === 1 ? ( <>

{content}

{post.data.cardImageAlt} ) : (

{content}

) ) }
{ post.data.tags?.map((tag: string, index) => ( {capitalize(tag)} )) }

Related articles

{relatedPosts.map((entry) => )}