2020-11-28 15:45:01 +00:00
|
|
|
import Head from "next/head";
|
|
|
|
import Link from 'next/link'
|
2020-11-30 11:29:34 +00:00
|
|
|
import { useRouter } from 'next/router'
|
|
|
|
import { useEffect,useRef } from "react";
|
2020-11-28 15:45:01 +00:00
|
|
|
import Layout, { siteTitle } from "../../components/layout";
|
2022-03-24 07:43:18 +00:00
|
|
|
import {getPostListData, getSinglePost, getGraphData, convertObject, getDirectoryData} from "../../lib/utils";
|
2020-11-30 11:29:34 +00:00
|
|
|
import { Network } from "../../components/graph";
|
2022-03-24 07:43:18 +00:00
|
|
|
import FolderTree from "../../components/FolderTree";
|
|
|
|
import {getFlattenArray} from "../../lib/utils";
|
2022-03-25 08:18:36 +00:00
|
|
|
import Alert from '@mui/material/Alert';
|
|
|
|
import AlertTitle from '@mui/material/AlertTitle';
|
2020-11-30 11:29:34 +00:00
|
|
|
|
2022-03-24 07:43:18 +00:00
|
|
|
export default function Home({ note, graphdata,tree, flattenNodes, ...props }) {
|
2020-11-30 11:29:34 +00:00
|
|
|
var jsnx = require('jsnetworkx');
|
|
|
|
|
|
|
|
//console.log("Note Page: ")
|
|
|
|
//console.log("Index Page Props: ", props /* backlinks, filenames*/)
|
|
|
|
|
|
|
|
const backlinks = graphdata.filter(g => g.data.target === note.id)
|
|
|
|
|
|
|
|
const ref = useRef(null);
|
|
|
|
const router = useRouter()
|
2020-12-06 19:40:20 +00:00
|
|
|
const routeQuery = router.query.id
|
|
|
|
const routeHandler = (r) => router.push(r)
|
|
|
|
//console.log("route", router)
|
|
|
|
|
2020-11-30 11:29:34 +00:00
|
|
|
var G;
|
|
|
|
useEffect(() => {
|
|
|
|
if (ref && ref.current){
|
2020-12-06 19:40:20 +00:00
|
|
|
G = Network({
|
|
|
|
el:ref.current,
|
|
|
|
graphdata,
|
|
|
|
current:note.id,
|
|
|
|
routeHandler,
|
|
|
|
allNodes:false
|
|
|
|
})
|
2020-11-30 11:29:34 +00:00
|
|
|
}
|
2020-12-06 19:40:20 +00:00
|
|
|
}, [routeQuery])
|
2020-11-30 11:29:34 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (backlinks.length > 0){
|
|
|
|
const sideBox = document.getElementById("side-graph-box");
|
|
|
|
const Backlink = (data) => (
|
|
|
|
<div className="backlink-box">
|
|
|
|
<Link href={data.id === "index" ? "/" : `/note/${data.id}`}>
|
|
|
|
<a>
|
|
|
|
{data.title ? data.title : data.id}
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
|
|
|
|
//sideBox
|
|
|
|
}
|
|
|
|
},[])
|
|
|
|
|
2020-11-28 15:45:01 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Layout home>
|
2020-11-30 11:29:34 +00:00
|
|
|
<Head>
|
|
|
|
{note.title && <meta name="title" content={note.title} />}
|
|
|
|
</Head>
|
2022-03-24 07:43:18 +00:00
|
|
|
<div className = 'container'>
|
|
|
|
<nav className="nav-bar">
|
|
|
|
<FolderTree tree={tree} flattenNodes={flattenNodes}/>
|
|
|
|
</nav>
|
2022-03-25 08:18:36 +00:00
|
|
|
<main className="markdown-rendered">
|
|
|
|
<Alert severity="info">
|
|
|
|
<AlertTitle>Want to know more?</AlertTitle>
|
|
|
|
🌱 <strong>Follow</strong> or <strong>DM</strong> me on Twitter at <span><a href="https://twitter.com/tuancm">@tuancm</a></span>
|
|
|
|
</Alert>
|
|
|
|
<div dangerouslySetInnerHTML={{__html: note.data}}/>
|
|
|
|
</main>
|
2022-03-24 07:43:18 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
2020-11-30 11:29:34 +00:00
|
|
|
|
2020-11-28 15:45:01 +00:00
|
|
|
</Layout>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
export async function getStaticPaths() {
|
|
|
|
const allPostsData = await getPostListData();
|
2020-12-01 03:28:42 +00:00
|
|
|
const paths = allPostsData.map(p => ({params: {id:p}}))
|
2020-11-30 11:29:34 +00:00
|
|
|
//console.log("paths", paths)
|
2020-11-28 15:45:01 +00:00
|
|
|
return {
|
|
|
|
paths,
|
|
|
|
fallback:false
|
|
|
|
};
|
|
|
|
}
|
|
|
|
export async function getStaticProps({ params }) {
|
2020-12-06 19:40:20 +00:00
|
|
|
console.log("params1", params.id)
|
2020-11-28 15:45:01 +00:00
|
|
|
const note = await getSinglePost(params.id);
|
2020-12-06 19:40:20 +00:00
|
|
|
//console.log("params2", note)
|
2020-11-30 11:29:34 +00:00
|
|
|
const graphdata = getGraphData();
|
2020-12-01 03:28:42 +00:00
|
|
|
//console.log("params3", params)
|
2022-03-24 07:43:18 +00:00
|
|
|
const tree = convertObject(getDirectoryData());
|
|
|
|
const flattenNodes = getFlattenArray(tree)
|
2020-11-30 11:29:34 +00:00
|
|
|
//console.log("note: ", params)
|
2020-11-28 15:45:01 +00:00
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
note,
|
2022-03-24 07:43:18 +00:00
|
|
|
graphdata:graphdata,
|
|
|
|
tree: tree,
|
|
|
|
flattenNodes: flattenNodes
|
2020-11-28 15:45:01 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|