diff --git a/src/templates/MarkdownList.jsx b/src/templates/MarkdownList.jsx index 02f52f04..ea82c60e 100644 --- a/src/templates/MarkdownList.jsx +++ b/src/templates/MarkdownList.jsx @@ -10,6 +10,40 @@ import sidebarStyles from '../components/Sidebar.module.scss' export default function MarkdownList({ pageContext }) { const modules = {} + const nested = {} + const nested2 = [] + const [selectedNodeId, setSelectedNodeId] = useState(0) + + const changeNodeid = (id) => { + setSelectedNodeId(id) + + for (let i = 0; i < pageContext.markdownList.length; i++) { + var node = pageContext.markdownList[i]['node'] + if (node.id == id) { + setElem(node) + break + } + } + } + + function generatedNested(obj, keyPath, value) { + var lastKeyIndex = keyPath.length - 1 + for (var i = 0; i < lastKeyIndex; ++i) { + var key = keyPath[i] + if (!(key in obj)) { + obj[key] = {} + } + obj = obj[key] + } + if (!obj[keyPath[lastKeyIndex]]) { + obj[keyPath[lastKeyIndex]] = { + id: value.id, + label: value.frontmatter.title + } + } + // obj[keyPath[lastKeyIndex]].push({ type: 'module', value: value.id }) + } + pageContext.markdownList.map(({ node }) => { const modulePath = node.frontmatter.module.split('.') const key = @@ -20,8 +54,49 @@ export default function MarkdownList({ pageContext }) { modules[key] = [] } modules[key].push(node) + + generatedNested(nested, modulePath, node) }) + const g = (title, nested) => { + if (nested.id) { + return ( +