1
0
mirror of https://github.com/oceanprotocol/docs.git synced 2024-11-26 19:49:26 +01:00

Improvement: Fix lint issues

This commit is contained in:
Akshay 2021-04-12 11:19:11 +02:00
parent 72054a3b71
commit 92a3e60137
4 changed files with 98 additions and 84 deletions

View File

@ -157,17 +157,17 @@ module.exports = {
name: `repo-read-the-docs`, name: `repo-read-the-docs`,
remote: `https://github.com/oceanprotocol/readthedocs.git`, remote: `https://github.com/oceanprotocol/readthedocs.git`,
local: 'markdowns/', local: 'markdowns/',
branch: `gatsby`, branch: 'gatsby',
patterns: `markdowns/**` patterns: 'markdowns/**'
} }
}, },
{ {
resolve: `gatsby-source-filesystem`, resolve: 'gatsby-source-filesystem',
options: { options: {
path: `${__dirname}/markdowns/markdowns`, path: `${__dirname}/markdowns/markdowns`,
name: `markdowns`, name: 'markdowns'
}, }
}, },
`gatsby-transformer-remark`, 'gatsby-transformer-remark'
] ]
} }

View File

@ -58,24 +58,24 @@ exports.createPages = ({ graphql, actions }) => {
} }
} }
allRepoMarkdown: allMarkdownRemark ( allRepoMarkdown: allMarkdownRemark(
filter: { fileAbsolutePath: { regex: "/markdowns/" } } filter: { fileAbsolutePath: { regex: "/markdowns/" } }
) { ) {
edges { edges {
node { node {
id id
html html
htmlAst htmlAst
tableOfContents tableOfContents
frontmatter { frontmatter {
slug slug
title title
section section
sub_section sub_section
}
} }
} }
} }
}
oceanJs: github { oceanJs: github {
repository(name: "ocean.js", owner: "oceanprotocol") { repository(name: "ocean.js", owner: "oceanprotocol") {
@ -111,7 +111,7 @@ exports.createPages = ({ graphql, actions }) => {
const docTemplate = path.resolve('./src/templates/Doc.jsx') const docTemplate = path.resolve('./src/templates/Doc.jsx')
const posts = result.data.allMarkdownRemark.edges const posts = result.data.allMarkdownRemark.edges
// //
// Create Doc pages // Create Doc pages
// //
@ -156,16 +156,20 @@ exports.createPages = ({ graphql, actions }) => {
// console.log("Query result:", JSON.stringify(result)) // console.log("Query result:", JSON.stringify(result))
const markdowns = result.data.allRepoMarkdown.edges const markdowns = result.data.allRepoMarkdown.edges
const prefix = '/read-the-docs' const prefix = '/read-the-docs'
let oceanPyList = markdowns.filter(({node}) => node.frontmatter.slug.startsWith(prefix + '/ocean-py/')) const oceanPyList = filterMarkdownList(markdowns, prefix + '/ocean-py/')
let aquariusList = markdowns.filter(({node}) => node.frontmatter.slug.startsWith(prefix + '/aquarius/')) const aquariusList = filterMarkdownList(
let providerList = markdowns.filter(({node}) => node.frontmatter.slug.startsWith(prefix + '/provider/')) markdowns,
prefix + '/aquarius/'
)
const providerList = filterMarkdownList(
markdowns,
prefix + '/provider/'
)
await createReadTheDocsPage(createPage, 'ocean-py', oceanPyList) await createReadTheDocsPage(createPage, 'ocean-py', oceanPyList)
await createReadTheDocsPage(createPage, 'aquarius', aquariusList) await createReadTheDocsPage(createPage, 'aquarius', aquariusList)
await createReadTheDocsPage(createPage, 'provider', providerList) await createReadTheDocsPage(createPage, 'provider', providerList)
resolve() resolve()
}) })
) )
@ -289,7 +293,7 @@ const createSwaggerPages = async (createPage) => {
} }
} }
const createReadTheDocsPage = async (createPage, name, list)=>{ const createReadTheDocsPage = async (createPage, name, list) => {
const markdownListTemplate = path.resolve('./src/templates/MarkdownList.jsx') const markdownListTemplate = path.resolve('./src/templates/MarkdownList.jsx')
createPage({ createPage({
path: `/read-the-docs/${name}`, path: `/read-the-docs/${name}`,
@ -300,18 +304,22 @@ const createReadTheDocsPage = async (createPage, name, list)=>{
} }
}) })
list.forEach((element)=>{ list.forEach((element) => {
createMarkdownPage(createPage, element) createMarkdownPage(createPage, element)
}) })
} }
const createMarkdownPage = async (createPage, element) => {
const createMarkdownPage = async (createPage, element)=>{
// console.log("element", JSON.stringify(element.node.frontmatter)) // console.log("element", JSON.stringify(element.node.frontmatter))
const markdownTemplate = path.resolve('./src/templates/MarkdownTemplate.jsx') const markdownTemplate = path.resolve('./src/templates/MarkdownTemplate.jsx')
createPage({ createPage({
path: element.node.frontmatter.slug, path: element.node.frontmatter.slug,
component: markdownTemplate component: markdownTemplate
}) })
} }
const filterMarkdownList = (markdownList, string) => {
return markdownList.filter(({ node }) =>
node.frontmatter.slug.startsWith(string)
)
}

View File

