import ShareButtons from '@/components/ShareButtons'; import { getPostData, getSortedPostsData } from '@/lib/markdown'; import { PostData, PostMetadata } from '@/types'; import { format } from 'date-fns'; import Image from 'next/image'; import Link from 'next/link'; import React from 'react'; import CommentSection from "@/components/CommentSection"; import { generateMetadata as createMetadata } from '@/components/Metadata'; import type { Metadata } from 'next'; interface PageProps { params: Promise<{ id: string }>; } export async function generateMetadata({ params }: PageProps): Promise { const { id } = await params; const post = await getPostData(id); const postUrl = `https://confessionsofgrace.com/posts/${post.id}`; return createMetadata({ title: post.title, description: post.excerpt, keywords: post.tags.join(', '), image: post.coverImage, url: postUrl, type: 'article' }); } async function getPostAndMorePosts(id: string): Promise<{ post: PostData; morePosts: PostMetadata[] }> { const post = await getPostData(id); const allPosts = getSortedPostsData(); // Filter out the current post and get a few related posts (by tags) const otherPosts = allPosts.filter(p => p.id !== post.id); // Find posts with matching tags const relatedPosts = otherPosts .filter(p => p.tags.some(tag => post.tags.includes(tag))) .slice(0, 2); // If we don't have enough related posts, add recent posts const morePosts = relatedPosts.length < 2 ? [...relatedPosts, ...otherPosts.filter(p => !relatedPosts.includes(p))].slice(0, 2) : relatedPosts; return { post, morePosts }; } export default async function PostPage({ params }: PageProps) { const { id } = await params; const { post, morePosts } = await getPostAndMorePosts(id); const postUrl = `https://confessionsofgrace.com/posts/${post.id}`; return (

{post.title}

{post.author}
{post.coverImage && (
{post.title}
)}
{post.tags.map(tag => ( {tag} ))}

More Posts

{morePosts.slice(0, 2).map(post => (

{post.title}

{format(new Date(post.date), 'MMMM d, yyyy')}

{post.excerpt}

))}
Back to all posts
); }