forked from vegaprotocol/vega.xyz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
136 lines (120 loc) · 3.46 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
const path = require(`path`);
const fetch = require(`node-fetch`);
const { createFilePath } = require(`gatsby-source-filesystem`);
const spawn = require("cross-spawn");
module.exports.onCreateNode = ({ node, getNode, actions }) => {
const { createNodeField } = actions;
if (node.internal.type === "MarkdownRemark") {
const path = createFilePath({ node, getNode, basePath: `content` });
const pathComponents = path.split("/").slice(1, -1);
node.collection = getNode(node.parent).sourceInstanceName;
const category = node.frontmatter.category;
const slug = pathComponents[0];
let locale = "en";
// extract locale from file extension
if (pathComponents[1]) {
locale = pathComponents[1].split(".").slice(-1).pop();
}
if (pathComponents.length > 0 && parseInt(pathComponents[0])) {
createNodeField({
node,
name: `order`,
value: parseInt(pathComponents[0]),
});
}
createNodeField({
node,
name: `locale`,
value: locale,
});
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
locale
}
}
}
}
}
`);
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: `careers/${edge.node.fields.slug}`,
context: {
slug: edge.node.fields.slug,
},
});
}
});
};
exports.sourceNodes = async ({
actions,
createNodeId,
createContentDigest,
}) => {
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);
});
};
exports.onCreateWebpackConfig = ({ actions }) => {
actions.setWebpackConfig({
module: {
rules: [
{
test: /\.asc$/i,
use: "raw-loader",
},
],
},
});
};
exports.onPreInit = () => {
const result = spawn.sync("yarn", ["i18next", "src/**/*.js"], {
stdio: "inherit",
});
};