-
Notifications
You must be signed in to change notification settings - Fork 9
/
gatsby-node.js
77 lines (70 loc) · 1.9 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
const path = require('path');
const fetch = require('node-fetch');
const { createFilePath } = require('gatsby-source-filesystem');
exports.onCreateNode = ({
node, actions, getNode, getNodesByType,
}) => {
const { createNodeField, createParentChildLink } = actions;
if (node.internal.type === 'Directory') {
const parentDirectory = path.normalize(`${node.dir}/`);
const parent = getNodesByType('Directory')
.find(
(n) => path.normalize(`${n.absolutePath}/`) === parentDirectory,
);
if (parent) {
// eslint-disable-next-line no-param-reassign
node.parent = parent.id;
createParentChildLink({
child: node,
parent,
});
}
}
if (node.internal.type === 'MarkdownRemark') {
const fileNode = (node.parent && node.parent !== 'undefined')
? getNode(node.parent)
: node;
const slug = createFilePath({
node,
getNode,
});
const fullSlug = fileNode.sourceInstanceName !== 'posts'
? path.posix.join(fileNode.sourceInstanceName, slug)
: slug;
const parent = getNodesByType('Directory')
.find(
(n) => n.name === fileNode.relativeDirectory,
);
if (parent) {
createParentChildLink({
child: node,
parent,
});
}
createNodeField({
name: 'slug',
node,
value: fullSlug,
});
}
};
exports.sourceNodes = async ({
actions: { createNode },
createContentDigest,
}) => {
const slackReq = await fetch('https://slackin.px.dev/data');
const slack = await slackReq.json();
const gitReq = await fetch('https://api.github.com/repos/pixie-io/pixie');
const github = await gitReq.json();
createNode({
slack: slack.total,
github: github.watchers,
id: 'header-counters-data',
parent: null,
children: [],
internal: {
type: 'HeaderCountersData',
contentDigest: createContentDigest({}),
},
});
};