move construct graph function call to getStaticProps
This commit is contained in:
parent
fd45def1bf
commit
060815395a
@ -5,14 +5,14 @@ import {
|
|||||||
getSinglePost,
|
getSinglePost,
|
||||||
convertObject,
|
convertObject,
|
||||||
getDirectoryData,
|
getDirectoryData,
|
||||||
constructGraphData, getLocalGraphData
|
constructGraphData
|
||||||
} from "../../lib/utils";
|
} from "../../lib/utils";
|
||||||
import FolderTree from "../../components/FolderTree";
|
import FolderTree from "../../components/FolderTree";
|
||||||
import { getFlattenArray } from "../../lib/utils";
|
import { getFlattenArray } from "../../lib/utils";
|
||||||
import MDContent from "../../components/MDContent";
|
import MDContent from "../../components/MDContent";
|
||||||
|
|
||||||
|
|
||||||
export default function Home({ note, backLinks, fileNames, tree, flattenNodes, graphData }) {
|
export default function Home({ note, backLinks, fileNames, tree, flattenNodes }) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout>
|
<Layout>
|
||||||
@ -40,9 +40,9 @@ export async function getStaticPaths() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const { nodes, edges } = constructGraphData()
|
|
||||||
|
|
||||||
export function getStaticProps({ params }) {
|
export function getStaticProps({ params }) {
|
||||||
|
const { nodes, edges } = constructGraphData()
|
||||||
const note = getSinglePost(params.id);
|
const note = getSinglePost(params.id);
|
||||||
const tree = convertObject(getDirectoryData());
|
const tree = convertObject(getDirectoryData());
|
||||||
const flattenNodes = getFlattenArray(tree)
|
const flattenNodes = getFlattenArray(tree)
|
||||||
@ -50,14 +50,12 @@ export function getStaticProps({ params }) {
|
|||||||
const listOfEdges = edges.filter(anEdge => anEdge.target === 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)
|
const internalLinks = listOfEdges.map(anEdge => nodes.find(aNode => aNode.slug === anEdge.source)).filter(element => element !== undefined)
|
||||||
const backLinks = [...new Set(internalLinks)]
|
const backLinks = [...new Set(internalLinks)]
|
||||||
const graphData = getLocalGraphData(params.id)
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
note,
|
note,
|
||||||
tree: tree,
|
tree: tree,
|
||||||
flattenNodes: flattenNodes,
|
flattenNodes: flattenNodes,
|
||||||
backLinks: backLinks.filter(link => link.slug !== params.id),
|
backLinks: backLinks.filter(link => link.slug !== params.id),
|
||||||
graphData: graphData
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -26,9 +26,9 @@ export default function Home({ content, tree, flattenNodes, backLinks }) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const { nodes, edges } = constructGraphData()
|
|
||||||
|
|
||||||
export function getStaticProps() {
|
export function getStaticProps() {
|
||||||
|
const { nodes, edges } = constructGraphData()
|
||||||
const tree = convertObject(getDirectoryData());
|
const tree = convertObject(getDirectoryData());
|
||||||
const contentData = getSinglePost("index");
|
const contentData = getSinglePost("index");
|
||||||
const flattenNodes = getFlattenArray(tree)
|
const flattenNodes = getFlattenArray(tree)
|
||||||
|
Loading…
Reference in New Issue
Block a user