XeNote/pages/notes/index.js

41 lines
1.3 KiB
JavaScript
Raw Normal View History

import Layout from "../../components/Layout";
import Util from '../../lib/utils'
import FolderTree from "../../components/FolderTree";
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)
2023-12-24 06:13:29 +00:00
export default function Home({ content, tree, flattenNodes, backLinks }) {
2023-12-24 04:26:19 +00:00
return (
<Layout>
<div className='notes-container'>
2023-12-24 04:26:19 +00:00
<nav className="nav-bar">
<FolderTree tree={tree} flattenNodes={flattenNodes} />
</nav>
<MDContent content={content} handleOpenNewContent={null} backLinks={backLinks} />
</div>
</Layout>
);
2020-11-28 15:45:01 +00:00
}
2023-12-26 02:25:55 +00:00
2020-11-28 15:45:01 +00:00
export function getStaticProps() {
const { nodes, edges } = Util.constructGraphData()
const tree = Util.convertObject(Util.getDirectoryData());
const contentData = Util.getSinglePost("index");
const flattenNodes = Util.getFlattenArray(tree)
2023-12-24 04:26:19 +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 16:18:26 +00:00
2023-12-24 04:26:19 +00:00
return {
props: {
content: contentData.data,
tree: tree,
flattenNodes: flattenNodes,
backLinks: backLinks
},
};
2020-11-28 15:45:01 +00:00
}