export const dynamic = 'force-dynamic'; import React from 'react'; import Link from 'next/link'; import { format } from 'date-fns'; import { getSortedPostsData } from '@/lib/posts'; import { PostMetadata } from '@/types'; import { generateMetadata as createMetadata } from '@/components/Metadata'; import type { Metadata } from 'next'; export async function generateMetadata(): Promise { return createMetadata({ title: 'Posts Archive', description: 'Browse all posts from Confessions of Grace, organized by year.', url: 'https://confessionsofgrace.com/posts', type: 'website' }); } async function getPostsAndYears(): Promise<{ posts: PostMetadata[]; years: number[] }> { const posts = await getSortedPostsData(); // Extract unique years from post dates const years = Array.from(new Set( posts.map(post => new Date(post.date).getFullYear()) )).sort((a, b) => b - a); // Sort years in descending order return { posts, years }; } export default async function PostsPage() { const { posts, years } = await getPostsAndYears(); return (

Archive

{years.map(year => (

{year}

    {posts .filter(post => new Date(post.date).getFullYear() === year) .map(post => (
  • {post.title}

    {post.author}

    {post.excerpt}

    {post.tags.map(tag => ( {tag} ))}
    Read post
  • ))}
))}
); }