63 lines
1.9 KiB
TypeScript
63 lines
1.9 KiB
TypeScript
import { getPostBySlug, getPostSlugs, Post } from '@/lib/mdx';
|
|
import { notFound } from 'next/navigation';
|
|
import { DATA } from '@/app/resume';
|
|
import { getPublicationsData } from '@/lib/publications';
|
|
import { Article } from '@/components/page-article';
|
|
|
|
type Props = {
|
|
params: Promise<{ slug: string }>;
|
|
searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
|
|
};
|
|
|
|
export async function generateStaticParams() {
|
|
const slugs = getPostSlugs('experience');
|
|
return slugs.map((slug) => ({ slug }));
|
|
}
|
|
|
|
export async function generateMetadata({ params }: Props) {
|
|
const { slug } = await params;
|
|
|
|
if (!slug) {
|
|
return {};
|
|
}
|
|
|
|
const post = await getPostBySlug('experience', slug);
|
|
if (!post) {
|
|
return {};
|
|
}
|
|
return {
|
|
title: post.frontmatter.title,
|
|
description: post.frontmatter.teaser || DATA.description,
|
|
};
|
|
}
|
|
|
|
export default async function ExperiencePage({ params }: Props) {
|
|
const { slug } = await params;
|
|
|
|
if (!slug) {
|
|
notFound();
|
|
}
|
|
|
|
const post = await getPostBySlug('experience', slug);
|
|
const publications = getPublicationsData();
|
|
|
|
if (!post) {
|
|
notFound();
|
|
}
|
|
|
|
// --- Navigation Logic ---
|
|
const allSlugs = getPostSlugs('experience');
|
|
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: Post | null = prevSlug ? await getPostBySlug('experience', prevSlug) : null;
|
|
const nextPost: Post | null = nextSlug ? await getPostBySlug('experience', nextSlug) : null;
|
|
|
|
const navigation = {
|
|
prev: prevPost ? { slug: prevSlug!, title: prevPost.frontmatter.title } : null,
|
|
next: nextPost ? { slug: nextSlug!, title: nextPost.frontmatter.title } : null,
|
|
};
|
|
|
|
return <Article post={post} publications={publications} navigation={navigation} basePath="experience" />;
|
|
} |