From e66dbd334bcf2a790a3c47d8141d4e868539e79f Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Wed, 14 Nov 2018 15:17:19 +0100 Subject: [PATCH] prototype page creation from submodule --- external/dev-ocean | 2 +- gatsby-config.js | 8 +- gatsby-node.js | 149 ++++++++++++++---------------- src/components/DocContent.jsx | 12 +-- src/components/DocToc.jsx | 16 ++++ src/components/DocToc.module.scss | 11 +++ src/templates/Doc.jsx | 23 ++++- src/templates/DocRepo.jsx | 89 ------------------ 8 files changed, 124 insertions(+), 186 deletions(-) create mode 100644 src/components/DocToc.jsx create mode 100644 src/components/DocToc.module.scss delete mode 100644 src/templates/DocRepo.jsx diff --git a/external/dev-ocean b/external/dev-ocean index 6d3378fb..90d07bfa 160000 --- a/external/dev-ocean +++ b/external/dev-ocean @@ -1 +1 @@ -Subproject commit 6d3378fb8ac3d55bcf51ed44c3aacff750eecc39 +Subproject commit 90d07bfa55df97951835545c188c38bc46682048 diff --git a/gatsby-config.js b/gatsby-config.js index 63a3beee..9f3d7fec 100755 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -37,7 +37,6 @@ module.exports = { path: `${__dirname}/data` } }, - { resolve: 'gatsby-source-filesystem', options: { @@ -45,6 +44,13 @@ module.exports = { path: `${__dirname}/node_modules/@oceanprotocol/art` } }, + { + resolve: 'gatsby-source-filesystem', + options: { + name: 'dev-ocean', + path: `${__dirname}/external/dev-ocean/doc` + } + }, { resolve: 'gatsby-source-graphql', options: { diff --git a/gatsby-node.js b/gatsby-node.js index 8180601d..83337aa8 100755 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -7,8 +7,17 @@ exports.onCreateNode = ({ node, getNode, actions }) => { if (node.internal.type === 'MarkdownRemark') { const fileNode = getNode(node.parent) const parsedFilePath = path.parse(fileNode.relativePath) - const slug = createFilePath({ node, getNode, basePath: 'content' }) - const section = parsedFilePath.dir + + let slug = createFilePath({ node, getNode, basePath: 'content' }) + let section = parsedFilePath.dir + + if (node.frontmatter.slug) { + ;({ slug } = node.frontmatter) + } + + if (node.frontmatter.section) { + ;({ section } = node.frontmatter) + } createNodeField({ node, @@ -22,47 +31,8 @@ exports.onCreateNode = ({ node, getNode, actions }) => { 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 }) => { const { createPage } = actions @@ -84,23 +54,18 @@ exports.createPages = ({ graphql, actions }) => { } } - github { - repository( - owner: "oceanprotocol" - name: "dev-ocean" - ) { - root: object( - expression: "master:doc/architecture.md" - ) { - ... on GitHub_Blob { - text - } + architectureDocs: allMarkdownRemark( + filter: { + fileAbsolutePath: { + regex: "/dev-ocean/doc/architecture.md/" } - squid: object( - expression: "master:doc/architecture/squid.md" - ) { - ... on GitHub_Blob { - text + } + ) { + edges { + node { + fields { + slug + section } } } @@ -130,33 +95,55 @@ exports.createPages = ({ graphql, actions }) => { }) // Create Architecture section from dev-ocean contents - const docRepoTemplate = path.resolve( - './src/templates/DocRepo.jsx' - ) + const postsArchitecture = result.data.architectureDocs.edges - createPage({ - path: '/concepts/architecture/', - component: docRepoTemplate, - context: { - slug: '/concepts/architecture/', - section: 'concepts', - title: 'Architecture', - description: 'Hello description', - content: `${result.data.github.repository.root.text}` - } + postsArchitecture.forEach(post => { + createPage({ + path: `${post.node.fields.slug}`, + component: docTemplate, + context: { + slug: post.node.fields.slug, + section: post.node.fields.section + } + }) }) - createPage({ - path: '/concepts/squid/', - component: docRepoTemplate, - context: { - slug: '/concepts/squid/', - section: 'concepts', - title: 'Squid', - description: 'Hello description', - content: `${result.data.github.repository.squid.text}` - } - }) + // createPage({ + // path: '/concepts/architecture/', + // component: docTemplate, + // context: { + // slug: post.node.fields.slug, + // section: post.node.fields.section + // } + // }) + + // 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() }) diff --git a/src/components/DocContent.jsx b/src/components/DocContent.jsx index 14ff3230..e639bc02 100644 --- a/src/components/DocContent.jsx +++ b/src/components/DocContent.jsx @@ -9,24 +9,18 @@ const renderAst = new RehypeReact({ components: { repo: Repository } }).Compiler -const DocContent = ({ html, htmlAst, github }) => { - if (github) { - return
{html}
- } - - return html ? ( +const DocContent = ({ html, htmlAst }) => + html ? (
{renderAst(htmlAst)}
) : (
This is a placeholder for now. Help creating it.
) -} DocContent.propTypes = { html: PropTypes.string, - htmlAst: PropTypes.object, - github: PropTypes.bool + htmlAst: PropTypes.object } export default DocContent diff --git a/src/components/DocToc.jsx b/src/components/DocToc.jsx new file mode 100644 index 00000000..e67158ac --- /dev/null +++ b/src/components/DocToc.jsx @@ -0,0 +1,16 @@ +import React from 'react' +import PropTypes from 'prop-types' +import styles from './DocToc.module.scss' + +const DocToc = ({ tableOfContents }) => ( +