This repository has been archived by the owner on Jun 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgridsome.server.js
93 lines (79 loc) · 2.92 KB
/
gridsome.server.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
// Server API makes it possible to hook into various parts of Gridsome
// on server-side and add custom data to the GraphQL data layer.
// Learn more: https://gridsome.org/docs/server-api/
// Changes here require a server restart.
// To restart press CTRL + C in terminal and run `gridsome develop`
const axios = require('axios')
module.exports = function (api) {
// Use the Data Store API here: https://gridsome.org/docs/data-store-api/
// Startups from Beta.gouv API
api.loadSource(async actions => {
const results = await axios.get('https://beta.gouv.fr/api/v2/startups.json')
const startups = results.data.data
const startupOverrides = actions.getCollection('Service')
const collection = actions.addCollection({
typeName: 'Startups'
})
for (const startup of startups) {
if (startup.relationships.incubator.data.id === 'anct') {
const override = startupOverrides.getNodeById(startup.id) || {}
const statusMap = {
"alumni": "partenariat passé",
"construction": "en construction",
"investigation": "en investigation"
}
collection.addNode({
id: startup.id,
name: startup.attributes.name,
pitch: startup.attributes.pitch,
beta_url: `https://beta.gouv.fr/startups/${startup.id}.html`,
service_url: startup.attributes.link,
repo_url: startup.attributes.repository,
stats_url: startup.attributes.stats_url,
contact: override.contact || startup.attributes.contact,
status: statusMap[startup.attributes.phases.slice(-1)[0].name],
startup_etat: !!override.startup_etat
})
}
}
const startupIds = startups.map(s => s.id)
const overrideIds = startupOverrides.data().map(d => d.id)
overrideIds.filter(s => !startupIds.includes(s)).forEach(id => {
const startup = startupOverrides.getNodeById(id)
collection.addNode({
id: startup.id,
name: startup.name,
pitch: startup.pitch,
beta_url: `https://beta.gouv.fr/startups/${startup.id}.html`,
service_url: startup.service_url,
repo_url: startup.repo_url,
stats_url: startup.stats_url,
contact: startup.contact,
status: startup.status,
startup_etat: !!startup.startup_etat
})
});
})
api.createPages(({ createPage }) => {
// Use the Pages API here: https://gridsome.org/docs/pages-api/
// Investigations from Directus
api.createPages(async ({ graphql, createPage }) => {
const { data } = await graphql(`{
directus {
investigations {
id
}
}
}`)
data.directus.investigations.forEach((node) => {
createPage({
path: `/investigation/${node.id}`,
component: './src/templates/Investigation.vue',
context: {
id: node.id
}
})
})
})
})
}