XeNote/pages/index.js

44 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-03-31 08:12:00 +00:00
import Layout from "../components/layout";
import {getSinglePost, getDirectoryData, convertObject, getFlattenArray, getGraphData} from "../lib/utils";
import FolderTree from "../components/FolderTree";
import MDContainer from "../components/MDContainer";
import dynamic from 'next/dynamic'
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 }
)
export default function Home({graphData, content, tree, flattenNodes}) {
2020-11-28 15:45:01 +00:00
return (
<Layout>
<div className = 'container'>
<nav className="nav-bar">
<FolderTree tree={tree} flattenNodes={flattenNodes}/>
</nav>
<MDContainer post={content.data}/>
</div>
<hr/>
<DynamicGraph graph={graphData}/>
2020-11-28 15:45:01 +00:00
</Layout>
);
}
export function getStaticProps() {
const tree = convertObject(getDirectoryData());
2020-12-01 03:28:42 +00:00
const contentData = getSinglePost("index");
const flattenNodes = getFlattenArray(tree)
const graphData = getGraphData();
2020-11-28 15:45:01 +00:00
return {
props: {
content: contentData,
tree: tree,
flattenNodes: flattenNodes,
graphData:graphData,
2020-11-28 15:45:01 +00:00
},
};
}