fix bug preventing home notes from rendering
This commit is contained in:
parent
7fc90d80b5
commit
4e26072046
@ -1,7 +1,5 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { TreeView, TreeItem } from '@mui/x-tree-view';
|
import { TreeView, TreeItem } from '@mui/x-tree-view';
|
||||||
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
|
||||||
import ChevronRightIcon from '@mui/icons-material/ChevronRight';
|
|
||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import { styled } from '@mui/material/styles';
|
import { styled } from '@mui/material/styles';
|
||||||
import { Divider } from '@mui/material';
|
import { Divider } from '@mui/material';
|
||||||
@ -36,7 +34,7 @@ export default function FolderTree(props) {
|
|||||||
<Divider />
|
<Divider />
|
||||||
<TreeView
|
<TreeView
|
||||||
aria-label="rich object"
|
aria-label="rich object"
|
||||||
defaultCollapseIcon={<ExpandMoreIcon />}
|
defaultCollapseIcon={<ChevronDownIcon />}
|
||||||
defaultExpanded={expandedNodes}
|
defaultExpanded={expandedNodes}
|
||||||
defaultExpandIcon={<ChevronRightIcon />}
|
defaultExpandIcon={<ChevronRightIcon />}
|
||||||
onNodeSelect={(event, nodIds) => {
|
onNodeSelect={(event, nodIds) => {
|
||||||
@ -54,3 +52,20 @@ export default function FolderTree(props) {
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ChevronRightIcon() {
|
||||||
|
return (
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" className="w-6 h-6">
|
||||||
|
<path strokeLinecap="round" strokeLinejoin="round" d="m8.25 4.5 7.5 7.5-7.5 7.5" />
|
||||||
|
</svg>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function ChevronDownIcon() {
|
||||||
|
return (
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" className="w-6 h-6">
|
||||||
|
<path strokeLinecap="round" strokeLinejoin="round" d="m19.5 8.25-7.5 7.5-7.5-7.5" />
|
||||||
|
</svg>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
"@emotion/styled": "latest",
|
"@emotion/styled": "latest",
|
||||||
"@headlessui/react": "^1.7.17",
|
"@headlessui/react": "^1.7.17",
|
||||||
"@heroicons/react": "^2.1.1",
|
"@heroicons/react": "^2.1.1",
|
||||||
"@mui/icons-material": "latest",
|
|
||||||
"@mui/lab": "latest",
|
"@mui/lab": "latest",
|
||||||
"@mui/material": "latest",
|
"@mui/material": "latest",
|
||||||
"@mui/x-tree-view": "^6.17.0",
|
"@mui/x-tree-view": "^6.17.0",
|
||||||
|
@ -3,9 +3,19 @@ import Layout from "../../components/Layout";
|
|||||||
import Util from "../../lib/utils"
|
import Util from "../../lib/utils"
|
||||||
import FolderTree from "../../components/FolderTree";
|
import FolderTree from "../../components/FolderTree";
|
||||||
import MDContent from "../../components/MDContent";
|
import MDContent from "../../components/MDContent";
|
||||||
|
import type { GetStaticProps } from "next/types";
|
||||||
|
import type { ParsedUrlQuery } from "querystring";
|
||||||
|
|
||||||
|
interface HomeProps {
|
||||||
|
note: { title: string, data: string }
|
||||||
|
fileNames: string[]
|
||||||
|
content: string
|
||||||
|
tree: Record<string, unknown>
|
||||||
|
flattenNodes: unknown[]
|
||||||
|
backLinks: unknown[]
|
||||||
|
}
|
||||||
|
|
||||||
export default function Home({ note, backLinks, fileNames, tree, flattenNodes }) {
|
export default function Home({ note, backLinks, fileNames: _, tree, flattenNodes }: HomeProps) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout>
|
<Layout>
|
||||||
@ -16,7 +26,7 @@ export default function Home({ note, backLinks, fileNames, tree, flattenNodes })
|
|||||||
<nav className="nav-bar">
|
<nav className="nav-bar">
|
||||||
<FolderTree tree={tree} flattenNodes={flattenNodes} />
|
<FolderTree tree={tree} flattenNodes={flattenNodes} />
|
||||||
</nav>
|
</nav>
|
||||||
<MDContent content={note.data} handleOpenNewContent={null} backLinks={backLinks} />
|
<MDContent content={note.data} backLinks={backLinks} />
|
||||||
</div>
|
</div>
|
||||||
</Layout>
|
</Layout>
|
||||||
);
|
);
|
||||||
@ -33,21 +43,23 @@ export async function getStaticPaths() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function getStaticProps({ params }) {
|
export const getStaticProps: GetStaticProps = (context) => {
|
||||||
const { nodes, edges } = Util.constructGraphData()
|
const { nodes, edges }: { nodes: unknown[], edges: unknown[] } = Util.constructGraphData()
|
||||||
const note = Util.getSinglePost(params.id);
|
const { id } = context.params as ParsedUrlQuery & { id: string }
|
||||||
|
|
||||||
|
const note = Util.getSinglePost(id);
|
||||||
const tree = Util.convertObject(Util.getDirectoryData());
|
const tree = Util.convertObject(Util.getDirectoryData());
|
||||||
const flattenNodes = Util.getFlattenArray(tree)
|
const flattenNodes = Util.getFlattenArray(tree)
|
||||||
|
|
||||||
const listOfEdges: unknown[] = edges.filter(anEdge => anEdge.target === params.id)
|
const listOfEdges: unknown[] = edges.filter(anEdge => (anEdge as { target: string }).target === id)
|
||||||
const internalLinks: unknown[] = listOfEdges.map((anEdge: { source: string }) => nodes.find(aNode => aNode.slug === anEdge.source)).filter(element => element !== undefined)
|
const internalLinks: unknown[] = listOfEdges.map((anEdge) => nodes.find(aNode => (aNode as { slug: string }).slug === (anEdge as { source: string }).source)).filter(element => element !== undefined)
|
||||||
const backLinks = [...new Set(internalLinks)]
|
const backLinks = [...new Set(internalLinks)]
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
note,
|
note,
|
||||||
tree: tree,
|
tree: tree,
|
||||||
flattenNodes: flattenNodes,
|
flattenNodes: flattenNodes,
|
||||||
backLinks: backLinks.filter((link: { slug: string }) => link.slug !== params.id),
|
backLinks: backLinks.filter((link) => (link as { slug: string }).slug !== id),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
@layer components {
|
@layer components {
|
||||||
|
|
||||||
.nav-bar {
|
.nav-bar {
|
||||||
@apply bg-blue-100 p-5;
|
@apply text-black bg-blue-100 p-5;
|
||||||
}
|
}
|
||||||
|
|
||||||
.notes-container {
|
.notes-container {
|
||||||
|
Loading…
Reference in New Issue
Block a user