svrjs-nextjs-website/app/(root)/changelog/[slug]/page.tsx
Dorian Niemiec a4cadaac3a
All checks were successful
Deploy Next.js application / deploy (push) Successful in 8m5s
fix: migrate the codebase from Next.js 14 to Next.js 15
2024-11-01 09:56:38 +01:00

70 lines
1.7 KiB
TypeScript

import { Skeleton } from "@/components/ui/skeleton";
import React from "react";
import ReactMarkdown from "react-markdown";
import Head from "next/head";
import clientPromise from "@/lib/db";
import { notFound } from "next/navigation";
interface Page {
title: string;
content: string;
}
export const dynamic = "force-static";
const Page = async (props: { params: Promise<{ slug: string }> }) => {
const params = await props.params;
const { slug } = params;
let page: Page | null = null;
let isNotFound = false;
try {
const client = await clientPromise;
const db = client.db(process.env.MONGODB_DB);
const fetchedPage = (await db
.collection("pages")
.findOne({ slug })) as unknown as Page;
if (fetchedPage) {
page = fetchedPage;
} else {
isNotFound = true;
}
} catch (err) {}
if (isNotFound) {
notFound();
}
if (!page) {
return null;
}
return (
<>
<section className="wrapper container py-24 md:py-28 gap-2 flex flex-col">
<h1 className="text-3xl md:text-5xl pb-1 md:pb-2 font-bold text-black dark:bg-clip-text dark:text-transparent dark:bg-gradient-to-b dark:from-white dark:to-neutral-400">
{page.title} change log
</h1>
<ReactMarkdown className="prose max-w-full md:prose-lg dark:prose-invert">
{page.content}
</ReactMarkdown>
</section>
</>
);
};
export async function generateStaticParams() {
try {
const client = await clientPromise;
const db = client.db(process.env.MONGODB_DB);
const slugs = await db.collection("pages").find().toArray();
return slugs.map((element) => {
return { slug: element.slug };
});
} catch (err) {
return [];
}
}
export default Page;