import React from 'react'; import { GetStaticProps, GetStaticPaths } from 'next'; import Image from 'next/image'; import Link from 'next/link'; import { format } from 'date-fns'; import Layout from '@/components/Layout'; import Meta from '@/components/Meta'; import ShareButtons from '@/components/ShareButtons'; import CommentSection from '@/components/CommentSection'; import { getAllPostIds, getPostData, getSortedPostsData } from '@/lib/markdown'; import { PostData, PostMetadata } from '@/types'; interface PostProps { post: PostData; morePosts: PostMetadata[]; } const Post: React.FC = ({ post, morePosts }) => { 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
); }; export const getStaticPaths: GetStaticPaths = async () => { const paths = getAllPostIds(); return { paths, fallback: false, }; }; export const getStaticProps: GetStaticProps = async ({ params }) => { const post = await getPostData(params?.id as string); 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 { props: { post, morePosts, }, }; }; export default Post;