diff --git a/src/pages/[...slug].astro b/src/pages/[...slug].astro index 898e4d7..501cb6b 100644 --- a/src/pages/[...slug].astro +++ b/src/pages/[...slug].astro @@ -6,10 +6,12 @@ import { getBlogDescription } from '../lib/get-blog-description'; import { renderDateToHtml } from '../lib/render-date-to-html'; export async function getStaticPaths() { - return (await getCollection('blog')).map((entry) => ({ - params: { slug: entry.slug }, - props: { entry }, - })); + return getCollection('blog').then((entries) => + entries.map((entry) => ({ + params: { slug: entry.slug }, + props: { entry }, + })), + ); } type Props = Awaited>[number]['props']; diff --git a/src/pages/blog.astro b/src/pages/blog.astro index 65294a1..d542b8b 100644 --- a/src/pages/blog.astro +++ b/src/pages/blog.astro @@ -8,27 +8,27 @@ import { renderDateToHtml } from '../lib/render-date-to-html'; const title = 'ブログ'; -const blogEntries = (await getCollection('blog')) - .toSorted((a, b) => a.data.pubDate.valueOf() - b.data.pubDate.valueOf()) - .toReversed(); - -const allBlogItems = await Promise.all( - blogEntries.map(async (entry) => { - const description = await getBlogDescription(entry); - return { - title: entry.data.title, - link: `/${entry.slug}`, - meta: renderDateToHtml(entry.data.pubDate), - description, - }; - }), -); +const items = await getCollection('blog') + .then((entries) => + entries + .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: `/${entry.slug}`, + meta: renderDateToHtml(entry.data.pubDate), + description, + }; + }), + ) + .then((promises) => Promise.all(promises)); ---
- +
diff --git a/src/pages/feed.ts b/src/pages/feed.ts index 982bf15..fbe8475 100644 --- a/src/pages/feed.ts +++ b/src/pages/feed.ts @@ -6,27 +6,29 @@ import { SITE_DESCRIPTION, SITE_TITLE } from '../consts'; import { getBlogDescription } from '../lib/get-blog-description'; export async function GET(context: APIContext) { - const blogEntries = (await getCollection('blog')) - .toSorted((a, b) => a.data.pubDate.valueOf() - b.data.pubDate.valueOf()) - .toReversed(); - invariant(context.site); + const items = await getCollection('blog') + .then((entries) => + entries + .toSorted((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf()) + .map(async (entry) => { + const description = await getBlogDescription(entry); + return { + link: `/${entry.slug}`, + title: entry.data.title, + pubDate: entry.data.pubDate, + description, + }; + }), + ) + .then((promises) => Promise.all(promises)); + return rss({ title: SITE_TITLE, description: SITE_DESCRIPTION, site: context.site, - items: await Promise.all( - blogEntries.map(async (entry) => { - const description = await getBlogDescription(entry); - return { - link: `/${entry.slug}`, - title: entry.data.title, - pubDate: entry.data.pubDate, - description, - }; - }), - ), + items, trailingSlash: false, }); } diff --git a/src/pages/index.astro b/src/pages/index.astro index cd231ee..8c47bcf 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -1,10 +1,10 @@ --- import type { CollectionEntry } from 'astro:content'; import { getCollection, getEntry } from 'astro:content'; -import DetailsList from '../components/DetailsList.astro'; import type { DetailsListItem } from '../components/DetailsList.astro'; +import DetailsList from '../components/DetailsList.astro'; import PageHeader from '../components/PageHeader.astro'; -import { SITE_TITLE, SITE_DESCRIPTION } from '../consts'; +import { SITE_DESCRIPTION, SITE_TITLE } from '../consts'; import Layout from '../layouts/Layout.astro'; import { getBlogDescription } from '../lib/get-blog-description'; import { renderDateToHtml } from '../lib/render-date-to-html'; @@ -111,21 +111,22 @@ const projectItems = [ }, ] satisfies DetailsListItem[]; -const blogEntries = (await getCollection('blog')) - .toSorted((a, b) => a.data.pubDate.valueOf() - b.data.pubDate.valueOf()) - .toReversed(); - -const latestBlogItems = await Promise.all( - blogEntries.slice(0, 3).map(async (entry) => { - const description = await getBlogDescription(entry); - return { - title: entry.data.title, - link: `/${entry.slug}`, - meta: renderDateToHtml(entry.data.pubDate), - description, - }; - }), -); +const latestBlogItems = await getCollection('blog') + .then((entries) => + entries + .toSorted((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf()) + .slice(0, 3) + .map(async (entry) => { + const description = await getBlogDescription(entry); + return { + title: entry.data.title, + link: `/${entry.slug}`, + meta: renderDateToHtml(entry.data.pubDate), + description, + }; + }), + ) + .then((promises) => Promise.all(promises)); ---