2024-04-20 02:35:52 +01:00
|
|
|
import { getDocumentation } from "@/app/common/documentation";
|
2024-04-20 02:59:07 +01:00
|
|
|
import { CustomMDX } from "@/app/components/mdx-components";
|
2024-04-20 00:50:59 +01:00
|
|
|
import { Metadata } from "next";
|
2024-04-20 02:35:52 +01:00
|
|
|
import { generateEmbed } from "@/app/common/embed";
|
2024-04-20 03:22:10 +01:00
|
|
|
import { Title } from "@/app/components/title";
|
2024-04-20 00:50:59 +01:00
|
|
|
|
|
|
|
type DocumentationPageParams = {
|
|
|
|
params: {
|
2024-04-20 02:04:42 +01:00
|
|
|
slug?: string[];
|
2024-04-20 00:50:59 +01:00
|
|
|
};
|
|
|
|
};
|
2024-04-20 00:34:42 +01:00
|
|
|
|
|
|
|
export async function generateStaticParams() {
|
|
|
|
let documentationPages = getDocumentation();
|
|
|
|
|
|
|
|
return documentationPages.map(page => ({
|
|
|
|
slug: [page.slug],
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2024-04-20 03:22:10 +01:00
|
|
|
/**
|
|
|
|
* Gets a documentation page by its slug.
|
|
|
|
*
|
|
|
|
* @param slug The slug of the documentation page.
|
|
|
|
*/
|
|
|
|
function getPage(slug?: string) {
|
2024-04-20 00:50:59 +01:00
|
|
|
const documentationPages = getDocumentation();
|
2024-04-20 03:22:10 +01:00
|
|
|
let page = documentationPages.find(page => page.slug === slug);
|
2024-04-20 00:50:59 +01:00
|
|
|
|
2024-04-20 03:22:10 +01:00
|
|
|
// Fallback to the landing page
|
2024-04-20 02:04:42 +01:00
|
|
|
if (!page && !slug) {
|
|
|
|
page = documentationPages.find(page => page.slug === "landing");
|
|
|
|
}
|
|
|
|
|
2024-04-20 03:22:10 +01:00
|
|
|
// We still can't find the page, return undefined
|
|
|
|
if (!page) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
return page;
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function generateMetadata({ params: { slug } }: DocumentationPageParams): Promise<Metadata> {
|
|
|
|
const page = getPage(slug?.join("/"));
|
|
|
|
|
2024-04-20 02:04:42 +01:00
|
|
|
// Fallback to page not found
|
2024-04-20 00:50:59 +01:00
|
|
|
if (!page) {
|
|
|
|
return generateEmbed({
|
|
|
|
title: "Page not found",
|
|
|
|
description: "The documentation page was not found",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return generateEmbed({
|
2024-04-20 03:04:23 +01:00
|
|
|
title: `${page.metadata.title} - Documentation`,
|
2024-04-20 02:04:42 +01:00
|
|
|
description: `${page.metadata.description}\n\nClick to view this page`,
|
2024-04-20 00:50:59 +01:00
|
|
|
});
|
|
|
|
}
|
2024-04-20 00:34:42 +01:00
|
|
|
|
|
|
|
export default function Page({ params: { slug } }: DocumentationPageParams) {
|
2024-04-20 03:22:10 +01:00
|
|
|
const page = getPage(slug?.join("/"));
|
2024-04-20 00:34:42 +01:00
|
|
|
|
2024-04-20 02:04:42 +01:00
|
|
|
// Page was not found, show an error page
|
2024-04-20 00:34:42 +01:00
|
|
|
if (!page) {
|
2024-04-20 02:04:42 +01:00
|
|
|
return (
|
|
|
|
<div className="text-center flex flex-col gap-2">
|
|
|
|
<h1 className="text-red-400 text-2xl">Not Found</h1>
|
|
|
|
<p>The page you are looking for was not found.</p>
|
|
|
|
</div>
|
|
|
|
);
|
2024-04-20 00:34:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="w-full px-4 flex flex-col gap-4">
|
2024-04-20 02:04:42 +01:00
|
|
|
{/* The documentation page title and description */}
|
|
|
|
<div className="text-center mb-4">
|
2024-04-20 03:22:10 +01:00
|
|
|
<Title title={page.metadata.title} subtitle={page.metadata.description} />
|
2024-04-20 02:04:42 +01:00
|
|
|
</div>
|
2024-04-20 00:34:42 +01:00
|
|
|
|
|
|
|
{/* The content of the documentation page */}
|
|
|
|
<div className="text-left w-full">
|
|
|
|
<CustomMDX source={page.content} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|