svrjs-nextjs-website/app/(root)/changelog/[slug]/page.tsx

70 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-07-28 12:52:13 +02:00
import { Skeleton } from "@/components/ui/skeleton";
import React from "react";
2024-07-23 20:02:57 +02:00
import ReactMarkdown from "react-markdown";
2024-07-28 16:47:09 +02:00
import Head from "next/head";
import clientPromise from "@/lib/db";
import { notFound } from "next/navigation";
2024-07-23 20:02:57 +02:00
interface Page {
title: string;
content: string;
}
2024-07-23 20:02:57 +02:00
export const dynamic = "force-static";
2024-07-25 20:29:21 +02:00
const Page = async ({ params }: { params: { slug: string } }) => {
const { slug } = params;
let page: Page | null = null;
let isNotFound = false;
2024-07-23 20:02:57 +02:00
try {
const client = await clientPromise;
const db = client.db(process.env.MONGODB_DB);
2024-07-25 20:29:21 +02:00
const fetchedPage = (await db
.collection("pages")
.findOne({ slug })) as unknown as Page;
if (fetchedPage) {
page = fetchedPage;
} else {
isNotFound = true;
}
} catch (err) {}
if (isNotFound) {
notFound();
}
2024-07-23 20:02:57 +02:00
if (!page) {
return null;
}
2024-07-25 20:29:21 +02:00
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>
</>
);
2024-07-23 20:02:57 +02:00
};
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 [];
}
}
2024-07-23 20:02:57 +02:00
export default Page;