@@ -4,10 +4,16 @@ import Link from "next/link";
44import { useRouter } from "next/router";
55import classnames from "classnames";
66import { join } from "path";
7−import { buildPageTree, getPage } from "../../lib/lib";
7+import {
8+ buildPageTree,
9+ getPage,
10+ getPreviousPost,
11+ getNextPost,
12+} from "../../lib/lib";
813import Markdown from "../../components/Markdown";
914import ContentArea from "../../components/ContentArea";
1015import Sidebar from "../../components/Sidebar";
16+import Pagination from "../../components/Pagination";
1117import markdownStyles from "../../styles/markdown.module.css";
1218import { decode } from "html-entities";
1319
@@ -65,6 +71,8 @@ export default function UnderstandingLayout({
6571 params,
6672 search,
6773 markdown,
74+ previousPost,
75+ nextPost,
6876}) {
6977 return (
7078 <>
@@ -87,6 +95,36 @@ export default function UnderstandingLayout({
8795 dangerouslySetInnerHTML={{ __html: decode(markdown) }}
8896 ></article>
8997 </div>
98+ <div className="flex justify-between mt-16">
99+ {previousPost === null ? (
100+ <div className={""} />
101+ ) : (
102+ <Pagination
103+ previous
104+ title="Previous Post"
105+ post={previousPost}
106+ className=""
107+ section={join(
108+ "understanding-urbit",
109+ params.slug?.slice(0, -1).join("/")
110+ )}
111+ />
112+ )}
113+ {nextPost === null ? (
114+ <div className={""} />
115+ ) : (
116+ <Pagination
117+ next
118+ title="Next Post"
119+ post={nextPost}
120+ className=""
121+ section={join(
122+ "understanding-urbit",
123+ params.slug?.slice(0, -1).join("/")
124+ )}
125+ />
126+ )}
127+ </div>
90128 </ContentArea>
91129 </div>
92130 </>
@@ -107,9 +145,25 @@ export async function getStaticProps({ params }) {
107145 )
108146 );
109147
148+ const previousPost =
149+ getPreviousPost(
150+ params.slug?.slice(-1).join("") || "understanding-urbit",
151+ ["title", "slug", "weight"],
152+ join("understanding-urbit", params.slug?.slice(0, -1).join("/") || "/"),
153+ "weight"
154+ ) || null;
155+
156+ const nextPost =
157+ getNextPost(
158+ params.slug?.slice(-1).join("") || "understanding-urbit",
159+ ["title", "slug", "weight"],
160+ join("understanding-urbit", params.slug?.slice(0, -1).join("/") || "/"),
161+ "weight"
162+ ) || null;
163+
110164 const markdown = await Markdown({ post: { content: content } });
111165
112− return { props: { posts, data, markdown, params } };
166+ return { props: { posts, data, markdown, params, previousPost, nextPost } };
113167}
114168
115169export async function getStaticPaths() {