-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
95 lines (80 loc) · 2.81 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
exports.onCreateNode = async ({node, cache, actions: {createNodeField}}) => {
if (node.internal.type === "GoogleMyMaps") {
await cache.set("mymaps-" + node.name, node.id)
await cache.set("polyline-" + node.name, node.polyline)
}
if (node.internal.type === "YoutubeVideo") {
if (node.country) {
const videos = (await cache.get("videos-" + node.country)) || []
await cache.set("videos-" + node.country, [...videos, node.id])
}
if (node.country && node.region) {
const videos = (await cache.get("videos-" + node.region)) || []
await cache.set("videos-" + node.region, [...videos, node.id])
}
}
if (node.internal.type === "GooglePhotosAlbum") {
if (node.category === "travel" && node.country && !node.region) {
await cache.set("album-" + node.country, node.id)
}
if (node.category === "travel" && node.country && node.region) {
await cache.set("album-" + node.country, node.id)
await cache.set("album-" + node.region, node.id)
}
}
if (node.internal.type === "GoogleDocs") {
if (node.template === "travel-region" && node.region) {
const album = await cache.get("album-" + node.region)
const videos = await cache.get("videos-" + node.region)
createNodeField({node, name: "albumId", value: album})
createNodeField({node, name: "videosIds", value: videos})
}
if (node.template === "travel-country" && node.country) {
const album = await cache.get("album-" + node.country)
const videos = await cache.get("videos-" + node.country)
createNodeField({node, name: "albumId", value: album})
createNodeField({node, name: "videosIds", value: videos})
}
if (node.template === "travel-story" && node.country) {
const polyline = await cache.get("polyline-" + node.country)
const map = await cache.get("mymaps-" + node.country)
node.polyline = polyline
createNodeField({node, name: "mapId", value: map})
}
}
}
exports.createSchemaCustomization = ({actions}) => {
const {createTypes} = actions
createTypes(`
type GoogleDocs implements Node {
id: ID!
map: GoogleMyMaps @link(from: "fields.mapId")
album: GooglePhotosAlbum @link(from: "fields.albumId")
videos: [YoutubeVideo] @link(from: "fields.videosIds")
}
`)
}
// type GooglePhotosPhoto implements Node {
// id: ID!
// description: String
// file: File @link
// }
// type GooglePhotosAlbum implements Node {
// id: ID!
// country: String
// region: String
// category: String
// photos: [GooglePhotosPhoto]
// latestDate(
// formatString: String
// fromNow: Boolean
// difference: String
// locale: String
// ): Date
// cover: GooglePhotosPhoto
// }
exports.onCreatePage = ({page}) => {
if (page.path.match(/^\/resume/)) {
page.context.layout = "blank"
}
}