2022-04-18 02:09:58 +00:00
|
|
|
import Layout from "../components/Layout";
|
2022-04-18 16:18:26 +00:00
|
|
|
import {
|
|
|
|
getSinglePost,
|
|
|
|
getDirectoryData,
|
|
|
|
convertObject,
|
|
|
|
getFlattenArray,
|
|
|
|
getLocalGraphData,
|
|
|
|
constructGraphData
|
|
|
|
} from "../lib/utils";
|
2022-03-23 15:25:39 +00:00
|
|
|
import FolderTree from "../components/FolderTree";
|
2022-04-15 02:04:28 +00:00
|
|
|
import dynamic from 'next/dynamic'
|
2022-04-18 16:18:26 +00:00
|
|
|
import MDContent from "../components/MDContent";
|
2020-12-01 03:28:42 +00:00
|
|
|
|
|
|
|
|
2022-04-15 02:04:28 +00:00
|
|
|
// This trick is to dynamically load component that interact with window object (browser only)
|
|
|
|
const DynamicGraph = dynamic(
|
|
|
|
() => import('../components/Graph'),
|
|
|
|
{ loading: () => <p>Loading ...</p>, ssr: false }
|
|
|
|
)
|
|
|
|
|
2022-04-18 16:18:26 +00:00
|
|
|
export default function Home({graphData, content, tree, flattenNodes, backLinks}) {
|
2020-11-28 15:45:01 +00:00
|
|
|
return (
|
2022-03-31 08:46:10 +00:00
|
|
|
<Layout>
|
2022-03-24 07:43:18 +00:00
|
|
|
<div className = 'container'>
|
|
|
|
<nav className="nav-bar">
|
|
|
|
<FolderTree tree={tree} flattenNodes={flattenNodes}/>
|
|
|
|
</nav>
|
2022-04-18 16:18:26 +00:00
|
|
|
<MDContent content={content} handleOpenNewContent={null} backLinks={backLinks}/>
|
2022-04-15 04:00:45 +00:00
|
|
|
<DynamicGraph graph={graphData}/>
|
2022-03-24 07:43:18 +00:00
|
|
|
</div>
|
2020-11-28 15:45:01 +00:00
|
|
|
</Layout>
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
2022-04-18 16:18:26 +00:00
|
|
|
const {nodes, edges} = constructGraphData()
|
2020-11-28 15:45:01 +00:00
|
|
|
|
|
|
|
export function getStaticProps() {
|
2022-03-23 15:25:39 +00:00
|
|
|
const tree = convertObject(getDirectoryData());
|
2020-12-01 03:28:42 +00:00
|
|
|
const contentData = getSinglePost("index");
|
2022-03-24 04:15:43 +00:00
|
|
|
const flattenNodes = getFlattenArray(tree)
|
2022-04-18 16:18:26 +00:00
|
|
|
const listOfEdges = edges.filter(anEdge => anEdge.target === "index")
|
|
|
|
const internalLinks = listOfEdges.map(anEdge => nodes.find(aNode => aNode.slug === anEdge.source)).filter(element => element !== undefined)
|
|
|
|
const backLinks = [...new Set(internalLinks)]
|
|
|
|
|
2022-04-18 04:48:36 +00:00
|
|
|
const graphData = getLocalGraphData("index");
|
2020-11-28 15:45:01 +00:00
|
|
|
return {
|
|
|
|
props: {
|
2022-04-18 16:18:26 +00:00
|
|
|
content: contentData.data,
|
2022-03-24 04:15:43 +00:00
|
|
|
tree: tree,
|
2022-04-15 02:04:28 +00:00
|
|
|
flattenNodes: flattenNodes,
|
|
|
|
graphData:graphData,
|
2022-04-18 16:18:26 +00:00
|
|
|
backLinks: backLinks
|
2020-11-28 15:45:01 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|