import fs from "fs"; import path from "path"; import Link from "next/link"; import { PageTransition } from "@/components/PageTransition"; import { Metadata } from "next"; import BackButton from "@/components/BackButton"; export const metadata: Metadata = { title: "Blog", description: "Read Asher Falcon's blog posts on software engineering, projects, and technology", keywords: ["blog", "software engineering", "coding", "projects", "tech"], }; const postsDirectory = path.join(process.cwd(), "src/app/blog/posts"); // Filter out system files and hidden files const isValidPostDirectory = (dirname: string) => { return !dirname.startsWith(".") && !dirname.includes(".DS_Store") && fs.statSync(path.join(postsDirectory, dirname)).isDirectory(); }; export async function generateStaticParams() { const allFiles = fs.readdirSync(postsDirectory); const postFolders = allFiles.filter(isValidPostDirectory); return postFolders.map((slug) => ({ slug })); } type PostData = { slug: string; title: string; description: string; }; export default async function BlogPage() { const allFiles = fs.readdirSync(postsDirectory); const postFolders = allFiles.filter(isValidPostDirectory); const posts = await Promise.all( postFolders.map(async (slug): Promise => { try { const { title, description } = await import(`./posts/${slug}/metadata.ts`); return { slug, title, description }; } catch (error) { console.error(`Error loading metadata for ${slug}:`, error); return null; } }) ); // Filter out any posts that failed to load and reverse for newest first const validPosts: PostData[] = posts.filter((post): post is PostData => post !== null).reverse(); return (
Posts
    {validPosts.map(({ slug, title, description }) => (
  • {title}

    {description}

  • ))}
); }