-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
56 lines (50 loc) · 1.4 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
const path = require("path");
const axios = require("axios");
exports.onCreateWebpackConfig = ({ actions }) => {
actions.setWebpackConfig({
resolve: {
alias: {
src: path.join(__dirname, "src"),
"@src": path.join(__dirname, "src"),
"@common": path.join(__dirname, "src/components/common"),
"@components": path.join(__dirname, "src/components"),
"@pages": path.join(__dirname, "src/pages"),
"@hooks": path.join(__dirname, "src/hooks"),
"@config": path.join(__dirname, "src/config"),
},
},
});
};
exports.sourceNodes = ({ actions, createNodeId, createContentDigest }) => {
const { createNode } = actions;
const createPinnedRepo = (repo, idx) => {
const node = {
id: createNodeId(`pinned-repo-${idx}`),
parent: null,
children: [],
internal: {
type: `PinnedRepos`,
content: JSON.stringify(repo),
contentDigest: createContentDigest(repo),
},
...repo,
};
createNode(node);
};
const API_URL =
"https://gh-pinned-repos-worker.pranjal.workers.dev/?username=PranjalAgni";
return new Promise((resolve, reject) => {
axios
.get(API_URL)
.then(res => {
res.data.forEach((repo, idx) => {
createPinnedRepo(repo, idx);
resolve();
});
})
.catch(ex => {
console.error(ex);
reject(ex);
});
});
};