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

proof of concept for generating pages from selected repo contents

This commit is contained in:
Matthias Kretschmann 2018-11-14 13:00:32 +01:00
parent b509f64f41
commit 13639a678f
Signed by: m
GPG Key ID: 606EEEF3C479A91F
6 changed files with 199 additions and 22 deletions

View File

@ -1,10 +0,0 @@
---
title: Architecture
description: The architecture of Ocean Protocol with all its components and how they work together.
---
See the page about the [Ocean network components](/concepts/components/).
See the (somewhat-dated) diagram on the page https://github.com/oceanprotocol/dev-ocean/blob/master/doc/architecture.md
![Ocean Protocol Components](images/components.png 'Ocean Protocol Components')

View File

@ -6,13 +6,13 @@
link: /concepts/terminology/ link: /concepts/terminology/
- title: Software Components - title: Software Components
link: /concepts/components/ link: /concepts/components/
- title: Architecture
link: /concepts/architecture/
- group: Details - group: Architecture
items: items:
- title: Coming Soon - title: Overview
link: / link: /concepts/architecture/
- title: Squid
link: /concepts/squid/
- group: Contribute - group: Contribute
items: items:

View File

@ -22,8 +22,47 @@ exports.onCreateNode = ({ node, getNode, actions }) => {
value: section value: section
}) })
} }
// // console.log(node)
// // if (node.internal.owner === 'gatsby-source-graphql') {
// // console.log(node)
// // }
} }
// exports.sourceNodes = (
// { actions, createNodeId, createContentDigest },
// configOptions
// ) => {
// const { createNode } = actions
// // Gatsby adds a configOption that's not needed for this plugin, delete it
// delete configOptions.plugins
// createNode({
// // Data for the node.
// field1: `a string`,
// field2: 10,
// field3: true,
// ...arbitraryOtherData,
// // Required fields.
// id: `a-node-id`,
// parent: `the-id-of-the-parent-node`, // or null if it's a source node without a parent
// children: [],
// internal: {
// type: `CoolServiceMarkdownField`,
// contentDigest: crypto
// .createHash(`md5`)
// .update(JSON.stringify(fieldData))
// .digest(`hex`),
// mediaType: `text/markdown`, // optional
// content: JSON.stringify(fieldData), // optional
// description: `Cool Service: "Title of entry"` // optional
// }
// })
// }
exports.createPages = ({ graphql, actions }) => { exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions const { createPage } = actions
@ -44,6 +83,28 @@ exports.createPages = ({ graphql, actions }) => {
} }
} }
} }
github {
repository(
owner: "oceanprotocol"
name: "dev-ocean"
) {
root: object(
expression: "master:doc/architecture.md"
) {
... on GitHub_Blob {
text
}
}
squid: object(
expression: "master:doc/architecture/squid.md"
) {
... on GitHub_Blob {
text
}
}
}
}
} }
` `
).then(result => { ).then(result => {
@ -53,8 +114,8 @@ exports.createPages = ({ graphql, actions }) => {
reject(result.errors) reject(result.errors)
} }
const posts = result.data.allMarkdownRemark.edges
const docTemplate = path.resolve('./src/templates/Doc.jsx') const docTemplate = path.resolve('./src/templates/Doc.jsx')
const posts = result.data.allMarkdownRemark.edges
// Create Doc pages // Create Doc pages
posts.forEach(post => { posts.forEach(post => {
@ -68,6 +129,35 @@ exports.createPages = ({ graphql, actions }) => {
}) })
}) })
// Create Architecture section from dev-ocean contents
const docRepoTemplate = path.resolve(
'./src/templates/DocRepo.jsx'
)
createPage({
path: '/concepts/architecture/',
component: docRepoTemplate,
context: {
slug: '/concepts/architecture/',
section: 'concepts',
title: 'Architecture',
description: 'Hello description',
content: `${result.data.github.repository.root.text}`
}
})
createPage({
path: '/concepts/squid/',
component: docRepoTemplate,
context: {
slug: '/concepts/squid/',
section: 'concepts',
title: 'Squid',
description: 'Hello description',
content: `${result.data.github.repository.squid.text}`
}
})
resolve() resolve()
}) })
) )

