on master help sign in
understanding-urbit: add pagination
ae124a1Matilde Park
components/Pagination.js+2−2
@@ -11,9 +11,9 @@ export default function Pagination(props) {
11 className="bg-wall cursor-pointer font-semibold p-2 px-4 rounded-xl flex"
11 className="bg-wall cursor-pointer font-semibold p-2 px-4 rounded-xl flex"
12 style={{ maxWidth: "45%" }}
12 style={{ maxWidth: "45%" }}
13 >
13 >
14− <p className="flex-shrink-0">{props.previous ? "<- " : ""}</p>
14+ <p className="flex-shrink-0 pr-1">{props.previous ? "<- " : ""}</p>
15 <p className="text-black truncate">{props.post.title}</p>
15 <p className="text-black truncate">{props.post.title}</p>
16− <p className="flex-shrink-0">{props.next ? " ->" : ""}</p>
16+ <p className="flex-shrink-0 pl-1">{props.next ? " ->" : ""}</p>
17 </div>
17 </div>
18 </Link>
18 </Link>
19 );
19 );
content/understanding-urbit/interface.md+1−1
@@ -1,7 +1,7 @@
1+++
1+++
2title = "Interface"
2title = "Interface"
3description = "What Urbit feels like to an everyday user"
3description = "What Urbit feels like to an everyday user"
4−weight = 3
4+weight = 4
5[extra]
5[extra]
6flatten_pagination = "true"
6flatten_pagination = "true"
7hide_next_title = "true"
7hide_next_title = "true"
content/understanding-urbit/people-history.md+1−1
@@ -1,7 +1,7 @@
1+++
1+++
2title = "People + History"
2title = "People + History"
3description = "Where we've been and were we are now"
3description = "Where we've been and were we are now"
4−weight = 5
4+weight = 6
5[extra]
5[extra]
6flatten_pagination = "true"
6flatten_pagination = "true"
7hide_next_title = "true"
7hide_next_title = "true"
content/understanding-urbit/roadmap.md+1−1
@@ -1,7 +1,7 @@
1+++
1+++
2title = "Roadmap: OS 1 -> OS N"
2title = "Roadmap: OS 1 -> OS N"
3description = "The core ideas that Urbit is built around"
3description = "The core ideas that Urbit is built around"
4−weight = 4
4+weight = 5
5[extra]
5[extra]
6flatten_pagination = "true"
6flatten_pagination = "true"
7hide_next_title = "true"
7hide_next_title = "true"
content/understanding-urbit/urbit-id.md+1−1
@@ -1,7 +1,7 @@
1+++
1+++
2title = "Urbit ID"
2title = "Urbit ID"
3description = "An overview of the Urbit ID system"
3description = "An overview of the Urbit ID system"
4−weight = 2
4+weight = 3
5[extra]
5[extra]
6flatten_pagination = "true"
6flatten_pagination = "true"
7hide_next_title = "true"
7hide_next_title = "true"
content/understanding-urbit/urbit-os.md+1−1
@@ -1,7 +1,7 @@
1+++
1+++
2title = "Urbit OS"
2title = "Urbit OS"
3description = "What Urbit should feel like to an everyday user"
3description = "What Urbit should feel like to an everyday user"
4−weight = 1
4+weight = 2
5[extra]
5[extra]
6flatten_pagination = "true"
6flatten_pagination = "true"
7hide_next_title = "true"
7hide_next_title = "true"
pages/understanding-urbit/[[...slug]].js+56−2
@@ -4,10 +4,16 @@ import Link from "next/link";
4import { useRouter } from "next/router";
4import { useRouter } from "next/router";
5import classnames from "classnames";
5import classnames from "classnames";
6import { join } from "path";
6import { join } from "path";
7+import {
7−import { buildPageTree, getPage } from "../../lib/lib";
8+ buildPageTree,
9+ getPage,
10+ getPreviousPost,
11+ getNextPost,
12+} from "../../lib/lib";
8import Markdown from "../../components/Markdown";
13import Markdown from "../../components/Markdown";
9import ContentArea from "../../components/ContentArea";
14import ContentArea from "../../components/ContentArea";
10import Sidebar from "../../components/Sidebar";
15import Sidebar from "../../components/Sidebar";
16+import Pagination from "../../components/Pagination";
11import markdownStyles from "../../styles/markdown.module.css";
17import markdownStyles from "../../styles/markdown.module.css";
12import { decode } from "html-entities";
18import { decode } from "html-entities";
13
19
@@ -65,6 +71,8 @@ export default function UnderstandingLayout({
65 params,
71 params,
66 search,
72 search,
67 markdown,
73 markdown,
74+ previousPost,
75+ nextPost,
68}) {
76}) {
69 return (
77 return (
70 <>
78 <>
@@ -87,6 +95,36 @@ export default function UnderstandingLayout({
87 dangerouslySetInnerHTML={{ __html: decode(markdown) }}
95 dangerouslySetInnerHTML={{ __html: decode(markdown) }}
88 ></article>
96 ></article>
89 </div>
97 </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>
90 </ContentArea>
128 </ContentArea>
91 </div>
129 </div>
92 </>
130 </>
@@ -107,9 +145,25 @@ export async function getStaticProps({ params }) {
107 )
145 )
108 );
146 );
109
147
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+
110 const markdown = await Markdown({ post: { content: content } });
164 const markdown = await Markdown({ post: { content: content } });
111
165
112− return { props: { posts, data, markdown, params } };
166+ return { props: { posts, data, markdown, params, previousPost, nextPost } };
113}
167}
114
168
115export async function getStaticPaths() {
169export async function getStaticPaths() {