@@ -6,6 +6,8 @@ import classnames from "classnames";
6import { join } from "path";
6import { join } from "path";
7import { getDocs, formatDate, buildPageTree, getPage } from "../../lib/lib";
7import { getDocs, formatDate, buildPageTree, getPage } from "../../lib/lib";
8import Markdown from "../../components/Markdown";
8import Markdown from "../../components/Markdown";
9+import ContentArea from "../../components/ContentArea";
10+import Sidebar from "../../components/Sidebar";
9import Search from "../../components/Search";
11import Search from "../../components/Search";
10import { configure, GlobalHotKeys } from "react-hotkeys";
12import { configure, GlobalHotKeys } from "react-hotkeys";
@@ -40,37 +42,53 @@ const pageTree = (thisLink, tree, level = 0) => {
40 const firstCrumb = "/" + router.asPath.split("/").slice(1, -1).join("/");
42 const firstCrumb = "/" + router.asPath.split("/").slice(1, -1).join("/");
42 const includesThisPage = firstCrumb.includes(thisLink);
44 const includesThisPage = firstCrumb.includes(thisLink);
43− const isThisPage = firstCrumb === thisLink;
45+ const isThisPage = router.asPath === thisLink;
44 const [isOpen, toggleTree] = useState(includesThisPage);
46 const [isOpen, toggleTree] = useState(includesThisPage);
46 const activeClasses = classnames({
48 const activeClasses = classnames({
47 hidden: !isOpen,
49 hidden: !isOpen,
50− const headerClass = classnames({
52+ const headingItemClasses = classnames({
51− "text-gray": !isThisPage,
53+ "pl-0 text-black text-base font-semibold hover:text-green leading-relaxed":
55+ "pl-4 text-black text-base font-semibold hover:text-green": level === 1,
56+ "pl-8 text-black text-base hover:text-green": level === 2,
59+ const pageItemClasses = classnames({
60+ "pl-4 text-black text-base hover:text-green": level === 0,
61+ "pl-8 text-black text-base hover:text-green": level === 1,
62+ "pl-12 text-black text-base hover:text-green": level === 2,
52 dot: isThisPage,
63 dot: isThisPage,
58− "font-medium text-lg cursor-pointer hover:text-black relative " +
61− onClick={() => toggleTree(!isOpen)}
68+ <span onClick={() => toggleTree(!isOpen)}>
62− >
69+ <p className={`${headingItemClasses} cursor-pointer`}>{tree.title}</p>
65 <div className={activeClasses}>
71 <div className={activeClasses}>
66 <ul className={"pl-1"}>
72 <ul className={"pl-1"}>
68− .sort((a, b) => a.weight - b.weight)
69− .map(({ title, slug }) => (
73+ {tree.pages.map(({ title, slug }) => {
70− <li className="font-thin py-1">
71− <Link href={join(thisLink, slug)}>{title}</Link>
74+ const href = join(thisLink, slug);
75+ const isSelected = router.asPath === href;
76+ const selectedClasses = classnames({
78+ "text-green": isSelected,
84+ className={`relative ${pageItemClasses} ${selectedClasses}`}
75 {childPages(thisLink, tree.children, level + 1)}
93 {childPages(thisLink, tree.children, level + 1)}
@@ -78,47 +96,6 @@ const pageTree = (thisLink, tree, level = 0) => {
81−function Sidebar(props) {
83− <div className="flex flex-col w-72 bg-wall max-h-screen h-screen">
84− <header className="flex flex-shrink-0 justify-between items-center pl-12 pt-12 pb-8">
86− <a className="type-ui text-gray">Urbit.org</a>
89− <div className="overflow-y-scroll p-12 pt-16">
91− <div className="pb-32" />
97−function ContentArea(props) {
99− <div className="w-full">
100− <header className="flex justify-between items-center px-24 pt-12 pb-8">
101− <div className="type-ui">Urbit Documentation</div>
104− e.stopPropagation();
105− props.toggleSearch();
107− className="button-sm bg-wall text-gray"
109− Search Urbit.org<div className="ml-4 text-lightGray">⌘K</div>
112− <div className="px-24 pb-24 pt-16 flex flex-col w-full max-h-screen h-screen overflow-y-scroll">
113− <div className="type-ui text-lightGray">{props.breadcrumbs}</div>
114− <h2 className="mb-16 mt-4">{props.title}</h2>
116− <div className="pb-32" />
122export default function DocsLayout({ posts, data, content, params }) {
99export default function DocsLayout({ posts, data, content, params }) {
123 const [showSearch, toggleSearch] = useState(false);
100 const [showSearch, toggleSearch] = useState(false);
124 const toggle = () => toggleSearch((state) => !state);
101 const toggle = () => toggleSearch((state) => !state);
@@ -137,7 +114,7 @@ export default function DocsLayout({ posts, data, content, params }) {
137 <div className="flex w-screen h-screen min-h-screen w-screen overflow-hidden">
114 <div className="flex w-screen h-screen min-h-screen w-screen overflow-hidden">
138 <Sidebar>{childPages("/docs", posts.children)}</Sidebar>
115 <Sidebar>{childPages("/docs", posts.children)}</Sidebar>
139 <ContentArea
116 <ContentArea
140− breadcrumbs={breadcrumbs(posts, params.slug.slice(0, -1))}
117+ breadcrumbs={breadcrumbs(posts, params.slug?.slice(0, -1) || "")}
141 title={data.title}
118 title={data.title}
142 toggleSearch={() => toggleSearch(true)}
119 toggleSearch={() => toggleSearch(true)}
@@ -150,15 +127,18 @@ export default function DocsLayout({ posts, data, content, params }) {
151export async function getStaticProps({ params }) {
128export async function getStaticProps({ params }) {
152 const posts = buildPageTree(join(process.cwd(), "content/docs"), "weight");
129 const posts = buildPageTree(join(process.cwd(), "content/docs"), "weight");
153 const { data, content } = getPage(
131 const { data, content } = getPage(
154− join(process.cwd(), "content/docs", params.slug.join("/"))
132+ join(process.cwd(), "content/docs", params.slug?.join("/") || "/")
156 return { props: { posts, data, content, params } };
135 return { props: { posts, data, content, params } };
159export async function getStaticPaths() {
138export async function getStaticPaths() {
160 const posts = buildPageTree(join(process.cwd(), "content/docs"), "weight");
139 const posts = buildPageTree(join(process.cwd(), "content/docs"), "weight");
161 const slugs = [];
140 const slugs = [];
162 const allHrefs = (thisLink, tree) => {
142 const allHrefs = (thisLink, tree) => {
163 slugs.push(thisLink, ...tree.pages.map((e) => join(thisLink, e.slug)));
143 slugs.push(thisLink, ...tree.pages.map((e) => join(thisLink, e.slug)));
164 allHrefsChildren(thisLink, tree.children);
144 allHrefsChildren(thisLink, tree.children);
@@ -169,9 +149,11 @@ export async function getStaticPaths() {
169 allHrefs(join(thisLink, childSlug), child);
149 allHrefs(join(thisLink, childSlug), child);
172 allHrefs("/docs", posts);
153 allHrefs("/docs", posts);
174− paths: slugs.filter((e) => e !== "/docs"),
156+ paths: slugs,
175 fallback: false,
157 fallback: false,