Skip to content

Commit e9737c9

Browse files
committed
Create a custom plugin for Bytes subscribers
1 parent 4f567da commit e9737c9

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

gatsby-config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module.exports = {
2121
},
2222
"gatsby-plugin-styled-components",
2323
"gatsby-plugin-react-helmet",
24+
"custom-bytes-subscriber-count-plugin",
2425
{
2526
resolve: "gatsby-source-filesystem",
2627
options: {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const fetch = require("node-fetch");
2+
3+
exports.sourceNodes = async ({
4+
actions,
5+
createNodeId,
6+
createContentDigest,
7+
}) => {
8+
try {
9+
const res = await fetch(`https://bytes.dev/api/subcount`).then((res) =>
10+
res.json()
11+
);
12+
13+
if (res.error) {
14+
throw res.error;
15+
}
16+
17+
actions.createNode({
18+
subcount: res.subcount,
19+
id: createNodeId(`bytes-subcount`),
20+
internal: {
21+
type: "bytes",
22+
contentDigest: createContentDigest({ subcount: res.subcount }),
23+
},
24+
});
25+
} catch (e) {
26+
console.log(`Error in custom-bytes-subscriber-count-plugin`, e.message);
27+
}
28+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

0 commit comments

Comments
 (0)