XeNote/pages/index.js

50 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-11-28 15:45:01 +00:00
import Head from "next/head";
2020-11-30 11:29:34 +00:00
import { useRouter } from 'next/router'
2020-11-28 15:45:01 +00:00
import { useEffect,useRef } from "react";
import Layout, { siteTitle } from "../components/layout";
2020-11-30 11:29:34 +00:00
import { getSinglePost, getGraphData } from "../lib/post";
import { Network } from "../components/graph";
2020-11-28 15:45:01 +00:00
2020-11-30 11:29:34 +00:00
export default function Home({ content, graphdata, filenames, ...props }) {
2020-12-01 20:30:06 +00:00
//console.log("Index Page Props: ", content /* backlinks, filenames*/)
2020-11-28 15:45:01 +00:00
const ref = useRef(null);
2020-11-30 11:29:34 +00:00
const router = useRouter()
2020-12-06 19:40:20 +00:00
const routeQuery = router.query.id
const routeHandler = (r) => router.push(r)
2020-11-28 15:45:01 +00:00
useEffect(() => {
2020-11-30 11:29:34 +00:00
if (ref && ref.current){
2020-11-28 15:45:01 +00:00
2020-12-01 20:30:06 +00:00
const G = Network({
el:ref.current,
graphdata,
current:"index",
2020-12-06 19:40:20 +00:00
routeQuery,
routeHandler,
2020-12-01 20:30:06 +00:00
allNodes:false // If true then shows every markdown file as node
})
2020-11-30 11:29:34 +00:00
}
}, [])
2020-12-01 03:28:42 +00:00
2020-11-28 15:45:01 +00:00
return (
<Layout home>
2020-11-30 11:29:34 +00:00
<section>
<div dangerouslySetInnerHTML={{__html: content.data}} />
2020-11-28 15:45:01 +00:00
</section>
</Layout>
);
}
export function getStaticProps() {
2020-12-01 03:28:42 +00:00
const contentData = getSinglePost("index");
2020-11-30 11:29:34 +00:00
const graphdata = getGraphData();
2020-11-28 15:45:01 +00:00
return {
props: {
content:contentData,
2020-11-30 11:29:34 +00:00
graphdata:graphdata,
2020-11-28 15:45:01 +00:00
},
};
}