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 {
|
2022-04-17 13:04:58 +00:00
|
|
|
getAllSlugs,
|
2022-04-05 04:47:41 +00:00
|
|
|
getSinglePost,
|
|
|
|
convertObject,
|
|
|
|
getDirectoryData,
|
2022-04-18 04:48:36 +00:00
|
|
|
constructGraphData, getLocalGraphData
|
2022-04-05 04:47:41 +00:00
|
|
|
} from "../../lib/utils";
|
2022-03-24 07:43:18 +00:00
|
|
|
import FolderTree from "../../components/FolderTree";
|
|
|
|
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
|
|
|
import dynamic from 'next/dynamic'
|
|
|
|
|
|
|
|
const DynamicGraph = dynamic(
|
|
|
|
() => import('../../components/Graph'),
|
|
|
|
{ loading: () => <p>Loading ...</p>, ssr: false }
|
|
|
|
)
|
|
|
|
|
|
|
|
export default function Home({note, backLinks, fileNames, tree, flattenNodes, graphData}) {
|
2022-04-18 09:37:59 +00:00
|
|
|
|
2020-11-28 15:45:01 +00:00
|
|
|
return (
|
2022-03-31 08:46:10 +00:00
|
|
|
<Layout>
|
2020-11-30 11:29:34 +00:00
|
|
|
<Head>
|
2022-04-07 03:44:02 +00:00
|
|
|
{note.title && <meta name="title" content={note.title}/>}
|
2020-11-30 11:29:34 +00:00
|
|
|
</Head>
|
2022-04-07 03:44:02 +00:00
|
|
|
<div className='container'>
|
2022-03-24 07:43:18 +00:00
|
|
|
<nav className="nav-bar">
|
|
|
|
<FolderTree tree={tree} flattenNodes={flattenNodes}/>
|
|
|
|
</nav>
|
2022-04-07 03:44:02 +00:00
|
|
|
<MDContent content={note.data} fileNames={fileNames} handleOpenNewContent={null} backLinks={backLinks}/>
|
2022-04-18 09:47:02 +00:00
|
|
|
<DynamicGraph graph={graphData}/>
|
2022-03-24 07:43:18 +00:00
|
|
|
</div>
|
2022-04-15 04:00:45 +00:00
|
|
|
|
2020-11-28 15:45:01 +00:00
|
|
|
</Layout>
|
|
|
|
);
|
|
|
|
}
|
2022-04-07 03:44:02 +00:00
|
|
|
|
2020-11-28 15:45:01 +00:00
|
|
|
export async function getStaticPaths() {
|
2022-04-17 13:04:58 +00:00
|
|
|
const allPostsData = getAllSlugs();
|
2022-04-07 03:44:02 +00:00
|
|
|
const paths = allPostsData.map(p => ({params: {id: p}}))
|
2022-04-15 04:00:45 +00:00
|
|
|
|
2020-11-28 15:45:01 +00:00
|
|
|
return {
|
2022-04-07 03:44:02 +00:00
|
|
|
paths,
|
|
|
|
fallback: false
|
2020-11-28 15:45:01 +00:00
|
|
|
};
|
2022-04-07 03:44:02 +00:00
|
|
|
}
|
|
|
|
|
2022-04-18 04:48:36 +00:00
|
|
|
const {nodes, edges} = constructGraphData()
|
2022-04-07 09:52:41 +00:00
|
|
|
|
2022-04-07 03:44:02 +00:00
|
|
|
export function getStaticProps({params}) {
|
2022-03-31 08:12:00 +00:00
|
|
|
const note = getSinglePost(params.id);
|
2022-03-24 07:43:18 +00:00
|
|
|
const tree = convertObject(getDirectoryData());
|
|
|
|
const flattenNodes = getFlattenArray(tree)
|
2022-04-07 09:52:41 +00:00
|
|
|
|
|
|
|
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)
|
2022-04-18 05:02:05 +00:00
|
|
|
const backLinks = [...new Set(internalLinks)]
|
2022-04-18 04:48:36 +00:00
|
|
|
const graphData = getLocalGraphData(params.id)
|
2020-11-28 15:45:01 +00:00
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
note,
|
2022-03-24 07:43:18 +00:00
|
|
|
tree: tree,
|
2022-04-05 04:47:41 +00:00
|
|
|
flattenNodes: flattenNodes,
|
2022-04-18 05:02:05 +00:00
|
|
|
backLinks: backLinks.filter(link => link.slug !== params.id),
|
2022-04-15 04:00:45 +00:00
|
|
|
graphData: graphData
|
2020-11-28 15:45:01 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|