Rename legacy /blog/[slug] redirect to /blog/[id] so it matches the nested [id]/[slug] segment name. Co-authored-by: Cursor <cursoragent@cursor.com>
23 lines
610 B
TypeScript
23 lines
610 B
TypeScript
import { notFound, redirect } from "next/navigation";
|
|
import { blogHref, fetchBlogBySlug } from "@/lib/blog";
|
|
import { getBlogPost } from "@/lib/data";
|
|
|
|
export const revalidate = 60;
|
|
|
|
/** Legacy `/blog/{slug-or-id}` → canonical `/blog/{id}/{titleSlug}`. */
|
|
export default async function LegacyBlogRedirect({
|
|
params,
|
|
}: {
|
|
params: Promise<{ id: string }>;
|
|
}) {
|
|
const { id } = await params;
|
|
|
|
const apiPost = await fetchBlogBySlug(id);
|
|
if (apiPost) redirect(blogHref(apiPost));
|
|
|
|
const local = getBlogPost(id);
|
|
if (local) redirect(blogHref({ id: local.slug, title: local.title }));
|
|
|
|
notFound();
|
|
}
|