-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
gridsome.server.js
92 lines (82 loc) · 2.18 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
const path = require('path')
const fs = require('fs-extra')
const { Octokit } = require("@octokit/rest")
const octokit = new Octokit()
module.exports = function (api, options) {
api.onCreateNode(options => {
if (options.internal.typeName === 'Blog' && options.draft) {
return null
}
})
api.loadSource(async actions => {
// authors
const authorsPath = path.join(__dirname, 'data/author.json')
const authorsRaw = await fs.readFile(authorsPath, 'utf8')
const authorsJson = JSON.parse(authorsRaw);
const authors = actions.addCollection('Author')
authorsJson.forEach((author) => {
authors.addNode({
id: author.id,
name: author.name,
twitter: author.twitter,
bio: author.bio,
image: author.image
})
})
const thermalRepository = {
owner: "gitthermal",
repo: "thermal"
}
// latest release artifacts
const getLatestRelease = await octokit.repos.getLatestRelease(thermalRepository)
try {
const latestRelease = actions.addCollection({
typeName: "latestRelease"
})
getLatestRelease.data.assets.forEach((item) => {
latestRelease.addNode({
id: item.id,
url: item.url,
name: item.name,
label: item.label,
size: item.size,
download_count: item.download_count,
created_at: item.created_at,
updated_at: item.updated_at,
browser_download_url: item.browser_download_url
})
})
} catch (error) {
console.log(error)
}
// list all releases
const listReleases = await octokit.repos.listReleases({ ...thermalRepository, per_page: 100 })
console.log(listReleases);
try {
const releases = actions.addCollection({
typeName: 'releasesData'
})
listReleases.data.forEach(item => {
releases.addNode({
id: item.id,
name: item.name,
html_url: item.html_url,
draft: item.draft,
prerelease: item.prerelease,
tag_name: item.tag_name,
target_commitish: item.target_commitish,
assets: item.assets,
author: {
id: item.author.id,
avatar_url: item.author.avatar_url,
url: item.author.url
},
created_at: item.created_at,
published_at: item.published_at
})
})
} catch (error) {
console.log(error);
};
})
}