From 3268faaf4be5a2b39f5d0efff29b1821300a6bb7 Mon Sep 17 00:00:00 2001 From: Daniel Kluge Date: Fri, 7 Oct 2022 23:43:39 +0200 Subject: [PATCH] Basic diary page --- pages/blog/diary/[did].tsx | 45 +++++++++++++++++++++++++++++++ pages/blog/diary/[did]/[page].tsx | 44 ++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 pages/blog/diary/[did].tsx create mode 100644 pages/blog/diary/[did]/[page].tsx diff --git a/pages/blog/diary/[did].tsx b/pages/blog/diary/[did].tsx new file mode 100644 index 0000000..aa1b01f --- /dev/null +++ b/pages/blog/diary/[did].tsx @@ -0,0 +1,45 @@ +import type { GetServerSideProps, NextPage } from "next"; +import Layout from "../../../components/Blog/Layout"; +import { generateContent } from "../../../lib/content/generateBackend"; +import type { ContentList } from "../../../lib/content/types"; + +import contentList from "../../../public/content/list.json"; + +import styles from "../../../styles/Blog/Content.module.scss"; + +interface IContentRender { + more?: string; + repo?: string; + title: string; + html: string; +} + +const DiaryMain: NextPage<{ content: IContentRender }> = ({ content }) => { + console.log(content); + return +
+
+
; +}; + +export const getServerSideProps: GetServerSideProps = async (context) => { + const { did } = context.query; + const contentEntry = (contentList as ContentList).find((c) => c.name === did && c.type === "diary"); + + if (!contentEntry) return { notFound: true }; + + const contentHtml = await generateContent(contentEntry); + + return { + props: { + content: { + more: contentEntry.more || null, + repo: contentEntry.repo || null, + title: contentEntry.title, + html: contentHtml + } + } + }; +}; + +export default DiaryMain; \ No newline at end of file diff --git a/pages/blog/diary/[did]/[page].tsx b/pages/blog/diary/[did]/[page].tsx new file mode 100644 index 0000000..dc90243 --- /dev/null +++ b/pages/blog/diary/[did]/[page].tsx @@ -0,0 +1,44 @@ +import type { GetServerSideProps, NextPage } from "next"; +import Layout from "../../../../components/Blog/Layout"; +import { generateContent } from "../../../../lib/content/generateBackend"; +import type { ContentList } from "../../../../lib/content/types"; + +import contentList from "../../../../public/content/list.json"; + +import styles from "../../../../styles/Blog/Content.module.scss"; + +interface IContentRender { + more?: string; + repo?: string; + title: string; + html: string; +} + +const DiaryMain: NextPage<{ content: IContentRender }> = ({ content }) => { + return +
+
+
; +}; + +export const getServerSideProps: GetServerSideProps = async (context) => { + const { did, page } = context.query; + const contentEntry = (contentList as ContentList).find((c) => c.name === did && c.type === "diary"); + + if (!contentEntry || !page || typeof page !== "string") return { notFound: true }; + + const contentHtml = await generateContent(contentEntry, Number.parseInt(page)); + + return { + props: { + content: { + more: contentEntry.more || null, + repo: contentEntry.repo || null, + title: contentEntry.title, + html: contentHtml + } + } + }; +}; + +export default DiaryMain; \ No newline at end of file