2018-11-28 12:19:11 +01:00
|
|
|
/* eslint-disable no-console */
|
|
|
|
|
2018-11-07 16:13:20 +01:00
|
|
|
const path = require('path')
|
|
|
|
const { createFilePath } = require('gatsby-source-filesystem')
|
2018-11-28 12:19:11 +01:00
|
|
|
const Swagger = require('swagger-client')
|
2018-11-29 10:47:42 +01:00
|
|
|
const { redirects } = require('./config')
|
2018-11-07 12:24:53 +01:00
|
|
|
|
2018-11-07 16:13:20 +01:00
|
|
|
exports.onCreateNode = ({ node, getNode, actions }) => {
|
2020-07-01 11:24:21 +02:00
|
|
|
const { createNodeField } = actions
|
2018-11-07 16:13:20 +01:00
|
|
|
|
2020-07-01 11:24:21 +02:00
|
|
|
if (node.internal.type === 'MarkdownRemark') {
|
|
|
|
const fileNode = getNode(node.parent)
|
|
|
|
const parsedFilePath = path.parse(fileNode.relativePath)
|
2018-11-14 15:17:19 +01:00
|
|
|
|
2020-07-01 11:24:21 +02:00
|
|
|
let slug = createFilePath({ node, getNode, basePath: 'content' })
|
|
|
|
let section = parsedFilePath.dir
|
2018-11-14 15:17:19 +01:00
|
|
|
|
2020-07-01 11:24:21 +02:00
|
|
|
if (node.frontmatter.slug) {
|
|
|
|
;({ slug } = node.frontmatter)
|
|
|
|
}
|
2018-11-14 15:17:19 +01:00
|
|
|
|
2020-07-01 11:24:21 +02:00
|
|
|
if (node.frontmatter.section) {
|
|
|
|
;({ section } = node.frontmatter)
|
|
|
|
}
|
2018-11-07 16:13:20 +01:00
|
|
|
|
2020-07-01 11:24:21 +02:00
|
|
|
createNodeField({
|
|
|
|
node,
|
|
|
|
name: 'slug',
|
|
|
|
value: slug
|
|
|
|
})
|
2018-11-07 16:13:20 +01:00
|
|
|
|
2020-07-01 11:24:21 +02:00
|
|
|
createNodeField({
|
|
|
|
node,
|
|
|
|
name: 'section',
|
|
|
|
value: section
|
|
|
|
})
|
|
|
|
}
|
2018-11-07 16:13:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.createPages = ({ graphql, actions }) => {
|
2020-07-01 11:24:21 +02:00
|
|
|
const { createPage, createRedirect } = actions
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
resolve(
|
|
|
|
graphql(
|
|
|
|
`
|
|
|
|
query {
|
|
|
|
allMarkdownRemark(
|
|
|
|
filter: { fileAbsolutePath: { regex: "/content/" } }
|
|
|
|
) {
|
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
fields {
|
|
|
|
slug
|
|
|
|
section
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-14 13:00:32 +01:00
|
|
|
|
2021-04-12 11:19:11 +02:00
|
|
|
allRepoMarkdown: allMarkdownRemark(
|
2021-04-20 15:44:23 +02:00
|
|
|
filter: { fileAbsolutePath: { regex: "/markdowns/markdowns/" } }
|
2021-04-12 11:19:11 +02:00
|
|
|
) {
|
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
id
|
|
|
|
html
|
|
|
|
htmlAst
|
|
|
|
tableOfContents
|
|
|
|
frontmatter {
|
2021-05-24 17:11:41 +02:00
|
|
|
slug
|
2021-05-24 01:40:02 +02:00
|
|
|
source
|
2021-04-12 11:19:11 +02:00
|
|
|
title
|
2021-04-22 11:41:32 +02:00
|
|
|
app
|
2021-04-21 20:25:49 +02:00
|
|
|
module
|
2021-04-10 17:08:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-12 11:19:11 +02:00
|
|
|
}
|
2021-04-10 17:08:14 +02:00
|
|
|
|
2020-11-12 16:37:49 +01:00
|
|
|
oceanJs: github {
|
|
|
|
repository(name: "ocean.js", owner: "oceanprotocol") {
|
|
|
|
name
|
|
|
|
releases(
|
|
|
|
first: 30
|
|
|
|
orderBy: { field: CREATED_AT, direction: DESC }
|
|
|
|
) {
|
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
isPrerelease
|
|
|
|
isDraft
|
2020-11-12 18:31:18 +01:00
|
|
|
releaseAssets(first: 1, name: "lib.json") {
|
2020-11-12 16:37:49 +01:00
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
name
|
|
|
|
downloadUrl
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-07-01 11:24:21 +02:00
|
|
|
}
|
|
|
|
`
|
|
|
|
).then(async (result) => {
|
|
|
|
if (result.errors) {
|
|
|
|
console.log(result.errors)
|
|
|
|
reject(result.errors)
|
|
|
|
}
|
2018-11-07 16:13:20 +01:00
|
|
|
|
2020-07-01 11:24:21 +02:00
|
|
|
const docTemplate = path.resolve('./src/templates/Doc.jsx')
|
|
|
|
const posts = result.data.allMarkdownRemark.edges
|
2021-04-12 11:19:11 +02:00
|
|
|
|
2020-07-01 11:24:21 +02:00
|
|
|
//
|
|
|
|
// Create Doc pages
|
|
|
|
//
|
|
|
|
posts.forEach((post) => {
|
|
|
|
createPage({
|
|
|
|
path: `${post.node.fields.slug}`,
|
|
|
|
component: docTemplate,
|
|
|
|
context: {
|
|
|
|
slug: post.node.fields.slug,
|
|
|
|
section: post.node.fields.section
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
// API: brizo, aquarius
|
|
|
|
await createSwaggerPages(createPage)
|
|
|
|
|
2020-11-12 16:37:49 +01:00
|
|
|
// API: ocean.js
|
2021-05-25 14:07:51 +02:00
|
|
|
const lastRelease =
|
|
|
|
result.data.oceanJs.repository.releases.edges.filter(
|
|
|
|
({ node }) => !node.isPrerelease && !node.isDraft
|
|
|
|
)[0].node.releaseAssets.edges[0].node
|
2020-11-12 18:31:18 +01:00
|
|
|
|
2020-11-12 16:37:49 +01:00
|
|
|
await createTypeDocPage(
|
|
|
|
createPage,
|
|
|
|
result.data.oceanJs.repository.name,
|
|
|
|
lastRelease.downloadUrl
|
|
|
|
)
|
2020-11-12 18:31:18 +01:00
|
|
|
|
2020-07-01 11:24:21 +02:00
|
|
|
//
|
|
|
|
// create redirects
|
|
|
|
//
|
|
|
|
redirects.forEach(({ from, to }) => {
|
|
|
|
createRedirect({
|
|
|
|
fromPath: from,
|
|
|
|
redirectInBrowser: true,
|
|
|
|
toPath: to
|
|
|
|
})
|
|
|
|
|
|
|
|
console.log('Create redirect: ' + from + ' --> ' + to)
|
|
|
|
})
|
|
|
|
|
2021-04-10 17:08:14 +02:00
|
|
|
const markdowns = result.data.allRepoMarkdown.edges
|
2021-04-21 20:25:49 +02:00
|
|
|
const oceanPyList = filterMarkdownList(markdowns, 'ocean.py')
|
|
|
|
const aquariusList = filterMarkdownList(markdowns, 'aquarius')
|
|
|
|
const providerList = filterMarkdownList(markdowns, 'provider')
|
2021-04-10 18:11:58 +02:00
|
|
|
|
2021-04-11 16:47:04 +02:00
|
|
|
await createReadTheDocsPage(createPage, 'ocean-py', oceanPyList)
|
2021-04-11 12:15:26 +02:00
|
|
|
await createReadTheDocsPage(createPage, 'aquarius', aquariusList)
|
|
|
|
await createReadTheDocsPage(createPage, 'provider', providerList)
|
2021-04-10 18:11:58 +02:00
|
|
|
|
2020-07-01 11:24:21 +02:00
|
|
|
resolve()
|
|
|
|
})
|
|
|
|
)
|
|
|
|
})
|
2018-11-07 16:13:20 +01:00
|
|
|
}
|
2019-06-24 20:48:45 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Create pages from TypeDoc json files
|
|
|
|
//
|
|
|
|
const createTypeDocPage = async (createPage, name, downloadUrl) => {
|
2020-07-01 11:24:21 +02:00
|
|
|
try {
|
|
|
|
const typedoc = await fetch(downloadUrl)
|
|
|
|
const typedocTemplate = path.resolve('./src/templates/Typedoc/index.jsx')
|
|
|
|
const slug = `/references/${name}/`
|
2019-06-24 20:48:45 +02:00
|
|
|
|
2020-07-01 11:24:21 +02:00
|
|
|
createPage({
|
|
|
|
path: slug,
|
|
|
|
component: typedocTemplate,
|
|
|
|
context: {
|
|
|
|
slug,
|
|
|
|
typedoc: await typedoc.json(),
|
|
|
|
// We define the classes here so the data object passed as page context
|
|
|
|
// is as small as possible.
|
|
|
|
// Caveat: no live update during development when these values are changed.
|
|
|
|
//
|
|
|
|
// TODO: defining these classes for inclusion
|
|
|
|
// needs to be handled somewhere else to keep
|
|
|
|
// it generic for all TypeDoc specs
|
|
|
|
classes: [
|
|
|
|
'ocean/Ocean',
|
2020-11-14 00:02:26 +01:00
|
|
|
'ocean/Account',
|
|
|
|
'ocean/Assets',
|
|
|
|
'ocean/Compute',
|
|
|
|
'ocean/Versions',
|
2020-07-01 11:24:21 +02:00
|
|
|
'ocean/DID',
|
|
|
|
'ddo/DDO',
|
2020-11-14 00:02:26 +01:00
|
|
|
'metadatacache/MetadataCache',
|
|
|
|
'metadatacache/OnChainMetaDataCache',
|
|
|
|
'provider/Provider',
|
|
|
|
'datatokens/Datatokens',
|
|
|
|
'datatokens/Network',
|
|
|
|
'datatokens/Web3Provider',
|
|
|
|
'balancer/OceanPool',
|
|
|
|
'balancer/Pool',
|
|
|
|
'balancer/PoolFactory',
|
|
|
|
'exchange/FixedRateExchange',
|
2020-07-01 11:24:21 +02:00
|
|
|
'models/Config',
|
2020-11-14 00:02:26 +01:00
|
|
|
'utils/ConfigHelper',
|
|
|
|
'utils/GasUtils',
|
2020-07-01 11:24:21 +02:00
|
|
|
'ocean/utils/OceanUtils',
|
|
|
|
'ocean/utils/WebServiceConnector',
|
|
|
|
'utils/Logger'
|
|
|
|
]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} catch (error) {
|
|
|
|
console.log(error.message)
|
|
|
|
}
|
2019-06-24 20:48:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Create pages from swagger json files
|
|
|
|
//
|
|
|
|
// https://github.com/swagger-api/swagger-js
|
2020-11-14 00:43:06 +01:00
|
|
|
const fetchSwaggerSpec = async (component) => {
|
2020-07-01 11:24:21 +02:00
|
|
|
try {
|
|
|
|
const client = await Swagger(
|
2020-11-14 00:43:06 +01:00
|
|
|
`https://${component}.mainnet.oceanprotocol.com/spec`
|
2020-07-01 11:24:21 +02:00
|
|
|
)
|
|
|
|
return client.spec // The resolved spec
|
|
|
|
|
|
|
|
// client.originalSpec // In case you need it
|
|
|
|
// client.errors // Any resolver errors
|
|
|
|
|
|
|
|
// Tags interface
|
|
|
|
// client.apis.pet.addPet({id: 1, name: "bobby"}).then(...)
|
|
|
|
|
|
|
|
// TryItOut Executor, with the `spec` already provided
|
|
|
|
// client.execute({operationId: 'addPet', parameters: {id: 1, name: "bobby") }).then(...)
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error.message)
|
|
|
|
}
|
2019-06-24 20:48:45 +02:00
|
|
|
}
|
|
|
|
|
2020-03-24 09:04:30 +01:00
|
|
|
const createSwaggerPages = async (createPage) => {
|
2020-11-14 00:43:06 +01:00
|
|
|
const swaggerComponents = ['aquarius', 'provider']
|
2020-07-01 11:24:21 +02:00
|
|
|
const apiSwaggerTemplate = path.resolve('./src/templates/Swagger/index.jsx')
|
|
|
|
|
2020-11-14 00:43:06 +01:00
|
|
|
const getSlug = (name) => `/references/${name}/`
|
2020-07-01 11:24:21 +02:00
|
|
|
|
2020-11-14 00:43:06 +01:00
|
|
|
for (const component of swaggerComponents) {
|
|
|
|
const slug = getSlug(component)
|
2020-07-01 11:24:21 +02:00
|
|
|
|
2020-11-14 00:43:06 +01:00
|
|
|
createPage({
|
|
|
|
path: slug,
|
|
|
|
component: apiSwaggerTemplate,
|
|
|
|
context: {
|
|
|
|
slug,
|
|
|
|
name: component,
|
|
|
|
api: await fetchSwaggerSpec(component)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2020-07-01 11:24:21 +02:00
|
|
|
|
|
|
|
// Swagger Pet Store example
|
|
|
|
const petStoreSlug = '/references/petstore/'
|
2019-06-24 20:48:45 +02:00
|
|
|
|
2020-07-01 11:24:21 +02:00
|
|
|
try {
|
|
|
|
const client = await Swagger(`http://petstore.swagger.io/v2/swagger.json`)
|
2019-06-24 20:48:45 +02:00
|
|
|
|
|
|
|
createPage({
|
2020-07-01 11:24:21 +02:00
|
|
|
path: petStoreSlug,
|
|
|
|
component: apiSwaggerTemplate,
|
|
|
|
context: {
|
|
|
|
slug: petStoreSlug,
|
|
|
|
api: client.spec
|
|
|
|
}
|
2019-06-24 20:48:45 +02:00
|
|
|
})
|
2020-07-01 11:24:21 +02:00
|
|
|
} catch (error) {
|
|
|
|
console.error(error.message)
|
|
|
|
}
|
2019-06-24 20:48:45 +02:00
|
|
|
}
|
2021-04-10 17:08:14 +02:00
|
|
|
|
2021-04-12 11:19:11 +02:00
|
|
|
const createReadTheDocsPage = async (createPage, name, list) => {
|
2021-05-18 21:23:46 +02:00
|
|
|
const markdownListTemplate = path.resolve(
|
|
|
|
'./src/templates/Markdown/MarkdownList.jsx'
|
|
|
|
)
|
2021-04-10 17:08:14 +02:00
|
|
|
createPage({
|
|
|
|
path: `/read-the-docs/${name}`,
|
2021-05-24 17:11:41 +02:00
|
|
|
matchPath: `/read-the-docs/${name}/*`,
|
2021-04-10 17:08:14 +02:00
|
|
|
component: markdownListTemplate,
|
|
|
|
context: {
|
|
|
|
markdownList: list,
|
2021-05-24 17:11:41 +02:00
|
|
|
name: name,
|
|
|
|
baseUrl: `/read-the-docs/${name}`
|
2021-04-10 17:08:14 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-04-12 11:19:11 +02:00
|
|
|
const filterMarkdownList = (markdownList, string) => {
|
2021-04-22 11:41:32 +02:00
|
|
|
return markdownList.filter(({ node }) => node.frontmatter.app === string)
|
2021-04-12 11:19:11 +02:00
|
|
|
}
|