mirror of
https://github.com/oceanprotocol/docs.git
synced 2024-11-26 19:49:26 +01:00
Feature: Render markdowns
This commit is contained in:
parent
c03baa4ed3
commit
9f0d0b318a
@ -150,6 +150,14 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
'gatsby-plugin-webpack-size',
|
'gatsby-plugin-webpack-size',
|
||||||
'gatsby-plugin-offline'
|
'gatsby-plugin-offline',
|
||||||
|
{
|
||||||
|
resolve: `gatsby-source-filesystem`,
|
||||||
|
options: {
|
||||||
|
path: `${__dirname}/markdowns`,
|
||||||
|
name: `markdowns`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
`gatsby-transformer-remark`,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,21 @@ exports.createPages = ({ graphql, actions }) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
allRepoMarkdown: allMarkdownRemark (
|
||||||
|
filter: { fileAbsolutePath: { regex: "/markdowns/" } }
|
||||||
|
) {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
id
|
||||||
|
html
|
||||||
|
frontmatter {
|
||||||
|
slug
|
||||||
|
title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
oceanJs: github {
|
oceanJs: github {
|
||||||
repository(name: "ocean.js", owner: "oceanprotocol") {
|
repository(name: "ocean.js", owner: "oceanprotocol") {
|
||||||
name
|
name
|
||||||
@ -134,6 +149,30 @@ exports.createPages = ({ graphql, actions }) => {
|
|||||||
console.log('Create redirect: ' + from + ' --> ' + to)
|
console.log('Create redirect: ' + from + ' --> ' + to)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// console.log("Query result:", JSON.stringify(result))
|
||||||
|
const markdowns = result.data.allRepoMarkdown.edges
|
||||||
|
const prefix = '/read-the-docs'
|
||||||
|
let oceanPyList = markdowns.filter(({node}) => node.frontmatter.slug.startsWith(prefix + '/oceanpy/'))
|
||||||
|
let aquariusList = markdowns.filter(({node}) => node.frontmatter.slug.startsWith(prefix + '/aquarius/'))
|
||||||
|
let providerList = markdowns.filter(({node}) => node.frontmatter.slug.startsWith(prefix + '/provider/'))
|
||||||
|
// const docMarkdownTemplate = path.resolve('./src/templates/DocMarkdown.jsx')
|
||||||
|
// oceanPyList.forEach((post) => {
|
||||||
|
// createPage({
|
||||||
|
// path: `${post.node.fields.slug}`,
|
||||||
|
// component: docMarkdownTemplate,
|
||||||
|
// context: {
|
||||||
|
// slug: post.node.fields.slug,
|
||||||
|
// section: post.node.fields.section
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// })
|
||||||
|
|
||||||
|
|
||||||
|
// console.log("OceanpyList:", JSON.stringify(oceanPyList))
|
||||||
|
// console.log("aquariusList:", JSON.stringify(aquariusList))
|
||||||
|
// console.log("providerList:", JSON.stringify(providerList))
|
||||||
|
await createOceanPyPage(createPage, 'oceanpy', oceanPyList)
|
||||||
|
|
||||||
resolve()
|
resolve()
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@ -256,3 +295,30 @@ const createSwaggerPages = async (createPage) => {
|
|||||||
console.error(error.message)
|
console.error(error.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const createOceanPyPage = async (createPage, name, list)=>{
|
||||||
|
const markdownListTemplate = path.resolve('./src/templates/MarkdownList.jsx')
|
||||||
|
createPage({
|
||||||
|
path: `/read-the-docs/${name}`,
|
||||||
|
component: markdownListTemplate,
|
||||||
|
context: {
|
||||||
|
markdownList: list,
|
||||||
|
name: name
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
list.forEach((element)=>{
|
||||||
|
createMarkdownPage(createPage, element)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const createMarkdownPage = async (createPage, element)=>{
|
||||||
|
console.log("element", JSON.stringify(element.node.frontmatter))
|
||||||
|
const markdownTemplate = path.resolve('./src/templates/MarkdownTemplate.jsx')
|
||||||
|
createPage({
|
||||||
|
path: element.node.frontmatter.slug,
|
||||||
|
component: markdownTemplate
|
||||||
|
})
|
||||||
|
}
|
16
src/templates/MarkdownList.jsx
Normal file
16
src/templates/MarkdownList.jsx
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { Link } from "gatsby"
|
||||||
|
import React from "react"
|
||||||
|
import Layout from "../components/Layout"
|
||||||
|
|
||||||
|
export default function MarkdownList({pageContext}) {
|
||||||
|
return (
|
||||||
|
<Layout>
|
||||||
|
<div>{pageContext.name}</div>
|
||||||
|
<ul>
|
||||||
|
{pageContext.markdownList.map(({node})=><li><Link to={node.frontmatter.slug}>{node.frontmatter.title}</Link></li>)}
|
||||||
|
</ul>
|
||||||
|
</Layout>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
25
src/templates/MarkdownTemplate.jsx
Normal file
25
src/templates/MarkdownTemplate.jsx
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { graphql, Link } from "gatsby"
|
||||||
|
import React from "react"
|
||||||
|
import Layout from "../components/Layout"
|
||||||
|
|
||||||
|
export default function MarkdownTemplate({data}) {
|
||||||
|
const post = data.markdownRemark
|
||||||
|
return (
|
||||||
|
<Layout>
|
||||||
|
<div dangerouslySetInnerHTML={{__html:post.html}}></div>
|
||||||
|
</Layout>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const postQuery = graphql`
|
||||||
|
query BlogPostByPath($path: String!) {
|
||||||
|
markdownRemark(frontmatter: { slug: { eq: $path } }) {
|
||||||
|
html
|
||||||
|
frontmatter {
|
||||||
|
slug
|
||||||
|
title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user