-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgridsome.server.js
53 lines (49 loc) · 1.45 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
module.exports = function(api) {
api.loadSource(({addCollection}) => {
// Use the Data Store API here: https://gridsome.org/docs/data-store-api/
});
api.createPages(async ({graphql, createPage}) => {
const response = await graphql(
`
{
allDoc {
edges {
node {
title
slug
order
path
content
}
}
}
}
`
);
if (response.errors) {
throw response.errors;
}
let docs = response.data.allDoc.edges.map(edge => edge.node);
docs.forEach(doc => {
let leaf = doc.path.split("/").slice(-2, -1)[0];
doc.leaf = leaf;
doc.slug = doc.slug || leaf;
createPage({
path: `/${doc.slug}`,
component: "./src/Doc.vue",
context: {
doc,
},
});
if (doc.order === 0) {
createPage({
path: `/`,
component: "./src/Doc.vue",
context: {
doc,
},
});
}
});
});
};