-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
64 lines (59 loc) · 1.72 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
const fetch = require(`node-fetch`)
//
exports.sourceNodes = async ({
actions: { createNode },
createContentDigest,
}) => {
// get photos from unsplash
const result = await fetch(
`https://api.unsplash.com/search/photos?per_page=30&query=cuba+cars&client_id=${process.env.unsplash_api_access_key}`
)
const resultData = await result.json()
// get list of countries
const countries = await fetch(`https://restcountries.com/v3.1/all`)
const listOfCountries = await countries.json()
// get raw covid data from github API
const COVIDData = await fetch(
`https://raw.githubusercontent.com/owid/covid-19-data/master/public/data/latest/owid-covid-latest.json`
)
const CubaCovidData = await COVIDData.json()
// create node for photos of Cuba
createNode({
results: resultData.results,
id: `unsplash_sosforcuba`,
parent: null,
children: [],
internal: {
type: `Unsplash`,
contentDigest: createContentDigest(resultData),
},
})
// create node for list of countries
createNode({
countries: listOfCountries,
id: `list_of_countries`,
parent: null,
children: [],
internal: {
type: `Countries`,
contentDigest: createContentDigest(listOfCountries),
},
})
// create node for COVID CUBA cases
createNode({
covid_cases_cuba: CubaCovidData,
id: `cuba_covid_cases`,
parent: null,
children: [],
internal: {
type: `CubaCOVIDCases`,
contentDigest: createContentDigest(CubaCovidData),
},
})
}
// get put this here so that no one visits the help center since donations are not needed
exports.onCreatePage = async ({ page, actions: { deletePage } }) => {
if (page.path.match(/help_center/g)) {
deletePage(page)
}
}