Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit 2f5765e

Browse files
committed
fix(gatsby-theme-docz): create pages hook
1 parent b0409a8 commit 2f5765e

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

core/gatsby-theme-docz/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
"remark-docz": "^0.13.3",
4343
"remark-frontmatter": "^1.3.1",
4444
"styled-components": "^4.1.3",
45-
"ulid": "^2.3.0",
4645
"yargs": "^13.2.2"
4746
},
4847
"devDependencies": {

core/gatsby-theme-docz/src/node/createPages.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const path = require('path')
22
const { getDoczConfig } = require('../utils/parseConfig')
3+
const { get } = require('lodash/fp')
34

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

3334
return graphql(ENTRIES_QUERY).then(({ data, errors }) => {
3435
const hasErrors = errors && errors.length > 0
35-
const entries = data && data.allDoczEntries.edges
36+
const entries = get('allDoczEntries.edges', data)
3637
if (!entries || entries.length === 0 || hasErrors) return
3738

3839
entries.forEach(({ node: entry }) => {

core/gatsby-theme-docz/src/node/sourceNodes.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ module.exports = async ({ actions, createNodeId }, opts) => {
4242
})
4343
}
4444

45-
const createEntriesNodes = payload => {
46-
const values = Array.isArray(payload) ? payload : []
47-
values.forEach(({ value: entry }) => {
45+
const createEntriesNodes = async payload => {
46+
const map = await entries.get()
47+
const values = Object.entries(map)
48+
49+
values.forEach(([key, entry]) => {
50+
if (!entry) return null
4851
const contentDigest = digest(JSON.stringify(entry))
4952
createNode({
5053
...entry,
@@ -59,12 +62,11 @@ module.exports = async ({ actions, createNodeId }, opts) => {
5962
})
6063
}
6164

62-
const createStateNodes = async ({ type, payload }) => {
63-
if (type === 'state.entries') createEntriesNodes(payload)
65+
const createNodes = async () => {
66+
await createDbNode()
67+
await createEntriesNodes()
6468
}
6569

66-
dataServer.onStateChange(async state => {
67-
await createDbNode()
68-
await createStateNodes(state)
69-
})
70+
await createNodes()
71+
dataServer.onStateChange(createNodes)
7072
}

0 commit comments

Comments
 (0)