From: Ardis Lu Date: Thu, 25 Mar 2021 06:01:48 +0000 (-0700) Subject: Replace homepage placeholder with real CMS X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=bfcd55cd53da4c320028679d706f68f7d33989c9;p=ardislu.dev Replace homepage placeholder with real CMS Reference README for detail on how the Google Sheet is being queried --- 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)); +})();