XeNote/pages/index.js
Tuan Cao ce8de2da9f - fix bug: missing nodes in global graph
- fix bug: mismatch mapping node in index page (/)
- local graph now include both backlink and forward link
2022-04-18 11:48:36 +07:00

45 lines
1.3 KiB
JavaScript

import Layout from "../components/Layout";
import {getSinglePost, getDirectoryData, convertObject, getFlattenArray, getLocalGraphData} from "../lib/utils";
import FolderTree from "../components/FolderTree";
import MDContainer from "../components/MDContainer";
import dynamic from 'next/dynamic'
// 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 }
)
export default function Home({graphData, content, tree, flattenNodes}) {
return (
<Layout>
<div className = 'container'>
<nav className="nav-bar">
<FolderTree tree={tree} flattenNodes={flattenNodes}/>
</nav>
<MDContainer post={content.data}/>
<DynamicGraph graph={graphData}/>
</div>
</Layout>
);
}
export function getStaticProps() {
const tree = convertObject(getDirectoryData());
const contentData = getSinglePost("index");
const flattenNodes = getFlattenArray(tree)
const graphData = getLocalGraphData("index");
return {
props: {
content: contentData,
tree: tree,
flattenNodes: flattenNodes,
graphData:graphData,
},
};
}