diff --git a/gatsby-node.js b/gatsby-node.js index c9f286fb..504d2688 100755 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -71,6 +71,7 @@ exports.createPages = ({ graphql, actions }) => { slug title section + sub_section } } } diff --git a/src/templates/MarkdownList.jsx b/src/templates/MarkdownList.jsx index a78d6e2c..8da1b312 100644 --- a/src/templates/MarkdownList.jsx +++ b/src/templates/MarkdownList.jsx @@ -8,11 +8,30 @@ import MarkdownTemplate from './MarkdownTemplate' import stylesDoc from '../templates/Doc.module.scss' export default function MarkdownList({pageContext}) { - const [elem, setElem] = useState(0); - const changePage= (index)=>{ - console.log("Onclickj") - setElem(index) + + const sub_sections = {} + pageContext.markdownList.map(({node}, index) => { + if(!sub_sections[node.frontmatter.sub_section]){ + sub_sections[node.frontmatter.sub_section] = [] + } + sub_sections[node.frontmatter.sub_section].push(node) + }) + + const [selectedSubSection, setSelectedSubSection] = useState(0); + const [elem, setElem] = useState(sub_sections[Object.keys(sub_sections)[selectedSubSection]][0]); + + + const changePage = (sub_section_index, node)=>{ + setElem(node) + setSelectedSubSection(sub_section_index) }; + + const changeSubsection = (index)=>{ + setSelectedSubSection(index) + setElem(sub_sections[Object.keys(sub_sections)[index]][0]) + + }; + return ( @@ -20,13 +39,16 @@ export default function MarkdownList({pageContext}) {
- {/* */}
- +