-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgatsby-node.js
56 lines (47 loc) · 1.3 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 Masto = require("mastodon");
const { tootType } = require("./schema");
exports.sourceNodes = (
{ actions, createNodeId, createContentDigest },
configOptions
) => {
const { createNode } = actions;
// Gatsby adds a configOption that's not needed for this plugin, delete it
delete configOptions.plugins;
var M = new Masto({
access_token: configOptions.access_token,
timeout_ms: 60 * 1000,
api_url: configOptions.api_url
});
const createNodes = toots => {
toots.forEach(toot => {
const nodeId = createNodeId(`toot-${toot.id}`);
const nodeContent = JSON.stringify(toot);
const nodeData = Object.assign({}, toot, {
id: nodeId,
parent: `__SOURCE__`,
children: [],
internal: {
type: `Toot`,
content: nodeContent,
contentDigest: createContentDigest(toot)
}
});
createNode(nodeData);
});
};
return M.get("accounts/verify_credentials").then(resp1 => {
const { id } = resp1.data;
return M.get(`accounts/${id}/statuses`, {
exclude_replies: true,
limit: configOptions.limit
}).then(resp2 => {
createNodes(resp2.data);
});
});
};
exports.setFieldsOnGraphQLNodeType = ({ type }) => {
if (type.name !== `Toot`) {
return {};
}
return tootType;
};