-
Notifications
You must be signed in to change notification settings - Fork 1
/
gatsby-node.ts
67 lines (57 loc) · 1.75 KB
/
gatsby-node.ts
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
import { GatsbyNode } from 'gatsby'
import * as path from 'path'
import simplifyForUrl from './src/utilities/simplifyForUrl'
export const createPages: GatsbyNode['createPages'] = async ({
actions,
graphql,
}) => {
const stakeholderPageTemplate = path.resolve(
'./src/templates/stakeholder.tsx'
)
const stakeholdersQuery = await graphql<Queries.StakeholdersQuery>(`
query Stakeholders {
stakeholders: allStakeholdersCsv {
nodes {
slug
name
iso3
}
}
}
`)
if (!stakeholdersQuery.data?.stakeholders.nodes)
throw new Error('No countries found to publish')
for (const stakeholder of stakeholdersQuery.data.stakeholders.nodes) {
if (!stakeholder.name) throw new Error(`All stakeholders must have a name`)
actions.createPage({
path: `/${stakeholder.slug}/${simplifyForUrl(stakeholder.name)}`,
component: stakeholderPageTemplate,
context: { name: stakeholder.name, iso3: stakeholder.iso3 },
})
}
const pheicsQuery = await graphql<Queries.PheicsQuery>(`
query Pheics {
pheics: allAirtable(filter: { table: { eq: "PHEIC" } }) {
nodes {
data {
PHEIC_name
PHEIC_database_name
}
}
}
}
`)
if (!pheicsQuery.data?.pheics.nodes)
throw new Error('No PHEICs found to publish')
for (const pheic of pheicsQuery.data.pheics.nodes) {
if (!pheic.data.PHEIC_name) throw new Error(`All PHEICs must have a name`)
actions.createPage({
path: `/pheic/${simplifyForUrl(pheic.data.PHEIC_name)}`,
component: path.resolve('./src/templates/pheic.tsx'),
context: {
name: pheic.data.PHEIC_name,
database_name: pheic.data.PHEIC_database_name,
},
})
}
}