XeNote/pages/notes/index.tsx

56 lines
1.5 KiB
TypeScript
Raw Normal View History

2023-12-31 15:35:22 +00:00
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
2023-12-31 15:35:22 +00:00
interface HomeProps {
content: string
tree: Record<string, unknown>
flattenNodes: unknown[]
backLinks: unknown[]
}
// This trick is to dynamically load component that interact with window object (browser only)
2023-12-31 15:35:22 +00:00
export default function Home({ content, tree, flattenNodes, backLinks }: HomeProps) {
2023-12-24 04:26:19 +00:00
return (
<Layout>
2023-12-31 20:29:30 +00:00
<div className='notes-container '>
2023-12-24 04:26:19 +00:00
<nav className="nav-bar">
<FolderTree tree={tree} flattenNodes={flattenNodes} />
</nav>
2023-12-30 16:49:39 +00:00
<MDContent content={content} backLinks={backLinks} />
2023-12-24 04:26:19 +00:00
</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() {
2023-12-31 15:35:22 +00:00
const { nodes, edges }: { nodes: unknown[], edges: unknown[] } = Util.constructGraphData()
const tree = Util.convertObject(Util.getDirectoryData());
const contentData = Util.getSinglePost("index");
const flattenNodes = Util.getFlattenArray(tree)
2023-12-31 15:35:22 +00:00
const listOfEdges = edges
.filter((anEdge) => (
anEdge as { target: string }).target === "index"
)
const internalLinks = listOfEdges.map(
anEdge => nodes
.find(
aNode => (
aNode as { slug: string }).slug === (anEdge as { source: string }).source))
.filter(
element => element !== undefined)
2023-12-24 04:26:19 +00:00
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
}