mirror of
https://github.com/oceanprotocol/docs.git
synced 2024-11-26 19:49:26 +01:00
Improvement: Add subsections
This commit is contained in:
parent
67c9968065
commit
f6baca584a
@ -71,6 +71,7 @@ exports.createPages = ({ graphql, actions }) => {
|
|||||||
slug
|
slug
|
||||||
title
|
title
|
||||||
section
|
section
|
||||||
|
sub_section
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,11 +8,30 @@ import MarkdownTemplate from './MarkdownTemplate'
|
|||||||
import stylesDoc from '../templates/Doc.module.scss'
|
import stylesDoc from '../templates/Doc.module.scss'
|
||||||
|
|
||||||
export default function MarkdownList({pageContext}) {
|
export default function MarkdownList({pageContext}) {
|
||||||
const [elem, setElem] = useState(0);
|
|
||||||
const changePage= (index)=>{
|
const sub_sections = {}
|
||||||
console.log("Onclickj")
|
pageContext.markdownList.map(({node}, index) => {
|
||||||
setElem(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 (
|
return (
|
||||||
<Layout>
|
<Layout>
|
||||||
<HeaderSection title={pageContext.name} />
|
<HeaderSection title={pageContext.name} />
|
||||||
@ -20,13 +39,16 @@ export default function MarkdownList({pageContext}) {
|
|||||||
<main className={styles.wrapper}>
|
<main className={styles.wrapper}>
|
||||||
<aside className={styles.sidebar}>
|
<aside className={styles.sidebar}>
|
||||||
<ul>
|
<ul>
|
||||||
{pageContext.markdownList.map(({node}, index)=><li onClick={()=>changePage(index)} key={node.id}>
|
{Object.keys(sub_sections).map((ele, sub_section_index)=>{return<li key={sub_section_index}>
|
||||||
{node.frontmatter.title}</li>)}
|
<div onClick={()=>changeSubsection(sub_section_index)}>{ele}</div>
|
||||||
|
<ul>
|
||||||
|
{sub_sections[ele].map((node)=><li key={node.id} onClick={()=>changePage(sub_section_index, node)}>{node.frontmatter.title}</li>)}
|
||||||
|
</ul>
|
||||||
|
</li>})}
|
||||||
</ul>
|
</ul>
|
||||||
</aside>
|
</aside>
|
||||||
{/* <MarkdownTemplate path={pageContext.markdownList[0]}></MarkdownTemplate> */}
|
|
||||||
<article className={stylesDoc.main}>
|
<article className={stylesDoc.main}>
|
||||||
<MarkdownTemplate data={pageContext.markdownList[elem].node}></MarkdownTemplate>
|
<MarkdownTemplate data={elem}></MarkdownTemplate>
|
||||||
</article>
|
</article>
|
||||||
</main>
|
</main>
|
||||||
</Content>
|
</Content>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user