2022-10-07 23:43:39 +02:00
|
|
|
import type { GetServerSideProps, NextPage } from "next";
|
2022-10-08 13:28:16 +02:00
|
|
|
import DiaryPageSelector from "../../../../components/Blog/DiaryPageSelector";
|
2022-10-07 23:43:39 +02:00
|
|
|
import Layout from "../../../../components/Blog/Layout";
|
2022-10-08 13:28:16 +02:00
|
|
|
import { generateContent, getContentList } from "../../../../lib/content/generateBackend";
|
|
|
|
import type { ContentList, Diary } from "../../../../lib/content/types";
|
2022-10-07 23:43:39 +02:00
|
|
|
|
|
|
|
import styles from "../../../../styles/Blog/Content.module.scss";
|
|
|
|
|
2022-10-08 13:28:16 +02:00
|
|
|
interface IContentRender extends Diary {
|
2022-10-07 23:43:39 +02:00
|
|
|
html: string;
|
2022-10-08 13:28:16 +02:00
|
|
|
pageSelected: number;
|
2022-10-07 23:43:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const DiaryMain: NextPage<{ content: IContentRender }> = ({ content }) => {
|
2022-10-08 13:28:16 +02:00
|
|
|
return <Layout title={`${content.entries[content.pageSelected - 1].title} - ${content.title} - c0ntroller.de`}>
|
2022-10-07 23:43:39 +02:00
|
|
|
<div dangerouslySetInnerHTML={{ __html: content.html }}>
|
|
|
|
</div>
|
2022-10-08 13:28:16 +02:00
|
|
|
<DiaryPageSelector title={content.title} pageSelected={content.pageSelected} name={content.name} pages={content.entries.map(e => e.title)} bottom />
|
2022-10-07 23:43:39 +02:00
|
|
|
</Layout>;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getServerSideProps: GetServerSideProps = async (context) => {
|
|
|
|
const { did, page } = context.query;
|
2022-10-08 13:28:16 +02:00
|
|
|
const contentList = await getContentList();
|
|
|
|
|
|
|
|
const contentEntry: Diary | undefined = (contentList as ContentList).find((c) => c.name === did && c.type === "diary") as Diary | undefined;
|
2022-10-07 23:43:39 +02:00
|
|
|
|
|
|
|
if (!contentEntry || !page || typeof page !== "string") return { notFound: true };
|
|
|
|
|
|
|
|
const contentHtml = await generateContent(contentEntry, Number.parseInt(page));
|
|
|
|
|
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
content: {
|
2022-10-08 13:28:16 +02:00
|
|
|
...contentEntry,
|
|
|
|
html: contentHtml,
|
|
|
|
pageSelected: Number.parseInt(page)
|
2022-10-07 23:43:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export default DiaryMain;
|