2023-12-31 15:35:22 +00:00
|
|
|
import Layout from "components/Layout";
|
|
|
|
import Util from 'lib/utils'
|
|
|
|
import FolderTree from "components/FolderTree";
|
2023-12-31 21:25:23 +00:00
|
|
|
import MDContent, { type LinkType } from "components/MDContent";
|
2020-12-01 03:28:42 +00:00
|
|
|
|
|
|
|
|
2023-12-31 21:25:23 +00:00
|
|
|
export interface HomeProps {
|
2023-12-31 15:35:22 +00:00
|
|
|
content: string
|
|
|
|
tree: Record<string, unknown>
|
|
|
|
flattenNodes: unknown[]
|
2023-12-31 21:25:23 +00:00
|
|
|
backLinks: LinkType[]
|
2023-12-31 15:35:22 +00:00
|
|
|
}
|
2022-04-15 02:04:28 +00:00
|
|
|
// 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()
|
2023-12-27 05:36:36 +00:00
|
|
|
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
|
|
|
}
|