XeNote/pages/notes/index.js

47 lines
1.4 KiB
JavaScript
Raw Normal View History

import Layout from "../../components/Layout";
2022-04-18 16:18:26 +00:00
import {
2023-12-24 04:26:19 +00:00
getSinglePost,
getDirectoryData,
convertObject,
getFlattenArray,
getLocalGraphData,
constructGraphData
} 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-24 04:26:19 +00:00
const { nodes, edges } = constructGraphData()
2020-11-28 15:45:01 +00:00
export function getStaticProps() {
2023-12-24 04:26:19 +00:00
const tree = convertObject(getDirectoryData());
const contentData = getSinglePost("index");
const flattenNodes = 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)]
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
}