current directory view
This commit is contained in:
parent
730533e88e
commit
6908b4f7b9
3 changed files with 89 additions and 24 deletions
|
@ -1,10 +1,10 @@
|
||||||
|
import WikiPage from "../../interfaces/WikiPage";
|
||||||
import mdStyles from "./markdown.module.css";
|
import mdStyles from "./markdown.module.css";
|
||||||
import RenderMarkdown from "./RenderMarkdown";
|
import RenderMarkdown from "./RenderMarkdown";
|
||||||
|
|
||||||
interface PageBodyProps {
|
interface PageBodyProps {
|
||||||
children: string;
|
children: string;
|
||||||
currentLanguage: string;
|
page: WikiPage;
|
||||||
path: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function PageBody(props: PageBodyProps) {
|
export default function PageBody(props: PageBodyProps) {
|
||||||
|
@ -12,12 +12,7 @@ export default function PageBody(props: PageBodyProps) {
|
||||||
<div className="prose prose-sm sm:prose lg:prose-lg xl:prose-xl">
|
<div className="prose prose-sm sm:prose lg:prose-lg xl:prose-xl">
|
||||||
<div className={mdStyles["markdown-body"]}>
|
<div className={mdStyles["markdown-body"]}>
|
||||||
<div className="text-left">
|
<div className="text-left">
|
||||||
<RenderMarkdown
|
<RenderMarkdown page={props.page}>{props.children}</RenderMarkdown>
|
||||||
path={props.path}
|
|
||||||
currentLanguage={props.currentLanguage}
|
|
||||||
>
|
|
||||||
{props.children}
|
|
||||||
</RenderMarkdown>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -4,14 +4,17 @@ import rehypeHighlight from "rehype-highlight";
|
||||||
import rehypeRaw from "rehype-raw";
|
import rehypeRaw from "rehype-raw";
|
||||||
import rehypeSlug from "rehype-slug";
|
import rehypeSlug from "rehype-slug";
|
||||||
import remarkGfm from "remark-gfm";
|
import remarkGfm from "remark-gfm";
|
||||||
|
import WikiPage from "../../interfaces/WikiPage";
|
||||||
|
|
||||||
interface RenderMarkdownProps {
|
interface RenderMarkdownProps {
|
||||||
children: string;
|
children: string;
|
||||||
path: string;
|
page: WikiPage;
|
||||||
currentLanguage: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function RenderMarkdown(pageprops: RenderMarkdownProps) {
|
export default function RenderMarkdown({
|
||||||
|
children,
|
||||||
|
page,
|
||||||
|
}: RenderMarkdownProps) {
|
||||||
return (
|
return (
|
||||||
<ReactMarkdown
|
<ReactMarkdown
|
||||||
remarkPlugins={[remarkGfm]}
|
remarkPlugins={[remarkGfm]}
|
||||||
|
@ -22,10 +25,10 @@ export default function RenderMarkdown(pageprops: RenderMarkdownProps) {
|
||||||
let href = props.href as string;
|
let href = props.href as string;
|
||||||
if (!href.endsWith("/") && !href.startsWith("http")) {
|
if (!href.endsWith("/") && !href.startsWith("http")) {
|
||||||
if (href.startsWith("/wiki/")) {
|
if (href.startsWith("/wiki/")) {
|
||||||
href = `/wiki/${pageprops.currentLanguage}${href.slice(5)}`;
|
href = `/wiki/${page.language}${href.slice(5)}`;
|
||||||
} else {
|
} else {
|
||||||
// if single relative
|
// if single relative
|
||||||
href = `/wiki/${pageprops.currentLanguage}/${pageprops.path}/${href}`;
|
href = `/wiki/${page.language}/${page.path}/${href}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
|
@ -38,7 +41,7 @@ export default function RenderMarkdown(pageprops: RenderMarkdownProps) {
|
||||||
// if image is internal (relative), prefix it with the current page's path
|
// if image is internal (relative), prefix it with the current page's path
|
||||||
let src = props.src as string;
|
let src = props.src as string;
|
||||||
if (!src.startsWith("http") && !src.startsWith("/")) {
|
if (!src.startsWith("http") && !src.startsWith("/")) {
|
||||||
src = `/img/wiki/${pageprops.path}/${src}`;
|
src = `/img/wiki/${page.path}/${src}`;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div className="flex w-full flex-col items-center justify-center">
|
<div className="flex w-full flex-col items-center justify-center">
|
||||||
|
@ -54,7 +57,7 @@ export default function RenderMarkdown(pageprops: RenderMarkdownProps) {
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{pageprops.children}
|
{children}
|
||||||
</ReactMarkdown>
|
</ReactMarkdown>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import Link from "next/link";
|
||||||
import { m } from "framer-motion";
|
import { m } from "framer-motion";
|
||||||
import PageBody from "../../../components/wiki/PageBody";
|
import PageBody from "../../../components/wiki/PageBody";
|
||||||
import { ReactElement, useEffect, useState } from "react";
|
import { ReactElement, useEffect, useState } from "react";
|
||||||
|
import Image from "next/image";
|
||||||
|
|
||||||
interface WikiLandingPageProps {
|
interface WikiLandingPageProps {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
|
@ -24,12 +25,8 @@ function WikiLandingPage(props: WikiLandingPageProps) {
|
||||||
|
|
||||||
// needed for proper hydration due to replacing some elements
|
// needed for proper hydration due to replacing some elements
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setWikiContent(
|
setWikiContent(<PageBody page={props.page}>{props.page.content}</PageBody>);
|
||||||
<PageBody currentLanguage={props.page.language} path={props.page.path}>
|
}, [props.page]);
|
||||||
{props.page.content}
|
|
||||||
</PageBody>
|
|
||||||
);
|
|
||||||
}, [props.page.content, props.page.language, props.page.path]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const toc: TableOfContentsItem[] = [];
|
const toc: TableOfContentsItem[] = [];
|
||||||
|
@ -46,9 +43,67 @@ function WikiLandingPage(props: WikiLandingPageProps) {
|
||||||
setIndexContent(toc);
|
setIndexContent(toc);
|
||||||
}, [wikiContent]);
|
}, [wikiContent]);
|
||||||
|
|
||||||
|
const dirPath = props.page.path.split("/").map((path, index) => {
|
||||||
|
// if home page, don't show
|
||||||
|
if (path === "home") return <></>;
|
||||||
|
return (
|
||||||
|
<div key={path} className="flex flex-row">
|
||||||
|
<span className="mx-2 flex items-center text-white">
|
||||||
|
<m.svg
|
||||||
|
viewBox={"0 0 24 24"}
|
||||||
|
width={20}
|
||||||
|
height={20}
|
||||||
|
origin="center"
|
||||||
|
color="currentColor"
|
||||||
|
fill="currentColor"
|
||||||
|
stroke="currentColor"
|
||||||
|
strokeWidth="2"
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
>
|
||||||
|
<m.path d="M6.23 20.23 8 22l10-10L8 2 6.23 3.77 14.46 12z" />
|
||||||
|
</m.svg>
|
||||||
|
</span>
|
||||||
|
<Link
|
||||||
|
href={`/wiki/${props.page.language}/${props.page.path
|
||||||
|
.split("/")
|
||||||
|
.slice(0, index + 1)
|
||||||
|
.join("/")}`}
|
||||||
|
>
|
||||||
|
<p className="hover:text-orange-400">{path}</p>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-full w-full flex-col items-center justify-center p-3 font-plusJakarta ">
|
<div className="flex w-full flex-col items-center justify-center p-3 font-plusJakarta ">
|
||||||
<div className="inline-grid h-full w-full max-w-screen-2xl grid-cols-10">
|
<div className="inline-grid h-full w-full max-w-screen-2xl grid-cols-10">
|
||||||
|
{/* Desktop Header */}
|
||||||
|
<div className="col-span-10 mb-2 hidden grid-cols-10 lg:inline-grid">
|
||||||
|
{/* Title */}
|
||||||
|
<div className="col-span-2 flex items-center justify-center">
|
||||||
|
<div className="text-2xl text-white">
|
||||||
|
<p>toffee wiki</p>
|
||||||
|
</div>
|
||||||
|
<Image
|
||||||
|
className="h-auto w-auto"
|
||||||
|
src="/img/logo.webp"
|
||||||
|
alt="toffee logo"
|
||||||
|
width={64}
|
||||||
|
height={64}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{/* Dir Path */}
|
||||||
|
<div className="col-span-8 ml-3 mb-3 mt-3 flex text-left text-xl">
|
||||||
|
<div className="flex w-auto flex-row items-center justify-start rounded-full bg-black p-2 px-4">
|
||||||
|
<Link href="/wiki">
|
||||||
|
<p className="hover:text-orange-400">home</p>
|
||||||
|
</Link>
|
||||||
|
{dirPath}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{/* Sidebar */}
|
{/* Sidebar */}
|
||||||
<div className="col-span-2 hidden w-full flex-col items-center justify-center lg:block">
|
<div className="col-span-2 hidden w-full flex-col items-center justify-center lg:block">
|
||||||
<div className="w-full rounded-tl-2xl rounded-bl-2xl border-r-2 border-orange-400 border-opacity-60 bg-zinc-800 bg-opacity-70 p-6 text-left text-6xl text-white">
|
<div className="w-full rounded-tl-2xl rounded-bl-2xl border-r-2 border-orange-400 border-opacity-60 bg-zinc-800 bg-opacity-70 p-6 text-left text-6xl text-white">
|
||||||
|
@ -75,11 +130,22 @@ function WikiLandingPage(props: WikiLandingPageProps) {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="col-span-10 mb-6 lg:hidden">
|
||||||
|
{/* Dir Path Mobile */}
|
||||||
|
<div className="col-span-8 flex text-left text-xl">
|
||||||
|
<div className="flex w-auto flex-row items-center justify-start rounded-full bg-black p-2 px-4">
|
||||||
|
<Link href="/wiki">
|
||||||
|
<p className="hover:text-orange-400">home</p>
|
||||||
|
</Link>
|
||||||
|
{dirPath}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{/* Mobile "Side"-bar */}
|
{/* Mobile "Side"-bar */}
|
||||||
<div className="col-span-10 mb-6 lg:hidden">
|
<div className="col-span-10 mb-6 lg:hidden">
|
||||||
<div className="w-full rounded-2xl rounded-tl-2xl bg-zinc-800 bg-opacity-70 p-6 text-left text-6xl text-white">
|
<div className="w-full rounded-2xl rounded-tl-2xl bg-zinc-800 bg-opacity-70 p-6 text-left text-6xl text-white">
|
||||||
<div
|
<div
|
||||||
className="flex cursor-pointer flex-row text-2xl"
|
className="flex cursor-pointer flex-row justify-between text-2xl"
|
||||||
onClick={() => setShowMobileIndex(!showMobileIndex)}
|
onClick={() => setShowMobileIndex(!showMobileIndex)}
|
||||||
>
|
>
|
||||||
<div>Contents</div>
|
<div>Contents</div>
|
||||||
|
@ -102,6 +168,7 @@ function WikiLandingPage(props: WikiLandingPageProps) {
|
||||||
/>
|
/>
|
||||||
</m.svg>
|
</m.svg>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<m.div
|
<m.div
|
||||||
className="overflow-hidden text-left text-orange-400"
|
className="overflow-hidden text-left text-orange-400"
|
||||||
animate={{
|
animate={{
|
||||||
|
@ -131,7 +198,7 @@ function WikiLandingPage(props: WikiLandingPageProps) {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/* Main content */}
|
{/* Main content */}
|
||||||
<div className="col-span-10 rounded-2xl bg-zinc-800 bg-opacity-70 p-6 text-center text-6xl text-white lg:col-span-8 lg:rounded-tl-none">
|
<div className="col-span-10 rounded-2xl bg-zinc-800 bg-opacity-70 px-6 pb-5 text-center text-6xl text-white lg:col-span-8 lg:rounded-tl-none">
|
||||||
<m.div
|
<m.div
|
||||||
initial={{ opacity: 0 }}
|
initial={{ opacity: 0 }}
|
||||||
animate={{ opacity: 1 }}
|
animate={{ opacity: 1 }}
|
||||||
|
|
Loading…
Add table
Reference in a new issue