diff --git a/lib/content/generateBackend.ts b/lib/content/generateBackend.ts
index 8df6a5a..3a1d594 100644
--- a/lib/content/generateBackend.ts
+++ b/lib/content/generateBackend.ts
@@ -13,13 +13,24 @@ const projectServerErrorHtml = `
Sorry! A server error ha
const ad = asciidoctor();
-// No error catching here as we are screwed if this fails
+const listPath = resolve("./public", "content", "list.json");
const projectPath = resolve("./public", "content", "projects");
const diaryPath = resolve("./public", "content", "diaries");
+// No error catching here as we are screwed if this fails
const projectFiles = readdirSync(projectPath, { withFileTypes: true }).filter((f) => f.isFile() && f.name.endsWith(".adoc"));
// As we need the diaries too, no filter here
const diaryFiles = readdirSync(diaryPath, { withFileTypes: true });
+export async function getContentList() {
+ try {
+ const list = await readFile(listPath, { encoding: "utf-8" });
+ return JSON.parse(list);
+ } catch (e) {
+ console.error(e);
+ return [];
+ }
+}
+
export async function generateContent(content: Project|Diary, selectedPage?: number): Promise
{
if(!content) return projectEmpty;
switch (content.type) {
diff --git a/pages/blog/diary/[did].tsx b/pages/blog/diary/[did].tsx
index aa1b01f..e79a3e9 100644
--- a/pages/blog/diary/[did].tsx
+++ b/pages/blog/diary/[did].tsx
@@ -1,30 +1,29 @@
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 DiaryPageSelector from "../../../components/Blog/DiaryPageSelector";
+import { generateContent, getContentList } from "../../../lib/content/generateBackend";
+import type { ContentList, Diary } from "../../../lib/content/types";
import styles from "../../../styles/Blog/Content.module.scss";
-interface IContentRender {
- more?: string;
- repo?: string;
- title: string;
+interface IContentRender extends Diary {
html: string;
}
const DiaryMain: NextPage<{ content: IContentRender }> = ({ content }) => {
- console.log(content);
return
+ e.title)} />
+ e.title)} bottom />
;
};
export const getServerSideProps: GetServerSideProps = async (context) => {
const { did } = context.query;
- const contentEntry = (contentList as ContentList).find((c) => c.name === did && c.type === "diary");
+ const contentList = await getContentList();
+
+ const contentEntry: Diary | undefined = (contentList as ContentList).find((c) => c.name === did && c.type === "diary") as Diary | undefined;
if (!contentEntry) return { notFound: true };
@@ -33,9 +32,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
return {
props: {
content: {
- more: contentEntry.more || null,
- repo: contentEntry.repo || null,
- title: contentEntry.title,
+ ...contentEntry,
html: contentHtml
}
}
diff --git a/pages/blog/diary/[did]/[page].tsx b/pages/blog/diary/[did]/[page].tsx
index dc90243..f31728d 100644
--- a/pages/blog/diary/[did]/[page].tsx
+++ b/pages/blog/diary/[did]/[page].tsx
@@ -1,29 +1,29 @@
import type { GetServerSideProps, NextPage } from "next";
+import DiaryPageSelector from "../../../../components/Blog/DiaryPageSelector";
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 { generateContent, getContentList } from "../../../../lib/content/generateBackend";
+import type { ContentList, Diary } from "../../../../lib/content/types";
import styles from "../../../../styles/Blog/Content.module.scss";
-interface IContentRender {
- more?: string;
- repo?: string;
- title: string;
+interface IContentRender extends Diary {
html: string;
+ pageSelected: number;
}
const DiaryMain: NextPage<{ content: IContentRender }> = ({ content }) => {
- return
+ return
+ e.title)} bottom />
;
};
export const getServerSideProps: GetServerSideProps = async (context) => {
const { did, page } = context.query;
- const contentEntry = (contentList as ContentList).find((c) => c.name === did && c.type === "diary");
+ const contentList = await getContentList();
+
+ const contentEntry: Diary | undefined = (contentList as ContentList).find((c) => c.name === did && c.type === "diary") as Diary | undefined;
if (!contentEntry || !page || typeof page !== "string") return { notFound: true };
@@ -32,10 +32,9 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
return {
props: {
content: {
- more: contentEntry.more || null,
- repo: contentEntry.repo || null,
- title: contentEntry.title,
- html: contentHtml
+ ...contentEntry,
+ html: contentHtml,
+ pageSelected: Number.parseInt(page)
}
}
};
diff --git a/pages/blog/project/[pid].tsx b/pages/blog/project/[pid].tsx
index 45448b3..92305d0 100644
--- a/pages/blog/project/[pid].tsx
+++ b/pages/blog/project/[pid].tsx
@@ -1,28 +1,28 @@
import type { GetServerSideProps, NextPage } from "next";
import Layout from "../../../components/Blog/Layout";
-import { generateContent } from "../../../lib/content/generateBackend";
+import { generateContent, getContentList } 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;
+ more?: string;
+ repo?: string;
+ title: string;
+ html: string;
}
const Post: NextPage<{ content: IContentRender }> = ({ content }) => {
- return
-
-
+ return
+
+
;
};
export const getServerSideProps: GetServerSideProps = async (context) => {
const { pid } = context.query;
+ const contentList = await getContentList();
+
const contentEntry = (contentList as ContentList).find((c) => c.name === pid && c.type === "project");
@@ -31,15 +31,15 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
const contentHtml = await generateContent(contentEntry);
return {
- props: {
- content: {
- more: contentEntry.more || null,
- repo: contentEntry.repo || null,
- title: contentEntry.title,
- html: contentHtml
- }
- }
- };
+ props: {
+ content: {
+ more: contentEntry.more || null,
+ repo: contentEntry.repo || null,
+ title: contentEntry.title,
+ html: contentHtml,
+ }
+ }
+ };
};
export default Post;
\ No newline at end of file