-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgridsome.server.js
83 lines (71 loc) · 2.28 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
const path = require('path')
const fs = require('fs-extra')
const execa = require('execa')
const yaml = require('js-yaml')
const Prism = require('prismjs')
// highlight page-query and static-query in html
Prism.languages.html.graphql = {
pattern: /(<(page|static)-query[\s\S]*?>)[\s\S]*?(?=<\/(page|static)-query>)/i,
inside: Prism.languages.graphql,
lookbehind: true,
greedy: true
}
module.exports = function (api) {
api.loadSource(async ({ addMetadata, addCollection }) => {
let gridsomeVersion = ''
try {
const { stdout } = await execa('npm', ['show', 'gridsome', 'version'])
gridsomeVersion = stdout
} catch (err) {
console.warn('Failed to get gridsome version from npm.')
}
addMetadata('gridsomeVersion', gridsomeVersion)
// contributors
const authorsPath = path.join(__dirname, 'contributors/contributors.yaml')
const authorsRaw = await fs.readFile(authorsPath, 'utf8')
const authorsJson = yaml.safeLoad(authorsRaw)
const authors = addCollection('Contributor')
authorsJson.forEach(({ id, name: title, ...fields }) => {
authors.addNode({
id,
title,
internal: {
origin: authorsPath
},
...fields
})
})
// Plugins
const pluginsPath = path.join(__dirname, 'plugins/plugins.yaml')
const pluginsRaw = await fs.readFile(pluginsPath, 'utf8')
const pluginsJson = yaml.safeLoad(pluginsRaw)
const plugins = addCollection('Plugin')
// Connect author field to Contributors & Platforms
plugins.addReference('author', 'Contributor')
plugins.addReference('platforms', 'Platform')
pluginsJson.forEach((plugin, index) => {
plugins.addNode({
...plugin,
index,
internal: {
origin: pluginsPath
}
})
})
// Platforms
const platformsPath = path.join(__dirname, 'platforms/platforms.yaml')
const platformsRaw = await fs.readFile(platformsPath, 'utf8')
const platformsJson = yaml.safeLoad(platformsRaw)
const platforms = addCollection('Platform')
// Connect author field to Contributors
platformsJson.forEach((platform, index) => {
platforms.addNode({
...platform,
index,
internal: {
origin: platformsPath
}
})
})
})
}