forked from Keycapsss/awesome-mechanical-keyboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gridsome.server.js
executable file
·146 lines (129 loc) · 4.23 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Server API makes it possible to hook into various parts of Gridsome
// on server-side and add custom data to the GraphQL data layer.
// Learn more: https://gridsome.org/docs/server-api
// Changes here require a server restart.
// To restart press CTRL + C in terminal and run `gridsome develop`
const { GraphQLClient } = require('graphql-request')
const axios = require('axios')
module.exports = function (api) {
api.loadSource(async actions => {
const graphqlClient = new GraphQLClient(process.env.GITHUB_API_V4_URL, {
headers: {
Authorization: `Bearer ${process.env.GITHUB_AUTH_TOKEN}`,
},
})
// get repo's commit history via graphql for the rss feed and
// news page
const commitHistoryQuery = `
{
repository(owner: "benroe", name: "awesome-mechanical-keyboard") {
ref(qualifiedName: "master") {
target {
... on Commit {
history(first: 30) {
edges {
node {
oid
committedDate
messageHeadline
messageBody
author {
date
name
}
}
}
}
}
}
}
}
}`
const commitMessages = actions.addCollection({
typeName: 'CommitMessages'
})
const commitMessagesData = await graphqlClient.request(commitHistoryQuery)
// add each node the the collection
commitMessagesData.repository.ref.target.history.edges.forEach(function(item) {
const coHeadline = item.node.messageHeadline
// add only commit messages which are relevant for website user
if(coHeadline.startsWith('feat') || coHeadline.startsWith('docs')) {
commitMessages.addNode({
id: item.node.oid,
date: item.node.committedDate,
message: item.node.messageHeadline,
body: item.node.messageBody,
author: item.node.author.name,
})
}
})
// get the sponsor list
const sponsorsQuery = `
{
user(login: "BenRoe") {
sponsorshipsAsMaintainer(first: 5) {
edges {
node {
sponsor {
id
name
login
avatarUrl
url
}
}
}
}
}
}`
const sponsors = actions.addCollection({
typeName: 'Sponsors'
})
const sponsorsData = await graphqlClient.request(sponsorsQuery)
// add each node the the collection
sponsorsData.user.sponsorshipsAsMaintainer.edges.forEach(function(item) {
sponsors.addNode({
id: item.node.sponsor.id,
login: item.node.sponsor.login,
avatarUrl: item.node.sponsor.avatarUrl,
url: item.node.sponsor.url,
})
})
// Get contributor list and add to GraphQL
const { data } = await axios.get('https://api.github.com/repos/BenRoe/awesome-mechanical-keyboard/contributors?q=contributions&order=desc')
const contributors = actions.addCollection({
typeName: 'Contributors'
})
for (const item of data) {
contributors.addNode({
id: item.id,
name: item.login,
avatar_url: item.avatar_url,
url: item.html_url,
contribution: item.contributions,
path: '/contributor/' + item.login
})
}
// const { data } = await axios.get('https://benroe.github.io/switch-database/mechanical-keyboard-switches.json')
// const contentType = store.addContentType({
// typeName: 'Switches',
// route: '/switch/:id'
// })
// for (const item of data) {
// contentType.addNode({
// id: item.id,
// brand: item.brand,
// type: item.type,
// path: '/switch/' + item.id
// })
// }
// contentType.addNode({
// fields: {
// items: data.map(item => {
// // Reference a node with typeName 'Item'
// return store.createReference('Item', item.id)
// })
// }
// })
})
}