68 lines
1.9 KiB
TypeScript
68 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 }>;
|
|
};
|
|
|
|
const page = "experience"
|
|
|
|
export async function generateStaticParams() {
|
|
const slugs = getPostSlugs(page);
|
|
return slugs.map((slug) => ({ slug }));
|
|
}
|
|
|
|
export async function generateMetadata({ params }: Props) {
|
|
const { slug } = await params;
|
|
|
|
if (!slug) {
|
|
return {};
|
|
}
|
|
|
|
const post = await getPostBySlug(page, slug);
|
|
if (!post) {
|
|
return {};
|
|
}
|
|
return {
|
|
title: post.frontmatter.title,
|
|
description: post.frontmatter.teaser || DATA.description,
|
|
alternates: {
|
|
canonical: `${DATA.url}/${page}/${slug}`,
|
|
},
|
|
};
|
|
}
|
|
|
|
export default async function ExperiencePage({ params }: Props) {
|
|
const { slug } = await params;
|
|
|
|
if (!slug) {
|
|
notFound();
|
|
}
|
|
|
|
const post = await getPostBySlug(page, slug);
|
|
const publications = getPublicationsData();
|
|
|
|
if (!post) {
|
|
notFound();
|
|
}
|
|
|
|
// --- Navigation Logic ---
|
|
const allSlugs = getPostSlugs(page);
|
|
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(page, prevSlug) : null;
|
|
const nextPost: Post | null = nextSlug ? await getPostBySlug(page, 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={page} />;
|
|
} |