@@ -1,198 +0,0 @@
1−import Head from "next/head";
2−import Meta from "../../components/Meta";
3−import Link from "next/link";
4−import { useRouter } from "next/router";
5−import classnames from "classnames";
6−import { join } from "path";
7−import { getPage, getPreviousPost, getNextPost } from "../../lib/lib";
8−import { Markdown } from "foundation-design-system";
9−import ContentArea from "../../components/ContentArea";
10−import Sidebar from "../../components/Sidebar";
11−import Pagination from "../../components/Pagination";
12−import UnderstandingUrbitTree from "../../cache/understanding-urbit.json";
13−
14−const breadcrumbs = (posts, paths) => {
15− const results = [
16− <Link href="/">Urbit</Link>,
17− <span className="px-1">/</span>,
18− <Link href="/understanding-urbit">Understanding Urbit</Link>,
19− ];
20− let thisLink = "/understanding-urbit";
21− for (const path of paths) {
22− posts = posts.children[path];
23− thisLink = join(thisLink, path);
24− results.push(
25− <span className="px-1">/</span>,
26− <Link href={thisLink}>{posts.title}</Link>
27− );
28− }
29− return results;
30−};
31−
32−const childPages = (thisLink, children, level = 0) => (
33− <ul>
34− {children?.map((child) => (
35− <li>{pageTree(join(thisLink, child.slug), child, level)}</li>
36− ))}
37− </ul>
38−);
39−
40−const pageTree = (thisLink, tree, level = 0) => {
41− const router = useRouter();
42−
43− const isThisPage = router.asPath === thisLink;
44−
45− const pageItemClasses = classnames({
46− "pl-4 text-base hover:text-green-400": level === 0,
47− "pl-8 text-base hover:text-green-400": level === 1,
48− "pl-12 text-base hover:text-green-400": level === 2,
49− "dot relative text-green-400": isThisPage,
50− "text-wall-600": !isThisPage,
51− });
52−
53− return (
54− <>
55− <Link href={thisLink} passHref>
56− <a className={`${pageItemClasses} cursor-pointer`}>{tree.title}</a>
57− </Link>
58− </>
59− );
60−};
61−
62−export default function UnderstandingLayout({
63− posts,
64− data,
65− params,
66− search,
67− markdown,
68− previousPost,
69− nextPost,
70−}) {
71− const router = useRouter();
72− const isSelected = "/understanding-urbit".includes(router.asPath);
73− const selectedClasses = classnames({
74− dot: isSelected,
75− "text-green-400": isSelected,
76− "text-wall-600": !isSelected,
77− });
78− const rootClasses = "pl-4 text-base hover:text-green-400";
79− return (
80− <>
81− <Head>
82− <title>{data.title} • Understanding Urbit • urbit.org</title>
83− {Meta(data)}
84− </Head>
85− <div className="flex h-screen min-h-screen w-screen sidebar">
86− <Sidebar search={search}>
87− <ul>
88− <li>
89− <Link href="/understanding-urbit" passHref>
90− <a className={`relative ${selectedClasses} ${rootClasses}`}>
91− Introduction
92− </a>
93− </Link>
94− </li>
95− </ul>
96− {childPages("/understanding-urbit", posts.pages)}
97− </Sidebar>
98− <ContentArea
99− breadcrumbs={breadcrumbs(posts, params.slug?.slice(0, -1) || "")}
100− title={data.title}
101− search={search}
102− section={"Understanding Urbit"}
103− params={params}
104− disableToC
105− >
106− <div className="markdown">
107− <Markdown.render content={JSON.parse(markdown)} />
108− </div>
109− <div className="flex justify-between mt-16">
110− {previousPost === null ? (
111− <div className={""} />
112− ) : (
113− <Pagination
114− previous
115− title="Previous Post"
116− post={previousPost}
117− className=""
118− section={join(
119− "understanding-urbit",
120− params.slug?.slice(0, -1).join("/")
121− )}
122− />
123− )}
124− {nextPost === null ? (
125− <div className={""} />
126− ) : (
127− <Pagination
128− next
129− title="Next Post"
130− post={nextPost}
131− className=""
132− section={join(
133− "understanding-urbit",
134− params.slug?.slice(0, -1).join("/")
135− )}
136− />
137− )}
138− </div>
139− </ContentArea>
140− </div>
141− </>
142− );
143−}
144−
145−export async function getStaticProps({ params }) {
146− const posts = UnderstandingUrbitTree;
147−
148− const { data, content } = getPage(
149− join(
150− process.cwd(),
151− "content/understanding-urbit",
152− params.slug?.join("/") || "/"
153− )
154− );
155− const markdown = JSON.stringify(Markdown.parse({ post: { content } }));
156−
157− const previousPost =
158− getPreviousPost(
159− params.slug?.slice(-1).join("") || "understanding-urbit",
160− ["title", "slug", "weight"],
161− join("understanding-urbit", params.slug?.slice(0, -1).join("/") || "/"),
162− "weight"
163− ) || null;
164−
165− const nextPost =
166− getNextPost(
167− params.slug?.slice(-1).join("") || "understanding-urbit",
168− ["title", "slug", "weight"],
169− join("understanding-urbit", params.slug?.slice(0, -1).join("/") || "/"),
170− "weight"
171− ) || null;
172−
173− return { props: { posts, data, markdown, params, previousPost, nextPost } };
174−}
175−
176−export async function getStaticPaths() {
177− const posts = UnderstandingUrbitTree;
178−
179− const slugs = [];
180−
181− const allHrefs = (thisLink, tree) => {
182− slugs.push(thisLink, ...tree.pages.map((e) => join(thisLink, e.slug)));
183− allHrefsChildren(thisLink, tree.children);
184− };
185−
186− const allHrefsChildren = (thisLink, children) => {
187− Object.entries(children).map(([childSlug, child]) => {
188− allHrefs(join(thisLink, childSlug), child);
189− });
190− };
191−
192− allHrefs("/understanding-urbit", posts);
193−
194− return {
195− paths: slugs,
196− fallback: false,
197− };
198−}