Files
website/src/app/projects/[slug]/page.tsx

50 lines
2.0 KiB
TypeScript

import { getPostBySlug, getPostSlugs, getPostFrontmatter } from '@/lib/mdx'; // Assume getPostFrontmatter exists
import { notFound } from 'next/navigation';
import { DATA } from '@/data/resume';
import { getPublicationsData } from '@/lib/publications';
import { ProjectArticle } from '@/components/project-article';
// Helper function to get frontmatter for a slug (you may need to create this in lib/mdx.ts)
// It's a lighter version of getPostBySlug that only parses frontmatter.
// If you don't have it, we can just use getPostBySlug, it's just slightly less performant.
export async function generateStaticParams() {
const slugs = getPostSlugs('projects');
return slugs.map((slug) => ({ slug }));
}
export async function generateMetadata({ params }: { params: { slug: string } }) {
const post = await getPostBySlug('projects', params.slug);
if (!post) { return {}; }
return {
title: post.frontmatter.title,
description: post.frontmatter.description || DATA.description,
};
}
export default async function ProjectPage({ params }: { params: { slug: string } }) {
const { slug } = params;
const post = await getPostBySlug('projects', slug);
const publications = getPublicationsData();
if (!post) {
notFound();
}
// --- Logic for Previous/Next Navigation ---
const allSlugs = getPostSlugs('projects'); // Or get them from your DATA file if they are ordered there
const currentIndex = allSlugs.findIndex((s) => s === slug);
const prevSlug = currentIndex > 0 ? allSlugs[currentIndex - 1] : null;
const nextSlug = currentIndex < allSlugs.length - 1 ? allSlugs[currentIndex + 1] : null;
const prevPost = prevSlug ? await getPostBySlug('projects', prevSlug) : null;
const nextPost = nextSlug ? await getPostBySlug('projects', nextSlug) : null;
const navigation = {
prev: prevPost ? { slug: prevSlug, title: prevPost.frontmatter.title } : null,
next: nextPost ? { slug: nextSlug, title: nextPost.frontmatter.title } : null,
};
return <ProjectArticle post={post} publications={publications} navigation={navigation} />;
}