Skip to content

Commit

Permalink
fix(gatsby-theme-docz): create pages hook
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Mar 18, 2019
1 parent b0409a8 commit 2f5765e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
1 change: 0 additions & 1 deletion core/gatsby-theme-docz/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"remark-docz": "^0.13.3",
"remark-frontmatter": "^1.3.1",
"styled-components": "^4.1.3",
"ulid": "^2.3.0",
"yargs": "^13.2.2"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion core/gatsby-theme-docz/src/node/createPages.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path')
const { getDoczConfig } = require('../utils/parseConfig')
const { get } = require('lodash/fp')

const mountRoute = (base = '/', route) => {
return `${base === '/' ? '' : base}${route}`
Expand Down Expand Up @@ -32,7 +33,7 @@ module.exports = ({ graphql, actions }, opts) => {

return graphql(ENTRIES_QUERY).then(({ data, errors }) => {
const hasErrors = errors && errors.length > 0
const entries = data && data.allDoczEntries.edges
const entries = get('allDoczEntries.edges', data)
if (!entries || entries.length === 0 || hasErrors) return

entries.forEach(({ node: entry }) => {
Expand Down
20 changes: 11 additions & 9 deletions core/gatsby-theme-docz/src/node/sourceNodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ module.exports = async ({ actions, createNodeId }, opts) => {
})
}

const createEntriesNodes = payload => {
const values = Array.isArray(payload) ? payload : []
values.forEach(({ value: entry }) => {
const createEntriesNodes = async payload => {
const map = await entries.get()
const values = Object.entries(map)

values.forEach(([key, entry]) => {
if (!entry) return null
const contentDigest = digest(JSON.stringify(entry))
createNode({
...entry,
Expand All @@ -59,12 +62,11 @@ module.exports = async ({ actions, createNodeId }, opts) => {
})
}

const createStateNodes = async ({ type, payload }) => {
if (type === 'state.entries') createEntriesNodes(payload)
const createNodes = async () => {
await createDbNode()
await createEntriesNodes()
}

dataServer.onStateChange(async state => {
await createDbNode()
await createStateNodes(state)
})
await createNodes()
dataServer.onStateChange(createNodes)
}

0 comments on commit 2f5765e

Please sign in to comment.