@ -1,61 +1,73 @@
import { Link } from "gatsby" import React, { useState } from 'react'
import React, {useState} from "react" import Layout from '../components/Layout'
import Layout from "../components/Layout"
import HeaderSection from '../components/HeaderSection' import HeaderSection from '../components/HeaderSection'
import Content from '../components/Content' import Content from '../components/Content'
import styles from '../templates/Doc.module.scss' import styles from '../templates/Doc.module.scss'
import MarkdownTemplate from './MarkdownTemplate' import MarkdownTemplate from './MarkdownTemplate'
import stylesDoc from '../templates/Doc.module.scss'
export default function MarkdownList({pageContext}) { export default function MarkdownList({ pageContext }) {
const sub_sections = {}
const sub_sections = {} pageContext.markdownList.map(({ node }) => {
pageContext.markdownList.map(({node}, index) => { if (!sub_sections[node.frontmatter.sub_section]) {
if(!sub_sections[node.frontmatter.sub_section]){
sub_sections[node.frontmatter.sub_section] = [] sub_sections[node.frontmatter.sub_section] = []
} }
sub_sections[node.frontmatter.sub_section].push(node) sub_sections[node.frontmatter.sub_section].push(node)
}) })
const [selectedSubSection, setSelectedSubSection] = useState(0); const [selectedSubSection, setSelectedSubSection] = useState(0)
const [elem, setElem] = useState(sub_sections[Object.keys(sub_sections)[selectedSubSection]][0]); const [elem, setElem] = useState(
sub_sections[Object.keys(sub_sections)[selectedSubSection]][0]
)
const changePage = (subSectionIndex, node) => {
const changePage = (sub_section_index, node)=>{
setElem(node) setElem(node)
setSelectedSubSection(sub_section_index) setSelectedSubSection(subSectionIndex)
}; }
const changeSubsection = (index)=>{ const changeSubsection = (index) => {
setSelectedSubSection(index) setSelectedSubSection(index)
setElem(sub_sections[Object.keys(sub_sections)[index]][0]) setElem(sub_sections[Object.keys(sub_sections)[index]][0])
}
};
return ( return (
<Layout> <Layout>
<HeaderSection title={pageContext.name} /> <HeaderSection title={pageContext.name} />
<Content> <Content>
<main className={styles.wrapper}> <main className={styles.wrapper}>
<aside className={styles.sidebar}> <aside className={styles.sidebar}>
<ul> <ul>
{Object.keys(sub_sections).map((ele, sub_section_index)=>{ {Object.keys(sub_sections).map((ele, subSectionIndex) => {
return selectedSubSection === sub_section_index? return selectedSubSection === subSectionIndex ? (
(<li key={sub_section_index}> <li key={subSectionIndex}>
<div onClick={()=>changeSubsection(sub_section_index)}>{ele.replaceAll('_', ' ')}</div> <div onClick={() => changeSubsection(subSectionIndex)}>
<ul> {ele.replaceAll('_', ' ')}
{sub_sections[ele].map((node)=><li key={node.id} onClick={()=>changePage(sub_section_index, node)}>{node.frontmatter.title.replaceAll('_', ' ')}</li>)} </div>
</ul> <ul>
</li>): <li><div onClick={()=>changeSubsection(sub_section_index)}>{ele.replaceAll('_', ' ')}</div></li> })} {sub_sections[ele].map((node) => (
</ul> <li
</aside> key={node.id}
<article className={stylesDoc.main}> onClick={() => changePage(subSectionIndex, node)}
<MarkdownTemplate data={elem}></MarkdownTemplate> >
</article> {node.frontmatter.title.replaceAll('_', ' ')}
</li>
))}
</ul>
</li>
) : (
<li>
<div onClick={() => changeSubsection(subSectionIndex)}>
{ele.replaceAll('_', ' ')}
</div>
</li>
)
})}
</ul>
</aside>
<article className={styles.main}>
<MarkdownTemplate data={elem}></MarkdownTemplate>
</article>
</main> </main>
</Content> </Content>
</Layout> </Layout>
) )
} }

View File

@ -1,23 +1,18 @@
import { graphql } from 'gatsby'
import React from 'react' import React from 'react'
import DocToc from '../components/DocToc'
import DocHeader from '../components/DocHeader'
import DocContent from '../components/DocContent' import DocContent from '../components/DocContent'
import Layout from '../components/Layout'
import HeaderSection from '../components/HeaderSection'
import Content from '../components/Content' import Content from '../components/Content'
export default function MarkdownTemplate({data}) { export default function MarkdownTemplate({ data }) {
const post = data const post = data
return ( return (
<> <>
{/* <div dangerouslySetInnerHTML={{__html:post.html}}></div> */} {/* <div dangerouslySetInnerHTML={{__html:post.html}}></div> */}
{/* <DocHeader title={post.frontmatter.title}/> */} {/* <DocHeader title={post.frontmatter.title}/> */}
{/* <HeaderSection title={post.frontmatter.title} /> {/* <HeaderSection title={post.frontmatter.title} />
{post.tableOfContents && <DocToc tableOfContents={post.tableOfContents} />}*/} {post.tableOfContents && <DocToc tableOfContents={post.tableOfContents} />}*/}
<Content> <Content>
<DocContent html={post.html} htmlAst={post.htmlAst} /> <DocContent html={post.html} htmlAst={post.htmlAst} />
</Content> </Content>
</> </>
) )
} }
@ -45,4 +40,3 @@ export default function MarkdownTemplate({data}) {
// } // }
// } // }
//` //`