Open mckelveygreg opened 5 years ago
Code.gs
/**
* @OnlyCurrentDoc
*/
// Function that is exposed
function doGet(e) {
var output = getOutputObjectFromSheet(e.parameter);
return ContentService.createTextOutput(JSON.stringify(output));
}
function getOutputObjectFromSheet(params) {
// Inspired by: http://ramblings.mcpher.com/Home/excelquirks/gassnips/namedcolumns
// get all the data on the sheet
var sheet = SpreadsheetApp.getActiveSheet();
var values = sheet.getDataRange().getValues();
// separete the headeres and data
var headers = values[0];
var data = values.slice(1);
// Build result as an array of objects
var result = []
data.forEach(function(d,i) {
var object = {};
headers.forEach(function(h, j) {
object[h] = d[j];
});
result.push(object);
});
return result;
}
Open Eugene Conference Leadership Team Roster API endpoint: https://script.google.com/macros/s/AKfycbzMa6BvpG0lMFSmL87L4nCPLk5j7BaZnJ9-Is7y03LeefWiKyo/exec
Open Eugene Call for Projects https://script.google.com/macros/s/AKfycbzfzMqhgN2vFovjEJXNIZjKqrINiwVoeoAol7xT5S058DS5TBXi/exec
Open Eugene Call for Programming https://script.google.com/macros/s/AKfycbyVcGpheIX9oOpHc3SWtiJn-koFIk1X-MiFwm6NRsPgRpaCJ88k/exec
Sponsor Web Logos and Links https://script.google.com/macros/s/AKfycbyytX06ACX5fV8inFiIDtVgyj_o6Vhu3zEEi1h5XRVFknoXUHRe/exec
@mckelveygreg I think that's it!
actually none of these work. the code has errors :(
lolz... found a little bug! Fixed it, and updated the above script. it actually should work now, though!
You can attach a "google script" to a google sheet to turn your info into a REST API. All that needs to happen is the creator of the sheet needs to attach the script (Tools > Script Editor), and then publish the script (Publish > Deploy as Web App). Gatsby would then use that url to fetch the json. Therefore, on each build, Gatsby would grab the latest info from the sheet.
This replaces exporting json from sheets, adding that file to the repo, and then doing another site build.
Needs: