forked from vegaprotocol/vega.xyz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
113 lines (101 loc) · 3.25 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
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
const path = require("path");
const fetch = require(`node-fetch`);
const { createFilePath } = require(`gatsby-source-filesystem`);
module.exports.onCreateNode = ({ node, getNode, actions }) => {
const { createNodeField } = actions;
if (node.internal.type === "MarkdownRemark") {
const slug = createFilePath({ node, getNode, basePath: `content` });
node.collection = getNode(node.parent).sourceInstanceName;
const category = node.frontmatter.category;
createNodeField({
node,
name: `slug`,
value: slug,
});
createNodeField({
node,
name: `category`,
value: category,
});
}
};
module.exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions;
const response = await graphql(`
query {
allMarkdownRemark {
edges {
node {
collection
fields {
slug
}
}
}
}
}
`);
response.data.allMarkdownRemark.edges.forEach((edge) => {
const slug = edge.node.fields.slug;
const template = edge.node.collection;
if (["jobs"].includes(template)) {
createPage({
component: path.resolve(`./src/templates/${template}.js`),
path: `${edge.node.fields.slug}`,
context: {
slug: edge.node.fields.slug,
},
});
}
});
};
exports.sourceNodes = async ({
actions,
createNodeId,
createContentDigest,
}) => {
// const contributorsData = await fetch(
// `https://github-contributors-service.ops.vega.xyz/contributors`
// );
// const contributorsResultData = await contributorsData.json();
// contributorsResultData.github_contributors.forEach((contributor) => {
// const node = {
// username: contributor.login,
// avatar: contributor.avatar_url,
// total_contributions: contributor.total_contributions,
// id: createNodeId(`contributors-${contributor.login}`),
// parent: null,
// children: [],
// internal: {
// type: `Contributors`,
// contentDigest: createContentDigest(contributor),
// },
// };
// actions.createNode(node);
// });
const incentivesData = await fetch(
`https://notion-data-service.ops.vega.xyz/query?id=aa64c6a0-0e0d-460d-ad44-ceacc6cd5957`
);
const incentivesResultData = await incentivesData.json();
incentivesResultData.notion_data.forEach((incentive) => {
const node = {
name: incentive.properties.find((o) => o.name === "Name").values,
type: incentive.properties.find((o) => o.name === "Type").values,
status: incentive.properties.find((o) => o.name === "Status").values,
reward: incentive.properties.find((o) => o.name === "Reward").values,
end_date: incentive.properties.find((o) => o.name === "End Date").values,
start_date: incentive.properties.find((o) => o.name === "Start Date")
.values,
link: incentive.properties.find((o) => o.name === "Link").values,
tags: incentive.properties.find((o) => o.name === "Tags").values,
id: createNodeId(`incentive-${incentive.id}`),
parent: null,
children: [],
internal: {
type: `Incentives`,
contentDigest: createContentDigest(incentive),
},
};
actions.createNode(node);
});
};