]> git.ardis.lu - ardislu.dev/commitdiff
Simplify loop to match feed.json
authorArdis Lu <ardisglu@gmail.com>
Thu, 7 Nov 2024 01:06:47 +0000 (17:06 -0800)
committerArdis Lu <ardisglu@gmail.com>
Thu, 7 Nov 2024 01:06:47 +0000 (17:06 -0800)
functions/atom.xml.js

index c76dab95409a8e18b36949fbcae53e2ada609aa8..c2f62b2866850f8c8fe6952de20d33716acee68a 100644 (file)
@@ -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(`<entry>
+  const googleSheet = await fetch(sheetUrl, { headers: { Authorization: `Bearer ${token}` } }).then(r => r.json());
+  for (const article of googleSheet.values) {
+    entries.push(`<entry>
     <id>urn:google:${article[2]}</id>
     <title>${article[0]}</title>
     ${article[7].split(',').map(s => `<category term="${s.trim()}"/>`).join('')}
@@ -18,9 +16,8 @@ export async function onRequestGet({ env }) {
     <published>${new Date(article[5]).toISOString()}</published>
     <updated>${new Date(article[6]).toISOString()}</updated>
   </entry>`);
-        updatedDates.push(new Date(article[6]));
-      }
-    });
+    updatedDates.push(new Date(article[6]));
+  }
 
   const feed = `<?xml version="1.0" encoding="utf-8"?>
 <feed xmlns="http://www.w3.org/2005/Atom" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">
This page took 0.032696 seconds and 4 git commands to generate.