--- import type { CollectionEntry } from "astro:content"; interface Props { post: CollectionEntry<"blog">; } const { post } = Astro.props; // Function to extract plain text preview from markdown function extractPreview(content: string, maxLength: number = 300): string { // Remove frontmatter const withoutFrontmatter = content.replace(/^---[\s\S]*?---\s*/, ""); // Basic markdown to plain text conversion let plainText = withoutFrontmatter .replace(/!\[.*?\]\(.*?\)/g, "[image]") // Replace images with placeholder .replace(/\[([^\]]+)\]\(.*?\)/g, "$1") // Remove link URLs, keep text .replace(/#{1,6}\s+/g, "") // Remove headers .replace(/```[\s\S]*?```/g, "[code block]") // Replace code blocks .replace(/`([^`]+)`/g, "$1") // Remove inline code formatting .replace(/\*\*([^*]+)\*\*/g, "$1") // Remove bold .replace(/\*([^*]+)\*/g, "$1") // Remove italic .replace(/_([^_]+)_/g, "$1") // Remove italic underscore .replace(/^\s*[-*+]\s+/gm, "") // Remove list markers .replace(/^\s*\d+\.\s+/gm, "") // Remove ordered list numbers .replace(/\n{3,}/g, "\n\n") // Collapse multiple newlines .trim(); // Truncate to maxLength if (plainText.length > maxLength) { plainText = plainText.substring(0, maxLength).trim() + "..."; } return plainText; } const preview = extractPreview(post.body); ---

{post.data.title}

{post.data.description}

{preview}

{ post.data.date.toLocaleDateString("en-US", { year: "numeric", month: "short", day: "numeric", }) }