From: Ardis Lu Date: Thu, 7 Nov 2024 01:06:47 +0000 (-0800) Subject: Simplify loop to match feed.json X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=7e4ac33ff869464d7bb00165ad2342cf90c6647e;p=ardislu.dev Simplify loop to match feed.json --- diff --git a/functions/atom.xml.js b/functions/atom.xml.js index c76dab9..c2f62b2 100644 --- a/functions/atom.xml.js +++ b/functions/atom.xml.js @@ -5,11 +5,9 @@ export async function onRequestGet({ env }) { const updatedDates = []; const token = await getGoogleAuthToken(env.EMAIL, env.PRIVATE_KEY, 'https://www.googleapis.com/auth/spreadsheets.readonly https://www.googleapis.com/auth/documents.readonly'); const sheetUrl = 'https://sheets.googleapis.com/v4/spreadsheets/1pfGF8yBu3D0GPTezygLuzu3Cif8SkjhtG98nL-czlhc/values/B3:I'; - await fetch(sheetUrl, { headers: { Authorization: `Bearer ${token}` } }) - .then(r => r.json()) - .then(googleSheet => { - for (const article of googleSheet.values) { - entries.push(` + const googleSheet = await fetch(sheetUrl, { headers: { Authorization: `Bearer ${token}` } }).then(r => r.json()); + for (const article of googleSheet.values) { + entries.push(` urn:google:${article[2]} ${article[0]} ${article[7].split(',').map(s => ``).join('')} @@ -18,9 +16,8 @@ export async function onRequestGet({ env }) { ${new Date(article[5]).toISOString()} ${new Date(article[6]).toISOString()} `); - updatedDates.push(new Date(article[6])); - } - }); + updatedDates.push(new Date(article[6])); + } const feed = `