frontpage/pages/blog/project/[pid].tsx

45 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-10-07 23:03:39 +02:00
import type { GetServerSideProps, NextPage } from "next";
2022-10-07 23:36:57 +02:00
import Layout from "../../../components/Blog/Layout";
2022-10-08 13:28:16 +02:00
import { generateContent, getContentList } from "../../../lib/content/generateBackend";
2022-10-07 23:03:39 +02:00
import type { ContentList } from "../../../lib/content/types";
import styles from "../../../styles/Blog/Content.module.scss";
interface IContentRender {
2022-10-08 13:28:16 +02:00
more?: string;
repo?: string;
title: string;
html: string;
2022-10-07 23:03:39 +02:00
}
const Post: NextPage<{ content: IContentRender }> = ({ content }) => {
2022-10-08 13:28:16 +02:00
return <Layout title={`${content.title} - c0ntroller.de`}>
<div dangerouslySetInnerHTML={{ __html: content.html }}>
</div>
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 };
const contentHtml = await generateContent(contentEntry);
return {
2022-10-08 13:28:16 +02:00
props: {
content: {
more: contentEntry.more || null,
repo: contentEntry.repo || null,
title: contentEntry.title,
html: contentHtml,
}
}
};
2022-10-07 23:03:39 +02:00
};
export default Post;