From bfcd55cd53da4c320028679d706f68f7d33989c9 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Wed, 24 Mar 2021 23:01:48 -0700 Subject: [PATCH] Replace homepage placeholder with real CMS Reference README for detail on how the Google Sheet is being queried --- script.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/script.js b/script.js index 725cc3e..55a245b 100644 --- a/script.js +++ b/script.js @@ -16,7 +16,7 @@ const createSkeletonElement = () => { const createArticleElement = (article) => { const el = document.createElement("article"); - el.innerHTML = `

${article.title}

${article.body}

Read More

`; + el.innerHTML = `

${article[0]}

${article[1]}

Read More

`; return el; }; @@ -44,6 +44,15 @@ const inject = (resp) => { } }; -fetch("https://jsonplaceholder.typicode.com/posts").then((httpResponse) => - httpResponse.json().then((jsonResponse) => inject(jsonResponse)) -); +/* Query Google Sheet for the card content */ +(async () => { + const proxyUrl = + "https://script.google.com/macros/s/AKfycbzMHxwypbwsccBq6RH8LDCAOpM02C4gbkljbcKHKFsoQTRE-f4XTIyswiaO0vshs-Kr/exec"; + const controllerId = "1pfGF8yBu3D0GPTezygLuzu3Cif8SkjhtG98nL-czlhc"; + const range = "B3:D"; + const url = `${proxyUrl}?https://sheets.googleapis.com/v4/spreadsheets/${controllerId}/values/${range}`; + + await fetch(url) + .then((httpResponse) => httpResponse.json()) + .then((googleSheetsRange) => inject(googleSheetsRange.values)); +})(); -- 2.47.3