XeNote/pages/index.js

56 lines
1.8 KiB
JavaScript
Raw Normal View History

import Layout from "../components/Layout";
2022-04-18 16:18:26 +00:00
import {
getSinglePost,
getDirectoryData,
convertObject,
getFlattenArray,
getLocalGraphData,
constructGraphData
} from "../lib/utils";
import FolderTree from "../components/FolderTree";
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
// 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 (
<Layout>
<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}/>
<DynamicGraph graph={graphData}/>
</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() {
const tree = convertObject(getDirectoryData());
2020-12-01 03:28:42 +00:00
const contentData = getSinglePost("index");
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)]
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,
tree: tree,
flattenNodes: flattenNodes,
graphData:graphData,
2022-04-18 16:18:26 +00:00
backLinks: backLinks
2020-11-28 15:45:01 +00:00
},
};
}