forked from publu/QIPs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
88 lines (79 loc) · 1.99 KB
/
gatsby-node.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
const fs = require('fs')
const kebabCase = require('lodash/kebabCase')
const statuses = require('./ps/statuses')
const kebabStatuses = statuses.map(kebabCase)
const Frontmatter = `
fragment Frontmatter on MarkdownRemarkFrontmatter {
qip
title
author
network
type
proposal
implementor
release
created
updated
status
}
`
const allQipsQuery = `
${Frontmatter}
query {
allMarkdownRemark(
filter: {fileAbsolutePath: {regex: "/QIP/"}, frontmatter: {qip: {ne: null}}}
) {
group(field: {frontmatter: {status: SELECT}}) {
fieldValue
totalCount
nodes {
id
frontmatter {
...Frontmatter
}
}
}
}
}
`;
exports.onPostBuild = async ({ graphql }) => {
const allQips = await graphql(allQipsQuery)
const qipsPath = './public/api/qips'
;[
{ path: qipsPath, result: allQips },
].forEach(({ path, result }) => {
if (!fs.existsSync(path)) fs.mkdirSync(path, { recursive: true })
// Initialize all statuses with empty array
kebabStatuses.forEach((status) =>
fs.writeFileSync(`${path}/${status}.json`, JSON.stringify([])),
)
result.data.allMarkdownRemark.group.forEach((group) => {
const status = kebabCase(group.fieldValue)
const data = group.nodes.map(({ frontmatter, ...node }) => ({
...frontmatter,
...node,
}))
fs.writeFileSync(`${path}/${status}.json`, JSON.stringify(data))
})
})
}
exports.createSchemaCustomization = ({ actions }) => {
const { createTypes } = actions;
const typeDefs = `
type MarkdownRemarkFrontmatter {
title: String!
shortDescription: String
network: String
author: String
type: String
proposal: String
implementor: String
release: String
created: Date
updated: Date
date: Date
status: String
}
`;
createTypes(typeDefs);
};