-
Notifications
You must be signed in to change notification settings - Fork 32
/
gatsby-node.js
25 lines (22 loc) · 883 Bytes
/
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
"use strict";
const fetchSheet = require(`./fetch-sheet.js`).default;
const uuidv5 = require("uuid/v5");
const _ = require("lodash");
const crypto = require("crypto");
const seedConstant = "2972963f-2fcf-4567-9237-c09a2b436541";
exports.sourceNodes = async ({ boundActionCreators, getNode, store, cache }, { spreadsheetId, worksheetTitle, credentials }) => {
const { createNode } = boundActionCreators;
console.log("FETCHING SHEET", fetchSheet);
let rows = await fetchSheet(spreadsheetId, worksheetTitle, credentials);
rows.forEach(r => {
createNode(Object.assign(r, {
id: uuidv5(r.id, uuidv5("gsheet", seedConstant)),
parent: "__SOURCE__",
children: [],
internal: {
type: _.camelCase(`googleSheet ${worksheetTitle} row`),
contentDigest: crypto.createHash("md5").update(JSON.stringify(r)).digest("hex")
}
}));
});
};