2020-07-01 17:11:45 +02:00
|
|
|
const path = require('path')
|
|
|
|
// const { config } = require('./src/config/ocean')
|
|
|
|
|
2020-06-30 13:32:16 +02:00
|
|
|
exports.onCreateWebpackConfig = ({ actions }) => {
|
|
|
|
actions.setWebpackConfig({
|
|
|
|
node: {
|
|
|
|
// 'fs' fix for squid.js
|
|
|
|
fs: 'empty'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2020-07-01 17:11:45 +02:00
|
|
|
|
2020-07-07 09:27:05 +02:00
|
|
|
exports.createPages = async ({ graphql, actions }) => {
|
2020-07-01 17:11:45 +02:00
|
|
|
const { createPage } = actions
|
2020-07-07 09:27:05 +02:00
|
|
|
|
|
|
|
// Create pages for all assets
|
|
|
|
const assetDetailsTemplate = path.resolve(
|
2020-07-07 09:43:45 +02:00
|
|
|
'src/components/templates/AssetDetails.tsx'
|
2020-07-01 17:11:45 +02:00
|
|
|
)
|
|
|
|
|
2020-07-07 09:27:05 +02:00
|
|
|
const result = await graphql(`
|
|
|
|
query {
|
2020-07-07 09:55:20 +02:00
|
|
|
allOceanAsset {
|
2020-07-07 09:27:05 +02:00
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
did
|
|
|
|
main {
|
|
|
|
type
|
|
|
|
name
|
|
|
|
dateCreated
|
|
|
|
author
|
|
|
|
license
|
|
|
|
price
|
|
|
|
datePublished
|
|
|
|
files {
|
|
|
|
contentType
|
|
|
|
index
|
|
|
|
}
|
|
|
|
}
|
|
|
|
additionalInformation {
|
|
|
|
description
|
|
|
|
deliveryType
|
|
|
|
termsAndConditions
|
|
|
|
access
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2020-07-01 17:11:45 +02:00
|
|
|
if (result.errors) {
|
2020-07-07 09:27:05 +02:00
|
|
|
throw result.errors
|
2020-07-01 17:11:45 +02:00
|
|
|
}
|
|
|
|
|
2020-07-07 09:55:20 +02:00
|
|
|
await result.data.allOceanAsset.edges.forEach(({ node }) => {
|
2020-07-07 09:27:05 +02:00
|
|
|
const path = `/asset/${node.did}`
|
2020-07-06 12:49:30 +02:00
|
|
|
|
2020-07-07 09:27:05 +02:00
|
|
|
createPage({
|
2020-07-01 17:11:45 +02:00
|
|
|
path,
|
|
|
|
component: assetDetailsTemplate,
|
2020-07-07 09:27:05 +02:00
|
|
|
context: { did: node.did }
|
2020-07-01 17:11:45 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2020-07-06 12:49:30 +02:00
|
|
|
|
2020-07-07 10:26:38 +02:00
|
|
|
exports.onCreatePage = async ({ page, actions }) => {
|
|
|
|
const { createPage } = actions
|
|
|
|
// page.matchPath is a special key that's used for matching pages
|
|
|
|
// only on the client.
|
|
|
|
const handleClientSideOnly = page.path.match(/^\/asset/)
|
2020-07-06 12:49:30 +02:00
|
|
|
|
2020-07-07 10:26:38 +02:00
|
|
|
if (handleClientSideOnly) {
|
|
|
|
page.matchPath = '/asset/*'
|
2020-07-06 12:49:30 +02:00
|
|
|
|
2020-07-07 10:26:38 +02:00
|
|
|
// Update the page.
|
|
|
|
createPage(page)
|
|
|
|
}
|
|
|
|
}
|