Triston Armstrong
fd51f273f4
- removes tailwind (was cool but dont need it) - reworks a lot of the html - utilize a no css... library? css file? idk - add a few details - rework the navigation on the built notes pages - write a bunch of tailwind like css classes - ... maybe some more, too lazy
68 lines
2.2 KiB
TypeScript
68 lines
2.2 KiB
TypeScript
import Head from "next/head";
|
|
import Layout from "components/Layout";
|
|
import Util from "lib/utils"
|
|
import FolderTree from "components/FolderTree";
|
|
import MDContent, { type LinkType } from "components/MDContent";
|
|
import type { GetStaticProps } from "next/types";
|
|
import type { ParsedUrlQuery } from "querystring";
|
|
|
|
interface HomeProps {
|
|
note: { title: string, data: string }
|
|
fileNames: string[]
|
|
content: string
|
|
tree: Record<string, unknown>
|
|
flattenNodes: unknown[]
|
|
backLinks: LinkType[]
|
|
}
|
|
|
|
export default function Home({ note, backLinks, fileNames: _, tree, flattenNodes }: HomeProps) {
|
|
|
|
return (
|
|
<Layout>
|
|
<Head>
|
|
{note.title && <meta name="title" content={note.title} />}
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/kimeiga/bahunya/dist/bahunya.min.css" />
|
|
<body style={{ margin: 0, padding: 0 }} /> </Head>
|
|
<div className='flex gap-1 w-full'>
|
|
<nav className="">
|
|
<FolderTree tree={tree} flattenNodes={flattenNodes} />
|
|
</nav>
|
|
|
|
<MDContent content={note.data} backLinks={backLinks} />
|
|
</div>
|
|
</Layout>
|
|
);
|
|
}
|
|
|
|
export async function getStaticPaths() {
|
|
const allPostsData = Util.getAllSlugs();
|
|
const paths = allPostsData.map(p => ({ params: { id: p } }))
|
|
|
|
return {
|
|
paths,
|
|
fallback: false
|
|
};
|
|
}
|
|
|
|
|
|
export const getStaticProps: GetStaticProps = (context) => {
|
|
const { nodes, edges }: { nodes: unknown[], edges: unknown[] } = Util.constructGraphData()
|
|
const { id } = context.params as ParsedUrlQuery & { id: string }
|
|
|
|
const note = Util.getSinglePost(id);
|
|
const tree = Util.convertObject(Util.getDirectoryData());
|
|
const flattenNodes = Util.getFlattenArray(tree)
|
|
|
|
const listOfEdges: unknown[] = edges.filter(anEdge => (anEdge as { target: string }).target === id)
|
|
const internalLinks: unknown[] = listOfEdges.map((anEdge) => nodes.find(aNode => (aNode as { slug: string }).slug === (anEdge as { source: string }).source)).filter(element => element !== undefined)
|
|
const backLinks = [...new Set(internalLinks)]
|
|
return {
|
|
props: {
|
|
note,
|
|
tree: tree,
|
|
flattenNodes: flattenNodes,
|
|
backLinks: backLinks.filter((link) => (link as { slug: string }).slug !== id),
|
|
},
|
|
};
|
|
}
|