Fixed layout on home page.

This commit is contained in:
Tuan Cao 2022-04-18 23:18:26 +07:00
parent 96d4e9e7e7
commit d8806d6771
2 changed files with 20 additions and 9 deletions

View File

@ -1,8 +1,15 @@
import Layout from "../components/Layout"; import Layout from "../components/Layout";
import {getSinglePost, getDirectoryData, convertObject, getFlattenArray, getLocalGraphData} from "../lib/utils"; import {
getSinglePost,
getDirectoryData,
convertObject,
getFlattenArray,
getLocalGraphData,
constructGraphData
} from "../lib/utils";
import FolderTree from "../components/FolderTree"; import FolderTree from "../components/FolderTree";
import MDContainer from "../components/MDContainer";
import dynamic from 'next/dynamic' import dynamic from 'next/dynamic'
import MDContent from "../components/MDContent";
// This trick is to dynamically load component that interact with window object (browser only) // This trick is to dynamically load component that interact with window object (browser only)
@ -11,34 +18,38 @@ const DynamicGraph = dynamic(
{ loading: () => <p>Loading ...</p>, ssr: false } { loading: () => <p>Loading ...</p>, ssr: false }
) )
export default function Home({graphData, content, tree, flattenNodes}) { export default function Home({graphData, content, tree, flattenNodes, backLinks}) {
return ( return (
<Layout> <Layout>
<div className = 'container'> <div className = 'container'>
<nav className="nav-bar"> <nav className="nav-bar">
<FolderTree tree={tree} flattenNodes={flattenNodes}/> <FolderTree tree={tree} flattenNodes={flattenNodes}/>
</nav> </nav>
<MDContainer post={content.data}/> <MDContent content={content} handleOpenNewContent={null} backLinks={backLinks}/>
<DynamicGraph graph={graphData}/> <DynamicGraph graph={graphData}/>
</div> </div>
</Layout> </Layout>
); );
} }
const {nodes, edges} = constructGraphData()
export function getStaticProps() { export function getStaticProps() {
const tree = convertObject(getDirectoryData()); const tree = convertObject(getDirectoryData());
const contentData = getSinglePost("index"); const contentData = getSinglePost("index");
const flattenNodes = getFlattenArray(tree) const flattenNodes = getFlattenArray(tree)
const listOfEdges = edges.filter(anEdge => anEdge.target === "index")
const internalLinks = listOfEdges.map(anEdge => nodes.find(aNode => aNode.slug === anEdge.source)).filter(element => element !== undefined)
const backLinks = [...new Set(internalLinks)]
const graphData = getLocalGraphData("index"); const graphData = getLocalGraphData("index");
return { return {
props: { props: {
content: contentData, content: contentData.data,
tree: tree, tree: tree,
flattenNodes: flattenNodes, flattenNodes: flattenNodes,
graphData:graphData, graphData:graphData,
backLinks: backLinks
}, },
}; };
} }

View File

@ -87,7 +87,7 @@ a:hover {
background-color: var(--background-primary); background-color: var(--background-primary);
color: var(--text-normal); color: var(--text-normal);
font-family:var(--default-font); font-family:var(--default-font);
padding: 20px; padding: 15px 30px;
} }
.nav-bar { .nav-bar {
@ -184,7 +184,7 @@ a:hover {
display: block; display: block;
} }
@media screen and (max-width: 1100px) { @media screen and (max-width: 1400px) {
.right-bar-container { .right-bar-container {
display: none; display: none;
} }