XeNote/pages/note/[id].js

61 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-11-28 15:45:01 +00:00
import Head from "next/head";
2022-03-31 08:12:00 +00:00
import Layout from "../../components/layout";
import {
getContentPaths,
getSinglePost,
convertObject,
getDirectoryData,
constructBackLinks, getFileNames
} from "../../lib/utils";
import FolderTree from "../../components/FolderTree";
import {getFlattenArray} from "../../lib/utils";
import MDContent from "../../components/MDContent";
2020-11-30 11:29:34 +00:00
export default function Home({note, backLinks, fileNames, tree, flattenNodes}) {
2020-11-28 15:45:01 +00:00
return (
<Layout>
2020-11-30 11:29:34 +00:00
<Head>
{note.title && <meta name="title" content={note.title}/>}
2020-11-30 11:29:34 +00:00
</Head>
<div className='container'>
<nav className="nav-bar">
<FolderTree tree={tree} flattenNodes={flattenNodes}/>
</nav>
<MDContent content={note.data} fileNames={fileNames} handleOpenNewContent={null} backLinks={backLinks}/>
</div>
2020-11-28 15:45:01 +00:00
</Layout>
);
}
2020-11-28 15:45:01 +00:00
export async function getStaticPaths() {
const allPostsData = getContentPaths();
const paths = allPostsData.map(p => ({params: {id: p}}))
2020-11-28 15:45:01 +00:00
return {
paths,
fallback: false
2020-11-28 15:45:01 +00:00
};
}
const {nodes, edges} = constructBackLinks()
export function getStaticProps({params}) {
2022-03-31 08:12:00 +00:00
const note = getSinglePost(params.id);
const tree = convertObject(getDirectoryData());
const flattenNodes = getFlattenArray(tree)
// const fileNames = getAllFileNames()
const { fileNames} = getFileNames(params.id)
const listOfEdges = edges.filter(anEdge => anEdge.target === params.id)
const internalLinks = listOfEdges.map(anEdge => nodes.find(aNode => aNode.slug === anEdge.source)).filter(element => element !== undefined)
2020-11-28 15:45:01 +00:00
return {
props: {
note,
tree: tree,
flattenNodes: flattenNodes,
fileNames: fileNames,
backLinks: internalLinks
2020-11-28 15:45:01 +00:00
},
};
}