XeNote/pages/notes/[id].tsx

54 lines
1.6 KiB
TypeScript
Raw Normal View History

2020-11-28 15:45:01 +00:00
import Head from "next/head";
import Layout from "../../components/Layout";
import Util from "../../lib/utils"
import FolderTree from "../../components/FolderTree";
import MDContent from "../../components/MDContent";
export default function Home({ note, backLinks, fileNames, tree, flattenNodes }) {
2022-04-18 09:37:59 +00:00
2023-12-24 04:26:19 +00:00
return (
<Layout>
<Head>
{note.title && <meta name="title" content={note.title} />}
</Head>
2023-12-26 01:26:45 +00:00
<div className='notes-container'>
2023-12-24 04:26:19 +00:00
<nav className="nav-bar">
<FolderTree tree={tree} flattenNodes={flattenNodes} />
</nav>
<MDContent content={note.data} handleOpenNewContent={null} backLinks={backLinks} />
2023-12-24 04:26:19 +00:00
</div>
</Layout>
);
2020-11-28 15:45:01 +00:00
}
2020-11-28 15:45:01 +00:00
export async function getStaticPaths() {
const allPostsData = Util.getAllSlugs();
2023-12-24 04:26:19 +00:00
const paths = allPostsData.map(p => ({ params: { id: p } }))
2023-12-24 04:26:19 +00:00
return {
paths,
fallback: false
};
}
2023-12-24 04:26:19 +00:00
export function getStaticProps({ params }) {
const { nodes, edges } = Util.constructGraphData()
const note = Util.getSinglePost(params.id);
const tree = Util.convertObject(Util.getDirectoryData());
const flattenNodes = Util.getFlattenArray(tree)
2023-12-24 04:26:19 +00:00
const listOfEdges: unknown[] = edges.filter(anEdge => anEdge.target === params.id)
2023-12-30 16:42:21 +00:00
const internalLinks: unknown[] = listOfEdges.map((anEdge: { source: string }) => nodes.find(aNode => aNode.slug === anEdge.source)).filter(element => element !== undefined)
2023-12-24 04:26:19 +00:00
const backLinks = [...new Set(internalLinks)]
return {
props: {
note,
tree: tree,
flattenNodes: flattenNodes,
2023-12-30 16:42:21 +00:00
backLinks: backLinks.filter((link: { slug: string }) => link.slug !== params.id),
2023-12-24 04:26:19 +00:00
},
};
2020-11-28 15:45:01 +00:00
}