-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgridsome.server.js
executable file
·55 lines (46 loc) · 1.39 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
const path = require('path')
const fs = require('fs-extra')
const execa = require('execa')
const yaml = require('js-yaml')
module.exports = function (api) {
api.loadSource(async store => {
let gridsomeVersion = ''
try {
const { stdout } = await execa('npm', ['show', 'gridsome', 'version'])
gridsomeVersion = stdout
} catch (err) {
console.warn('Failed to get gridsome version from npm.')
}
store.addMetaData('gridsomeVersion', gridsomeVersion)
// Fake plugin node. TODO: Will be replaced with client side routes
store
.addContentType({
typeName: 'Plugin',
route: '/plugins/:id*'
})
.addNode({ id: '1' })
// authors
const authorsPath = path.join(__dirname, 'blog/authors/authors.yaml')
const authorsRaw = await fs.readFile(authorsPath, 'utf8')
const authorsJson = yaml.safeLoad(authorsRaw)
const authors = store.addContentType({
typeName: 'Author',
route: '/author/:id'
})
authorsJson.forEach(({ id, name: title, ...fields }) => {
authors.addNode({
id,
title,
...fields,
internal: {
origin: authorsPath
}
})
})
})
api.afterBuild(async ({ config }) => {
const from = path.join(config.outDir, 'plugins/1/index.html')
const to = path.join(config.outDir, 'plugins/index.html')
await fs.copy(from, to)
})
}