2024-01-07 18:05:04 +00:00
|
|
|
import Head from 'next/head'
|
|
|
|
import Layout from 'components/Layout'
|
|
|
|
import Util from 'lib/utils'
|
|
|
|
import FolderTree from 'components/FolderTree'
|
|
|
|
import MDContent, { type LinkType } from 'components/MDContent'
|
|
|
|
import type { GetStaticProps } from 'next/types'
|
|
|
|
import type { ParsedUrlQuery } from 'querystring'
|
2022-04-15 04:00:45 +00:00
|
|
|
|
2023-12-31 16:57:12 +00:00
|
|
|
interface HomeProps {
|
|
|
|
note: { title: string, data: string }
|
|
|
|
fileNames: string[]
|
|
|
|
content: string
|
|
|
|
tree: Record<string, unknown>
|
|
|
|
flattenNodes: unknown[]
|
2023-12-31 21:15:25 +00:00
|
|
|
backLinks: LinkType[]
|
2023-12-31 16:57:12 +00:00
|
|
|
}
|
2022-04-15 04:00:45 +00:00
|
|
|
|
2023-12-31 16:57:12 +00:00
|
|
|
export default function Home({ note, backLinks, fileNames: _, tree, flattenNodes }: HomeProps) {
|
2023-12-24 04:26:19 +00:00
|
|
|
return (
|
|
|
|
<Layout>
|
2024-01-07 19:56:19 +00:00
|
|
|
{/*
|
2023-12-24 04:26:19 +00:00
|
|
|
<Head>
|
|
|
|
{note.title && <meta name="title" content={note.title} />}
|
2024-01-07 04:12:23 +00:00
|
|
|
<body style={{ margin: 0, padding: 0 }} />
|
|
|
|
</Head>
|
2024-01-07 19:56:19 +00:00
|
|
|
*/}
|
2024-01-07 03:04:57 +00:00
|
|
|
<div className='flex gap-1 w-full'>
|
|
|
|
<nav className="">
|
2023-12-24 04:26:19 +00:00
|
|
|
<FolderTree tree={tree} flattenNodes={flattenNodes} />
|
|
|
|
</nav>
|
2024-01-07 03:04:57 +00:00
|
|
|
|
2023-12-31 16:57:12 +00:00
|
|
|
<MDContent content={note.data} backLinks={backLinks} />
|
2023-12-24 04:26:19 +00:00
|
|
|
</div>
|
|
|
|
</Layout>
|
2024-01-07 18:05:04 +00:00
|
|
|
)
|
2020-11-28 15:45:01 +00:00
|
|
|
}
|
2022-04-07 03:44:02 +00:00
|
|
|
|
2020-11-28 15:45:01 +00:00
|
|
|
export async function getStaticPaths() {
|
2024-01-07 18:05:04 +00:00
|
|
|
const allPostsData = Util.getAllSlugs()
|
2023-12-24 04:26:19 +00:00
|
|
|
const paths = allPostsData.map(p => ({ params: { id: p } }))
|
2022-04-15 04:00:45 +00:00
|
|
|
|
2023-12-24 04:26:19 +00:00
|
|
|
return {
|
|
|
|
paths,
|
|
|
|
fallback: false
|
2024-01-07 18:05:04 +00:00
|
|
|
}
|
2022-04-07 03:44:02 +00:00
|
|
|
}
|
|
|
|
|
2023-12-31 16:57:12 +00:00
|
|
|
export const getStaticProps: GetStaticProps = (context) => {
|
|
|
|
const { nodes, edges }: { nodes: unknown[], edges: unknown[] } = Util.constructGraphData()
|
|
|
|
const { id } = context.params as ParsedUrlQuery & { id: string }
|
|
|
|
|
2024-01-07 18:05:04 +00:00
|
|
|
const note = Util.getSinglePost(id)
|
|
|
|
const tree = Util.convertObject(Util.getDirectoryData())
|
2023-12-27 05:36:36 +00:00
|
|
|
const flattenNodes = Util.getFlattenArray(tree)
|
2023-12-24 04:26:19 +00:00
|
|
|
|
2023-12-31 16:57:12 +00:00
|
|
|
const listOfEdges: unknown[] = edges.filter(anEdge => (anEdge as { target: string }).target === id)
|
|
|
|
const internalLinks: unknown[] = 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)]
|
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
note,
|
2024-01-07 18:05:04 +00:00
|
|
|
tree,
|
|
|
|
flattenNodes,
|
|
|
|
backLinks: backLinks.filter((link) => (link as { slug: string }).slug !== id)
|
|
|
|
}
|
|
|
|
}
|
2020-11-28 15:45:01 +00:00
|
|
|
}
|