-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
129 lines (119 loc) · 3.04 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
const path = require('path')
const linkResolver = require('./src/utils/linkResolver').linkResolver
exports.createPages = async ({ actions, graphql }) => {
const { createPage, createRedirect } = actions
const domainQuery = await graphql(`
query domain {
site {
siteMetadata {
domain
}
}
}
`)
const domainTag = `domain:${domainQuery.data?.site.siteMetadata.domain}`
// Query all Pages with their IDs and template data.
const pages = await graphql(
`
query Pages($domainTag: String!) {
allPrismicPage(filter: { tags: { eq: $domainTag } }) {
nodes {
id
uid
url
tags
type
data {
parent_page {
url
uid
type
link_type
}
}
}
}
}
`,
{ domainTag: domainTag }
)
// Create pages for each Page in Prismic using the selected template.
pages.data?.allPrismicPage.nodes.forEach((node) => {
// console.log('gatby-node', node.uid)
const url = linkResolver(node)
// const fullPath =
// node.data.parent_page.uid === null
// ? node.uid === 'home'
// ? '/'
// : `/${node.uid}`
// : `/${node.data.parent_page.uid}/${node.uid}`
createPage({
path: url,
component: path.resolve(__dirname, 'src/pages/page.tsx'),
context: {
uid: node.uid,
domainTag: domainTag,
},
})
})
const redirects = await graphql(
`
query Redirects($domainTag: String!) {
allPrismicRedirect(filter: { tags: { eq: $domainTag } }) {
nodes {
url
uid
type
data {
page_title
permanent
destination {
link_type
url
type
uid
}
}
}
}
}
`,
{ domainTag: domainTag }
)
redirects.data?.allPrismicRedirect.nodes.forEach((node) => {
// if (node.data && node.data.destination) {
// const url = linkResolver(node)
createRedirect({
fromPath: `/${node.uid}`,
isPermanent: node.data.permanent || true,
toPath: node.url,
redirectInBrowser: true,
})
createRedirect({
fromPath: `/${node.uid.toUpperCase()}`,
isPermanent: node.data.permanent || true,
toPath: node.url,
redirectInBrowser: true,
})
// } else {
// console.error('node', node.uid)
// }
})
}
exports.createSchemaCustomization = ({ actions, schema }) => {
const { createTypes } = actions
const { buildObjectType } = schema
// List known embed fields. Any unknown fields will still be inferred.
const PrismicEmbedType = buildObjectType({
name: 'PrismicEmbedType',
fields: {
height: 'Int',
embed_url: 'String',
thumbnail_url: 'String',
title: 'String',
type: 'String',
width: 'Int',
},
})
createTypes(PrismicEmbedType)
}