-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathgatsby-node.js
67 lines (58 loc) · 1.66 KB
/
gatsby-node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const path = require(`path`)
const glob = require(`glob`)
const createBlog = require(`./create/createBlog`)
const createContentTypes = require(`./create/createContentTypes`)
const createCategories = require(`./create/createCategories`)
const createAuthors = require(`./create/createAuthors`)
const getTemplates = () => {
const sitePath = path.resolve(`./`)
return glob.sync(`./src/templates/**/*.js`, { cwd: sitePath })
}
exports.createPages = async (props) => {
const { data: wpSettings } = await props.graphql(/* GraphQL */ `
{
wp {
readingSettings {
postsPerPage
}
}
}
`)
const perPage = wpSettings.wp.readingSettings.postsPerPage || 10
const blogURI = "/"
const templates = getTemplates()
await createContentTypes(props, { templates })
await createBlog(props, { perPage, blogURI })
await createCategories(props, { perPage })
await createAuthors(props, { perPage })
}
const { createRemoteFileNode } = require(`gatsby-source-filesystem`)
// We do this, because the Avatar doesn't get handled as a File from the gatsby-source plugin yet. This might change in the future.
exports.createResolvers = async ({
actions,
cache,
createNodeId,
createResolvers,
store,
reporter,
}) => {
const { createNode } = actions
await createResolvers({
WpAvatar: {
imageFile: {
type: "File",
async resolve(source) {
let sourceUrl = source.url
return await createRemoteFileNode({
url: encodeURI(sourceUrl),
store,
cache,
createNode,
createNodeId,
reporter,
})
},
},
},
})
}