41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import Layout from "../../components/Layout";
|
|
import Util from '../../lib/utils'
|
|
import FolderTree from "../../components/FolderTree";
|
|
import MDContent from "../../components/MDContent";
|
|
|
|
|
|
// This trick is to dynamically load component that interact with window object (browser only)
|
|
export default function Home({ content, tree, flattenNodes, backLinks }) {
|
|
return (
|
|
<Layout>
|
|
<div className='notes-container'>
|
|
<nav className="nav-bar">
|
|
<FolderTree tree={tree} flattenNodes={flattenNodes} />
|
|
</nav>
|
|
<MDContent content={content} handleOpenNewContent={null} backLinks={backLinks} />
|
|
</div>
|
|
</Layout>
|
|
);
|
|
|
|
}
|
|
|
|
|
|
export function getStaticProps() {
|
|
const { nodes, edges } = Util.constructGraphData()
|
|
const tree = Util.convertObject(Util.getDirectoryData());
|
|
const contentData = Util.getSinglePost("index");
|
|
const flattenNodes = Util.getFlattenArray(tree)
|
|
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)]
|
|
|
|
return {
|
|
props: {
|
|
content: contentData.data,
|
|
tree: tree,
|
|
flattenNodes: flattenNodes,
|
|
backLinks: backLinks
|
|
},
|
|
};
|
|
}
|