mirror of
https://github.com/oceanprotocol/docs.git
synced 2024-11-26 19:49:26 +01:00
Improvement: Use module instead of subsection
This commit is contained in:
parent
f3020e2159
commit
9069508860
2
.gitignore
vendored
2
.gitignore
vendored
@ -7,4 +7,4 @@ yarn-error.log
|
|||||||
.env
|
.env
|
||||||
.env.*
|
.env.*
|
||||||
markdowns/
|
markdowns/
|
||||||
!markdowns/.gitkeep
|
.vscode/
|
@ -8,26 +8,7 @@ import MarkdownTemplate from './MarkdownTemplate'
|
|||||||
import sidebarStyles from '../components/Sidebar.module.scss'
|
import sidebarStyles from '../components/Sidebar.module.scss'
|
||||||
|
|
||||||
export default function MarkdownList({ pageContext }) {
|
export default function MarkdownList({ pageContext }) {
|
||||||
const subSections = {}
|
const modules = {}
|
||||||
const temp = {}
|
|
||||||
|
|
||||||
const assign = (obj, keyPath, value) => {
|
|
||||||
let lastKeyIndex = keyPath.length - 1
|
|
||||||
for (var i = 0; i < lastKeyIndex; ++i) {
|
|
||||||
let key = keyPath[i]
|
|
||||||
if (!(key in obj)) {
|
|
||||||
obj[key] = {}
|
|
||||||
}
|
|
||||||
obj = obj[key]
|
|
||||||
}
|
|
||||||
obj[keyPath[lastKeyIndex]] = value
|
|
||||||
}
|
|
||||||
|
|
||||||
// console.log('pageContext', pageContext)
|
|
||||||
// pageContext.markdownList.map(({ node }) => {
|
|
||||||
// let modules = node.frontmatter.module.split('.')
|
|
||||||
// assign(temp, modules, node)
|
|
||||||
// })
|
|
||||||
|
|
||||||
pageContext.markdownList.map(({ node }) => {
|
pageContext.markdownList.map(({ node }) => {
|
||||||
let modules = node.frontmatter.module.split('.')
|
let modules = node.frontmatter.module.split('.')
|
||||||
@ -36,17 +17,15 @@ export default function MarkdownList({ pageContext }) {
|
|||||||
|
|
||||||
console.log(key)
|
console.log(key)
|
||||||
|
|
||||||
if (!subSections[key]) {
|
if (!modules[key]) {
|
||||||
subSections[key] = []
|
modules[key] = []
|
||||||
}
|
}
|
||||||
subSections[key].push(node)
|
modules[key].push(node)
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log('subSections', subSections)
|
|
||||||
|
|
||||||
const [selectedSubSection, setSelectedSubSection] = useState(0)
|
const [selectedSubSection, setSelectedSubSection] = useState(0)
|
||||||
const [elem, setElem] = useState(
|
const [elem, setElem] = useState(
|
||||||
subSections[Object.keys(subSections)[selectedSubSection]][0]
|
modules[Object.keys(modules)[selectedSubSection]][0]
|
||||||
)
|
)
|
||||||
|
|
||||||
const changePage = (subSectionIndex, node) => {
|
const changePage = (subSectionIndex, node) => {
|
||||||
@ -56,7 +35,7 @@ export default function MarkdownList({ pageContext }) {
|
|||||||
|
|
||||||
const changeSubsection = (index) => {
|
const changeSubsection = (index) => {
|
||||||
setSelectedSubSection(index)
|
setSelectedSubSection(index)
|
||||||
setElem(subSections[Object.keys(subSections)[index]][0])
|
setElem(modules[Object.keys(modules)[index]][0])
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -71,7 +50,7 @@ export default function MarkdownList({ pageContext }) {
|
|||||||
<main className={styles.wrapper}>
|
<main className={styles.wrapper}>
|
||||||
<aside className={styles.sidebar}>
|
<aside className={styles.sidebar}>
|
||||||
<nav className={sidebarStyles.sidebar}>
|
<nav className={sidebarStyles.sidebar}>
|
||||||
{Object.keys(subSections)
|
{Object.keys(modules)
|
||||||
.sort()
|
.sort()
|
||||||
.map((ele, subSectionIndex) => {
|
.map((ele, subSectionIndex) => {
|
||||||
return selectedSubSection === subSectionIndex ? (
|
return selectedSubSection === subSectionIndex ? (
|
||||||
@ -85,7 +64,7 @@ export default function MarkdownList({ pageContext }) {
|
|||||||
</a>
|
</a>
|
||||||
<div className={sidebarStyles.list}>
|
<div className={sidebarStyles.list}>
|
||||||
<ul>
|
<ul>
|
||||||
{subSections[ele].map((node) => (
|
{modules[ele].map((node) => (
|
||||||
<li
|
<li
|
||||||
className={
|
className={
|
||||||
elem.id === node.id
|
elem.id === node.id
|
||||||
|
Loading…
Reference in New Issue
Block a user