2020-11-28 15:45:01 +00:00
|
|
|
import Head from "next/head";
|
2022-04-18 02:09:58 +00:00
|
|
|
import Layout from "../../components/Layout";
|
2022-04-05 04:47:41 +00:00
|
|
|
import {
|
2023-12-24 04:26:19 +00:00
|
|
|
getAllSlugs,
|
|
|
|
getSinglePost,
|
|
|
|
convertObject,
|
|
|
|
getDirectoryData,
|
2023-12-26 04:04:02 +00:00
|
|
|
constructGraphData
|
2022-04-05 04:47:41 +00:00
|
|
|
} from "../../lib/utils";
|
2022-03-24 07:43:18 +00:00
|
|
|
import FolderTree from "../../components/FolderTree";
|
2023-12-24 04:26:19 +00:00
|
|
|
import { getFlattenArray } from "../../lib/utils";
|
2022-04-07 03:44:02 +00:00
|
|
|
import MDContent from "../../components/MDContent";
|
2022-04-15 04:00:45 +00:00
|
|
|
|
|
|
|
|
2023-12-26 04:04:02 +00:00
|
|
|
export default function Home({ note, backLinks, fileNames, tree, flattenNodes }) {
|
2022-04-18 09:37:59 +00:00
|
|
|
|
2023-12-24 04:26:19 +00:00
|
|
|
return (
|
|
|
|
<Layout>
|
|
|
|
<Head>
|
|
|
|
{note.title && <meta name="title" content={note.title} />}
|
|
|
|
</Head>
|
2023-12-26 01:26:45 +00:00
|
|
|
<div className='notes-container'>
|
2023-12-24 04:26:19 +00:00
|
|
|
<nav className="nav-bar">
|
|
|
|
<FolderTree tree={tree} flattenNodes={flattenNodes} />
|
|
|
|
</nav>
|
|
|
|
<MDContent content={note.data} fileNames={fileNames} handleOpenNewContent={null} backLinks={backLinks} />
|
|
|
|
</div>
|
2022-04-15 04:00:45 +00:00
|
|
|
|
2023-12-24 04:26:19 +00:00
|
|
|
</Layout>
|
|
|
|
);
|
2020-11-28 15:45:01 +00:00
|
|
|
}
|
2022-04-07 03:44:02 +00:00
|
|
|
|
2020-11-28 15:45:01 +00:00
|
|
|
export async function getStaticPaths() {
|
2023-12-24 04:26:19 +00:00
|
|
|
const allPostsData = getAllSlugs();
|
|
|
|
const paths = allPostsData.map(p => ({ params: { id: p } }))
|
2022-04-15 04:00:45 +00:00
|
|
|
|
2023-12-24 04:26:19 +00:00
|
|
|
return {
|
|
|
|
paths,
|
|
|
|
fallback: false
|
|
|
|
};
|
2022-04-07 03:44:02 +00:00
|
|
|
}
|
|
|
|
|
2023-12-24 04:26:19 +00:00
|
|
|
|
|
|
|
export function getStaticProps({ params }) {
|
2023-12-26 04:04:02 +00:00
|
|
|
const { nodes, edges } = constructGraphData()
|
2023-12-24 04:26:19 +00:00
|
|
|
const note = getSinglePost(params.id);
|
|
|
|
const tree = convertObject(getDirectoryData());
|
|
|
|
const flattenNodes = getFlattenArray(tree)
|
|
|
|
|
|
|
|
const listOfEdges = edges.filter(anEdge => anEdge.target === params.id)
|
|
|
|
const internalLinks = listOfEdges.map(anEdge => nodes.find(aNode => aNode.slug === anEdge.source)).filter(element => element !== undefined)
|
|
|
|
const backLinks = [...new Set(internalLinks)]
|
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
note,
|
|
|
|
tree: tree,
|
|
|
|
flattenNodes: flattenNodes,
|
|
|
|
backLinks: backLinks.filter(link => link.slug !== params.id),
|
|
|
|
},
|
|
|
|
};
|
2020-11-28 15:45:01 +00:00
|
|
|
}
|