From 6048575e33f77edf009d111cce5ccd148ba36cab Mon Sep 17 00:00:00 2001 From: nemanjam Date: Sat, 22 Jun 2024 15:46:12 +0200 Subject: [PATCH] use Promise.all for feed --- docs/todo3.md | 1 + src/libs/api/feed.ts | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/todo3.md b/docs/todo3.md index 0ce3832..a80b7f5 100644 --- a/docs/todo3.md +++ b/docs/todo3.md @@ -348,4 +348,5 @@ styleguide transitions render mdx for rss feed content Promise.all for all render, feed, toc +fix git text in footer ``` diff --git a/src/libs/api/feed.ts b/src/libs/api/feed.ts index 92c96a1..c6a929f 100644 --- a/src/libs/api/feed.ts +++ b/src/libs/api/feed.ts @@ -39,7 +39,7 @@ export const getFeed = async (): Promise => { // this handles omitting draft posts and preview mode by default const sortedPosts = await getAllPosts(); - for (const post of sortedPosts) { + const itemPromises = sortedPosts.map(async (post) => { const { data, body, slug } = post; const { title, description, publishDate, heroImage, noHero } = data; @@ -59,8 +59,12 @@ export const getFeed = async (): Promise => { ...(noHero ? { image: `${SITE_URL}${heroImage.src}` } : {}), }; - feed.addItem(item); - } + return item; + }); + + const items = await Promise.all(itemPromises); + + items.forEach((item) => feed.addItem(item)); return feed; };