2022-10-07 23:03:39 +02:00
|
|
|
import type { GetServerSideProps, NextPage } from "next";
|
2022-10-15 22:17:51 +02:00
|
|
|
import ContentPage from "../../../components/Blog/ContentPage";
|
2022-10-07 23:36:57 +02:00
|
|
|
import Layout from "../../../components/Blog/Layout";
|
2022-10-18 16:46:33 +02:00
|
|
|
import { generateContent, getContentList, prepareDOM } from "../../../lib/content/generateBackend";
|
2022-10-15 22:17:51 +02:00
|
|
|
import type { ContentList, ProjectRender } from "../../../lib/content/types";
|
2022-10-07 23:03:39 +02:00
|
|
|
|
2022-10-15 22:17:51 +02:00
|
|
|
const Post: NextPage<{ content: ProjectRender }> = ({ content }) => {
|
2022-10-08 13:28:16 +02:00
|
|
|
return <Layout title={`${content.title} - c0ntroller.de`}>
|
2022-10-15 22:17:51 +02:00
|
|
|
<ContentPage content={content} />
|
2022-10-07 23:36:57 +02:00
|
|
|
</Layout>;
|
2022-10-07 23:03:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export const getServerSideProps: GetServerSideProps = async (context) => {
|
|
|
|
const { pid } = context.query;
|
2022-10-08 13:28:16 +02:00
|
|
|
const contentList = await getContentList();
|
|
|
|
|
2022-10-07 23:03:39 +02:00
|
|
|
const contentEntry = (contentList as ContentList).find((c) => c.name === pid && c.type === "project");
|
|
|
|
|
|
|
|
|
|
|
|
if (!contentEntry) return { notFound: true };
|
|
|
|
|
2022-11-03 14:49:32 +01:00
|
|
|
const contentHtml = await generateContent(contentEntry) as string;
|
2022-10-18 16:46:33 +02:00
|
|
|
const contentPrepared = prepareDOM(contentHtml);
|
2022-10-07 23:03:39 +02:00
|
|
|
|
2022-11-03 15:12:03 +01:00
|
|
|
context.res.setHeader("Cache-Control", "public, s-maxage=3600, stale-while-revalidate=600");
|
|
|
|
|
2022-10-07 23:03:39 +02:00
|
|
|
return {
|
2022-10-08 13:28:16 +02:00
|
|
|
props: {
|
|
|
|
content: {
|
|
|
|
more: contentEntry.more || null,
|
|
|
|
repo: contentEntry.repo || null,
|
|
|
|
title: contentEntry.title,
|
2022-10-18 16:46:33 +02:00
|
|
|
html: contentPrepared,
|
2022-10-08 13:28:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2022-10-07 23:03:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Post;
|