Skip to content

Commit

Permalink
refactor promise tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
yuheiy committed Jul 19, 2024
1 parent 27ee174 commit 218b6dc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 23 deletions.
3 changes: 1 addition & 2 deletions src/pages/[...slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { getBlogDescription } from '../lib/get-blog-description';
import { renderDateToHtml } from '../lib/render-date-to-html';
export async function getStaticPaths() {
const entries = await getCollection('blog');
return entries.map((entry) => ({
return (await getCollection('blog')).map((entry) => ({
params: { slug: entry.slug },
props: { entry },
}));
Expand Down
15 changes: 6 additions & 9 deletions src/pages/blog.astro
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@ const title = 'ブログ';
const items = await Promise.all(
(await getCollection('blog'))
.toSorted((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf())
.map(async (entry) => {
const description = await getBlogDescription(entry);
return {
title: entry.data.title,
link: getBlogUrl(entry),
meta: renderDateToHtml(entry.data.pubDate),
description,
};
}),
.map(async (entry) => ({
title: entry.data.title,
link: getBlogUrl(entry),
meta: renderDateToHtml(entry.data.pubDate),
description: await getBlogDescription(entry),
})),
);
---

Expand Down
18 changes: 8 additions & 10 deletions src/pages/external-posts.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ import { renderDateToHtml } from '../lib/render-date-to-html';
const title = '外部サイトの投稿';
const description = '外部サイトに寄稿した記事、登壇したイベントやスライド、出版物など。';
const items = await Promise.all(
(await getCollection('external-post'))
.toSorted((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf())
.map(async (entry) => ({
title: entry.data.title,
link: entry.data.link,
meta: `${renderDateToHtml(entry.data.pubDate)} · ${entry.data.channel}`,
description: entry.data.description,
})),
);
const items = (await getCollection('external-post'))
.toSorted((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf())
.map((entry) => ({
title: entry.data.title,
link: entry.data.link,
meta: `${renderDateToHtml(entry.data.pubDate)} · ${entry.data.channel}`,
description: entry.data.description,
}));
---

<Layout title={title} description={description}>
Expand Down
5 changes: 3 additions & 2 deletions src/pages/rss.xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import { getBlogUrl } from '../lib/get-blog-url';
export async function GET(context: APIContext) {
invariant(context.site);

const renderers = await loadRenderers([getContainerRenderer()]);
const container = await AstroContainer.create({ renderers });
const container = await AstroContainer.create({
renderers: await loadRenderers([getContainerRenderer()]),
});

const items = await Promise.all(
[...(await getCollection('blog')), ...(await getCollection('external-post'))]
Expand Down

0 comments on commit 218b6dc

Please sign in to comment.