-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgridsome.server.js
64 lines (51 loc) · 1.48 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
module.exports = function (api) {
api.onCreateNode( options => {
if (options.internal.typeName === 'Item') {
// If tags aren't an array split them by ', '
options.tags = (typeof options.tags === 'string') ? options.tags.split(',').map(string => string.trim()) : options.tags;
}
if (options.internal.typeName === 'Tag') {
// To allow showing variant tags on the tag's page
if (!options.id.startsWith('variant')) {
options.variantTag = `variant:${options.id}`;
}
}
return {...options};
})
api.createPages( async ({graphql, createPage}) => {
const {data} = await graphql(`{
allItem {
edges {
node {
id
path
tags {
title
}
}
}
}
}
`);
// For every item
data.allItem.edges.forEach(function(element) {
// Allow querying post's variants
let variantTags = element.node.tags
.filter( tag=>tag.title.startsWith('variant-of:') )
.map( tag=>tag.title );
// Allow querying post's artists
let artistTags = element.node.tags
.filter( tag=>tag.title.startsWith('artist:') )
.map( tag=>tag.title );
createPage({
path: element.node.path,
component: './src/templates/SingleItem.vue',
context: {
variantTags,
artistTags,
id: element.node.id,
}
});
});
});
}