Skip to content

Commit

Permalink
use Promise.all for feed
Browse files Browse the repository at this point in the history
  • Loading branch information
nemanjam committed Jun 22, 2024
1 parent 6b37f85 commit 6048575
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/todo3.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,5 @@ styleguide
transitions
render mdx for rss feed content
Promise.all for all render, feed, toc
fix git text in footer
```
10 changes: 7 additions & 3 deletions src/libs/api/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const getFeed = async (): Promise<Feed> => {
// 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;

Expand All @@ -59,8 +59,12 @@ export const getFeed = async (): Promise<Feed> => {
...(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;
};
Expand Down

0 comments on commit 6048575

Please sign in to comment.