forked from DISIC/design.numerique.gouv.fr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gridsome.server.js
120 lines (104 loc) · 3.3 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
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
// 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`
module.exports = function (api) {
api.loadSource(({ addSchemaResolvers }) => {
// Use the Data Store API here: https://gridsome.org/docs/data-store-api/
addSchemaResolvers({
DiagFlashCriterion: {
rgaaStr: {
type: '[String]',
resolve(obj) {
return obj.rgaa || []
}
}
}
})
});
api.createPages(async ({ graphql, createPage }) => {
// Création manuel des pages Cours pour prendre en compte la Formation dans l'URL
const cours = await graphql(`{
allCours (filter: { publier: { eq: true }}) {
edges {
node {
id
slug
publier
formation {
slug
}
}
}
}
}`);
cours.data.allCours.edges.forEach(({ node }) => {
createPage({
path: `/formations/${node.formation.slug}/${node.slug}`,
component: './src/templates/Cours.vue',
queryVariables: { id: node.id } // use ($id: ID!) in page-query instead of $path
})
});
// Création manuel des pages Poste pour ne créer que les offres publiées
const poste = await graphql(`{
allPoste (filter: { publier: { eq: 1 }}) {
edges {
node {
id
slug
publier
}
}
}
}`);
poste.data.allPoste.edges.forEach(({ node }) => {
createPage({
path: `/recrutement/${node.slug}`,
component: './src/templates/Poste.vue',
queryVariables: { id: node.id } // use ($id: ID!) in page-query instead of $path
})
});
});
api.onCreateNode((node, collection) => {
if (node.internal.typeName === 'Cours') {
const markdownStore = collection._store.addCollection('CoursContent')
const markdownNode = markdownStore.addNode({
// any other fields, id, slug, title etc
internal: {
mimeType: 'text/markdown',
content: node.Contenu,
origin: node.id
}
})
node.content = collection._store.createReference(markdownNode)
}
if (node.internal.typeName === 'Poste') {
const markdownStore = collection._store.addCollection('PosteContent')
const markdownNode = markdownStore.addNode({
// any other fields, id, slug, title etc
internal: {
mimeType: 'text/markdown',
content: node.description,
origin: node.id
}
})
node.content = collection._store.createReference(markdownNode)
}
if (node.internal.typeName === 'Accompagnement') {
const markdownStore = collection._store.addCollection('AccompagnementContent')
const markdownNode = markdownStore.addNode({
// any other fields, id, slug, title etc
internal: {
mimeType: 'text/markdown',
content: node.Mission,
origin: node.id
},
})
node.content = collection._store.createReference(markdownNode)
// node.Experts.forEach((expert, i) => {
// node.Experts[i].slug = slugify(expert.name);
// });
}
});
}