View File

@ -9,18 +9,24 @@ const renderAst = new RehypeReact({
components: { repo: Repository } components: { repo: Repository }
}).Compiler }).Compiler
const DocContent = ({ html, htmlAst }) => const DocContent = ({ html, htmlAst, github }) => {
html ? ( if (github) {
return <div className={styles.docContent}>{html}</div>
}
return html ? (
<div className={styles.docContent}>{renderAst(htmlAst)}</div> <div className={styles.docContent}>{renderAst(htmlAst)}</div>
) : ( ) : (
<div className={styles.empty}> <div className={styles.empty}>
This is a placeholder for now. Help creating it. This is a placeholder for now. Help creating it.
</div> </div>
) )
}
DocContent.propTypes = { DocContent.propTypes = {
html: PropTypes.string, html: PropTypes.string,
htmlAst: PropTypes.object htmlAst: PropTypes.object,
github: PropTypes.bool
} }
export default DocContent export default DocContent

View File

@ -14,15 +14,17 @@ import styles from './Doc.module.scss'
export default class DocTemplate extends Component { export default class DocTemplate extends Component {
static propTypes = { static propTypes = {
data: PropTypes.object.isRequired, data: PropTypes.object.isRequired,
location: PropTypes.object.isRequired location: PropTypes.object.isRequired,
pageContext: PropTypes.object
} }
render() { render() {
const { location } = this.props const { location } = this.props
const post = this.props.data.markdownRemark const post = this.props.data.markdownRemark
const sections = this.props.data.allSectionsYaml.edges const sections = this.props.data.allSectionsYaml.edges
const { section } = post.fields const { section } = post.fields ? post.fields : this.props.pageContext
const { title, description } = post.frontmatter const { title, description } =
post.frontmatter || this.props.pageContext
// output section title as defined in sections.yml // output section title as defined in sections.yml
const sectionTitle = sections.map(({ node }) => { const sectionTitle = sections.map(({ node }) => {

89
src/templates/DocRepo.jsx Normal file
View File

@ -0,0 +1,89 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { graphql } from 'gatsby'
import Helmet from 'react-helmet'
import Layout from '../components/Layout'
import Content from '../components/Content'
import HeaderSection from '../components/HeaderSection'
import Sidebar from '../components/Sidebar'
import DocContent from '../components/DocContent'
import DocHeader from '../components/DocHeader'
import styles from './Doc.module.scss'
export default class DocRepoTemplate extends Component {
static propTypes = {
data: PropTypes.object.isRequired,
location: PropTypes.object.isRequired,
pageContext: PropTypes.object
}
render() {
const { location } = this.props
const sections = this.props.data.allSectionsYaml.edges
const { section } = this.props.pageContext
const { title, description, content } = this.props.pageContext
// output section title as defined in sections.yml
const sectionTitle = sections.map(({ node }) => {
// compare section against section title from sections.yml
if (node.title.toLowerCase().includes(section)) {
return node.title
}
})
return (
<>
<Helmet>
<title>{title}</title>
<meta name="description" content={description} />
<body className={section} />
</Helmet>
<Layout location={location}>
<HeaderSection title={section ? sectionTitle : title} />
<Content>
{section ? (
<main className={styles.wrapper}>
<aside className={styles.sidebar}>
<Sidebar
location={location}
sidebar={section}
/>
</aside>
<article className={styles.main}>
<DocHeader
title={title}
description={description}
/>
<DocContent html={content} github />
</article>
</main>
) : (
<article className={styles.mainSingle}>
<DocHeader
title={title}
description={description}
/>
<DocContent html={content} github />
</article>
)}
</Content>
</Layout>
</>
)
}
}
export const pageQuery = graphql`
query {
allSectionsYaml {
edges {
node {
title
description
link
}
}
}
}
`