-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
132 lines (114 loc) · 2.86 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
const path = require(`path`)
exports.createPages = async ({ graphql, actions, reporter }) => {
const postTemplate = path.resolve(`./src/templates/post.js`)
const pageTemplate = path.resolve(`./src/templates/page.js`)
const tagTemplate = path.resolve(`./src/templates/tag.js`)
const result = await graphql(`
{
allGhostPost {
edges {
node {
slug
primary_tag {
slug
}
}
}
}
allGhostPage {
edges {
node {
slug
}
}
}
allGhostTag {
edges {
node {
slug
}
}
}
}
`)
if (result.errors) {
reporter.panicOnBuild(`Error whilst running GraphQL query.`)
}
if (result.data.allGhostPost && result.data.allGhostPost.edges.length > 0) {
const posts = result.data.allGhostPost.edges
posts.forEach(({ node }) => {
node.url = `/${node.slug}/`
actions.createPage({
path: node.url,
component: postTemplate,
context: {
post_slug: node.slug,
primary_tag_slug: node.primary_tag ? node.primary_tag.slug : null,
},
})
})
}
if (result.data.allGhostPage && result.data.allGhostPage.edges.length > 0) {
const pages = result.data.allGhostPage.edges
pages.forEach(({ node }) => {
node.url = `/${node.slug}/`
actions.createPage({
path: node.url,
component: pageTemplate,
context: {
page_slug: node.slug,
},
})
})
}
if (result.data.allGhostTag && result.data.allGhostTag.edges.length > 0) {
const tags = result.data.allGhostTag.edges
tags.forEach(({ node }) => {
node.url = `/tag/${node.slug}/`
actions.createPage({
path: node.url,
component: tagTemplate,
context: {
tag_slug: node.slug,
},
})
})
}
}
exports.createSchemaCustomization = ({ actions }) => {
const { createTypes } = actions
createTypes(`
type GhostPage implements Node {
childHtmlRehype: HTMLRehype
featureImageSharp: File @link
twitterImageSharp: File @link
ogImageSharp: File @link
}
type GhostPost implements Node {
childHtmlRehype: HTMLRehype
featureImageSharp: File @link
twitterImageSharp: File @link
ogImageSharp: File @link
}
type GhostTag implements Node {
featureImageSharp: File @link
}
type GhostSettings implements Node {
coverImageSharp: File @link
twitterImageSharp: File @link
ogImageSharp: File @link
logoSharp: File @link
iconSharp: File @link
}
type HTMLRehype implements Node {
html: String!
htmlAst: String!
id: ID!
tableOfContents: [TableOfContents]
}
type TableOfContents {
id: ID!
heading: String!
}
`)
}