@@ -4,7 +4,13 @@ import { useRouter } from "next/router";
44import { useState } from "react";
55import classnames from "classnames";
66import { join } from "path";
7−import { getDocs, formatDate, buildPageTree, getPage } from "../../lib/lib";
7+import {
8+ getPreviousPost,
9+ getNextPost,
10+ buildPageTree,
11+ getPage,
12+} from "../../lib/lib";
13+import Pagination from "../../components/Pagination";
814import Markdown from "../../components/Markdown";
915import ContentArea from "../../components/ContentArea";
1016import Sidebar from "../../components/Sidebar";
@@ -95,7 +101,15 @@ const pageTree = (thisLink, tree, level = 0) => {
95101 );
96102};
97103
98−export default function DocsLayout({ posts, data, params, search, markdown }) {
104+export default function DocsLayout({
105+ posts,
106+ data,
107+ params,
108+ search,
109+ markdown,
110+ previousPost,
111+ nextPost,
112+}) {
99113 const router = useRouter();
100114 const isSelected = "/docs".includes(router.asPath);
101115 const selectedClasses = classnames({
@@ -133,6 +147,30 @@ export default function DocsLayout({ posts, data, params, search, markdown }) {
133147 dangerouslySetInnerHTML={{ __html: decode(markdown) }}
134148 ></article>
135149 </div>
150+ <div className="flex justify-between mt-16">
151+ {previousPost === null ? (
152+ <div className={""} />
153+ ) : (
154+ <Pagination
155+ previous
156+ title="Previous Post"
157+ post={previousPost}
158+ className=""
159+ section={join("docs", params.slug?.slice(0, -1).join("/"))}
160+ />
161+ )}
162+ {nextPost === null ? (
163+ <div className={""} />
164+ ) : (
165+ <Pagination
166+ next
167+ title="Next Post"
168+ post={nextPost}
169+ className=""
170+ section={join("docs", params.slug?.slice(0, -1).join("/"))}
171+ />
172+ )}
173+ </div>
136174 </ContentArea>
137175 </div>
138176 </>
@@ -146,9 +184,25 @@ export async function getStaticProps({ params }) {
146184 join(process.cwd(), "content/docs", params.slug?.join("/") || "/")
147185 );
148186
187+ const previousPost =
188+ getPreviousPost(
189+ params.slug?.slice(-1).join("") || "docs",
190+ ["title", "slug", "weight"],
191+ join("docs", params.slug?.slice(0, -1).join("/") || "/"),
192+ "weight"
193+ ) || null;
194+
195+ const nextPost =
196+ getNextPost(
197+ params.slug?.slice(-1).join("") || "docs",
198+ ["title", "slug", "weight"],
199+ join("docs", params.slug?.slice(0, -1).join("/") || "/"),
200+ "weight"
201+ ) || null;
202+
149203 const markdown = await Markdown({ post: { content: content } });
150204
151− return { props: { posts, data, markdown, params } };
205+ return { props: { posts, data, markdown, previousPost, nextPost, params } };
152206}
153207
154208export async function getStaticPaths() {