forked from gatsbyjs/homepage-starters
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
175 lines (160 loc) · 4.06 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
const path = require("path")
const localPlugins = [
"contentful-plugin",
"datocms-plugin",
"drupal-plugin",
"sanity-plugin",
"wordpress-plugin",
]
// for theming development
exports.onCreateWebpackConfig = ({ actions, store }) => {
// redux state to check which plugin is used
const state = store.getState()
const plugins = state.config.plugins.map((plugin) => plugin.resolve)
const plugin = plugins.reduce((a, b) => {
if (a) return a
if (localPlugins.includes(b)) return b
return null
}, null)
// skip creating an alias if it hasn't been included in the list above
if (!plugin) return
actions.setWebpackConfig({
resolve: {
alias: {
"./colors.css": path.resolve(
__dirname,
"plugins",
plugin,
"src",
"colors.css"
),
"./brand-logo": path.resolve(
__dirname,
"plugins",
plugin,
"src",
"components",
"brand-logo.js"
),
},
},
})
if (plugin == "wordpress-plugin") {
actions.setWebpackConfig({
resolve: {
alias: {
// WordPress uses a hard-coded header & footer
"./header": path.resolve(
__dirname,
"plugins",
plugin,
"src",
"components",
"header.tsx"
),
"./header.css": path.resolve(
__dirname,
"src",
"components",
"header.css"
),
"./footer": path.resolve(
__dirname,
"plugins",
plugin,
"src",
"components",
"footer.tsx"
),
"./ui": path.resolve(__dirname, "src", "components", "ui.tsx"),
},
},
})
}
}
// WordPress does not use layout types and uses
// a custom header and footer with hard-coded values.
// This is a shim to prevent errors in the development repo
exports.createSchemaCustomization = async ({ actions, store }) => {
const state = store.getState()
const plugins = state.config.plugins.map((plugin) => plugin.resolve)
if (!plugins.includes("wordpress-plugin")) return
actions.createTypes(/* GraphQL */ `
interface HeaderNavItem implements Node {
id: ID!
originalId: String
navItemType: String
}
type NavItem implements Node & HeaderNavItem {
id: ID!
originalId: String
navItemType: String
href: String
text: String
icon: HomepageImage @link
description: String
}
type NavItemGroup implements Node & HeaderNavItem {
id: ID!
originalId: String
navItemType: String
name: String
navItems: [NavItem] @link(by: "originalId")
}
type LayoutHeader implements Node {
id: ID!
layoutType: String
navItems: [HeaderNavItem] @link(by: "originalId")
cta: HomepageLink @link
}
enum SocialService {
TWITTER
FACEBOOK
INSTAGRAM
YOUTUBE
LINKEDIN
GITHUB
DISCORD
TWITCH
}
type SocialLink implements Node {
id: ID!
username: String!
service: SocialService!
}
type LayoutFooter implements Node {
id: ID!
layoutType: String
links: [HomepageLink] @link
meta: [HomepageLink] @link
socialLinks: [SocialLink] @link(by: "originalId")
copyright: String
}
type Layout implements Node {
id: ID!
header: LayoutHeader @link(by: "layoutType")
footer: LayoutFooter @link(by: "layoutType")
}
`)
}
// WordPress does not include the about page
// This type is to shim the GraphQL layer for development
exports.sourceNodes = ({
actions,
store,
createNodeId,
createContentDigest,
}) => {
const state = store.getState()
const plugins = state.config.plugins.map((plugin) => plugin.resolve)
if (!plugins.includes("wordpress-plugin")) return
actions.createNode({
id: createNodeId(`Shim AboutPage`),
internal: {
type: "AboutPage",
contentDigest: createContentDigest(""),
},
title: "About",
content: [],
})
}