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

proof of concept for nav sidebar

This commit is contained in:
Matthias Kretschmann 2018-11-08 10:44:46 +01:00
parent 2eff47b9b9
commit cb32491139
Signed by: m
GPG Key ID: 606EEEF3C479A91F
15 changed files with 197 additions and 2 deletions

View File

@ -8,5 +8,5 @@ indent_style = space
insert_final_newline = true insert_final_newline = true
trim_trailing_whitespace = true trim_trailing_whitespace = true
[*.json] [*.{json,yml,yaml}]
indent_size = 2 indent_size = 2

View File

@ -0,0 +1,4 @@
---
title: Architecture
sidebar: concepts
---

View File

@ -0,0 +1,4 @@
---
title: Ecosystem
sidebar: concepts
---

View File

@ -1,5 +1,6 @@
--- ---
title: Introduction title: Introduction
sidebar: concepts
--- ---
What is Ocean Protocol? What is Ocean Protocol?

View File

@ -0,0 +1,4 @@
---
title: Security
sidebar: concepts
---

View File

@ -1,5 +1,6 @@
--- ---
title: Terminology title: Terminology
sidebar: concepts
--- ---
There is terminology specific to Ocean Protocol. There is terminology specific to Ocean Protocol.
@ -43,4 +44,3 @@ A set of software libraries to interact with Ocean network participants, includi
## Pleuston ## Pleuston
An example marketplace frontend implemented using React and Squid-JavaScript. An example marketplace frontend implemented using React and Squid-JavaScript.

View File

@ -0,0 +1,4 @@
---
title: Reporting vulnerabilities
sidebar: concepts
---

View File

@ -34,6 +34,7 @@ module.exports = {
] ]
} }
}, },
'gatsby-transformer-yaml',
{ {
resolve: 'gatsby-plugin-sass', resolve: 'gatsby-plugin-sass',
options: { options: {

View File

@ -20,6 +20,7 @@
"gatsby-source-filesystem": "^2.0.7", "gatsby-source-filesystem": "^2.0.7",
"gatsby-transformer-remark": "^2.1.11", "gatsby-transformer-remark": "^2.1.11",
"gatsby-transformer-sharp": "^2.1.8", "gatsby-transformer-sharp": "^2.1.8",
"gatsby-transformer-yaml": "^2.1.4",
"intersection-observer": "^0.5.1", "intersection-observer": "^0.5.1",
"node-sass": "^4.10.0", "node-sass": "^4.10.0",
"prismjs": "^1.15.0", "prismjs": "^1.15.0",

134
src/components/Sidebar.jsx Normal file
View File

@ -0,0 +1,134 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { Link } from 'gatsby'
import styles from './Sidebar.module.scss'
function groupExpanded(items, pathname) {
var breakException = {}
try {
items.forEach(item => {
if (item.link === pathname) {
throw breakException
}
})
} catch (e) {
if (e !== breakException) {
throw e
} else {
return true
}
}
return false
}
const SidebarLink = ({ link, title, linkClasses }) => {
if (link) {
if (link.match(/^\s?http(s?)/gi)) {
return (
<a href={link} target="_blank" rel="noopener noreferrer">
{title}
</a>
)
} else {
return (
<Link to={link} className={linkClasses}>
{title}
</Link>
)
}
} else {
return <>{this.props.title}</>
}
}
const SidebarList = ({ items, location }) => (
<ul>
{items.map((item, j) => (
<li key={j}>
<SidebarLink
link={item.link}
title={item.title}
linkClasses={
item.link === location.pathname
? styles.active
: styles.link
}
/>
</li>
))}
</ul>
)
export default class Sidebar extends Component {
static propTypes = {
sidebar: PropTypes.string,
location: PropTypes.object.isRequired
}
static defaultProps = {
location: { pathname: `/` }
}
render() {
const { sidebar, location } = this.props
const sidebarfile = sidebar
? require(`../data/sidebars/${sidebar}.yml`) // eslint-disable-line
: []
if (!sidebarfile) {
return null
}
return (
<nav>
{sidebarfile.map((group, i) => (
<div key={i}>
{groupExpanded(group.items, location.pathname) ? (
<>
<h4>
{group.items[0].link ? (
<SidebarLink
link={group.items[0].link}
title={group.group}
linkClasses="midgrey link"
/>
) : (
group.group
)}
</h4>
<SidebarList
key={i}
items={group.items}
location={location}
/>
</>
) : (
<h4>
{group.items[0].link ? (
<SidebarLink
link={group.items[0].link}
title={group.group}
/>
) : (
group.group
)}
</h4>
)}
</div>
))}
</nav>
)
}
}
SidebarLink.propTypes = {
link: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
linkClasses: PropTypes.string
}
SidebarList.propTypes = {
items: PropTypes.array.isRequired,
location: PropTypes.object.isRequired
}

View File

@ -0,0 +1,7 @@
.link {
color: black;
}
.active {
composes: link;
}

View File

@ -0,0 +1,20 @@
- group: Getting Started
items:
- title: What is Ocean Protocol?
link: /concepts/introduction/
- title: Terminology
link: /concepts/terminology/
- title: Ecosystem overview
link: /concepts/ecosystem/
- group: Architecture
items:
- title: Overview
link: /concepts/architecture/
- group: Security
items:
- title: Overview
link: /concepts/security/
- title: Reporting vulnerabilities
link: /concepts/vulnerabilities/

View File

@ -0,0 +1,8 @@
- group: Setup Guides
items:
- title: Set Up a Keeper
link: /setup/keeper/
- title: Set Up a Marketplace
link: /setup/marketplace/
- title: Publish Data or Services
link: /setup/publisher/

View File

@ -2,6 +2,7 @@ import React, { Component } from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import { graphql } from 'gatsby' import { graphql } from 'gatsby'
import Layout from '../components/Layout' import Layout from '../components/Layout'
import Sidebar from '../components/Sidebar'
export default class DocTemplate extends Component { export default class DocTemplate extends Component {
static propTypes = { static propTypes = {
@ -14,6 +15,11 @@ export default class DocTemplate extends Component {
return ( return (
<Layout location={this.props.location}> <Layout location={this.props.location}>
<Sidebar
location={this.props.location}
sidebar={post.frontmatter.sidebar}
/>
<h1>{post.frontmatter.title}</h1> <h1>{post.frontmatter.title}</h1>
<div dangerouslySetInnerHTML={{ __html: post.html }} /> <div dangerouslySetInnerHTML={{ __html: post.html }} />
</Layout> </Layout>
@ -34,6 +40,7 @@ export const pageQuery = graphql`
html html
frontmatter { frontmatter {
title title
sidebar
} }
} }
} }