diff --git a/src/lib/get-blog-url.ts b/src/lib/get-blog-url.ts new file mode 100644 index 0000000..43f839c --- /dev/null +++ b/src/lib/get-blog-url.ts @@ -0,0 +1,5 @@ +import type { CollectionEntry } from "astro:content"; + +export function getBlogUrl(entry: CollectionEntry<'blog'>) { + return `/${entry.slug}` +} diff --git a/src/pages/blog.astro b/src/pages/blog.astro index d11cb65..729ceaf 100644 --- a/src/pages/blog.astro +++ b/src/pages/blog.astro @@ -4,6 +4,7 @@ import DetailsList from '../components/DetailsList.astro'; import PageHeader from '../components/PageHeader.astro'; import Layout from '../layouts/Layout.astro'; import { getBlogDescription } from '../lib/get-blog-description'; +import { getBlogUrl } from '../lib/get-blog-url'; import { renderDateToHtml } from '../lib/render-date-to-html'; const title = 'ブログ'; @@ -15,7 +16,7 @@ const items = await Promise.all( const description = await getBlogDescription(entry); return { title: entry.data.title, - link: `/${entry.slug}`, + link: getBlogUrl(entry), meta: renderDateToHtml(entry.data.pubDate), description, }; diff --git a/src/pages/index.astro b/src/pages/index.astro index 42761a5..5207f2b 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -7,15 +7,18 @@ import PageHeader from '../components/PageHeader.astro'; import { siteDescription, siteTitle } from '../consts'; import Layout from '../layouts/Layout.astro'; import { getBlogDescription } from '../lib/get-blog-description'; +import { getBlogUrl } from '../lib/get-blog-url'; import { renderDateToHtml } from '../lib/render-date-to-html'; import { renderYearMonthRangeToHtml } from '../lib/render-year-month-range-to-html'; +const everylayoutUrl = getBlogUrl(await getEntry('blog', '20211011-publication-of-everylayout')); + function toPrimaryItem(entry: CollectionEntry<'blog' | 'external-post'>): DetailsListItem { switch (entry.collection) { case 'blog': return { title: entry.data.title, - link: `/${entry.slug}`, + link: getBlogUrl(entry), meta: siteTitle, }; @@ -115,13 +118,11 @@ const latestBlogItems = await Promise.all( .slice(0, 3) .map(async (entry) => ({ title: entry.data.title, - link: `/${entry.slug}`, + link: getBlogUrl(entry), meta: renderDateToHtml(entry.data.pubDate), description: await getBlogDescription(entry), })), ); - -const everylayoutEntry = await getEntry('blog', '20211011-publication-of-everylayout'); --- @@ -129,7 +130,7 @@ const everylayoutEntry = await getEntry('blog', '20211011-publication-of-everyla

{siteDescription}

- 監訳を担当した書籍『Every Layout——モジュラーなレスポンシブデザインを実現するCSS設計論』がオンライン書店などで発売中。 diff --git a/src/pages/rss.xml.ts b/src/pages/rss.xml.ts index b0f3eda..9cb1045 100644 --- a/src/pages/rss.xml.ts +++ b/src/pages/rss.xml.ts @@ -8,6 +8,7 @@ import sanitizeHtml from 'sanitize-html'; import invariant from 'tiny-invariant'; import { siteDescription, siteTitle } from '../consts'; import { getBlogDescription } from '../lib/get-blog-description'; +import { getBlogUrl } from '../lib/get-blog-url'; export async function GET(context: APIContext) { invariant(context.site); @@ -22,7 +23,7 @@ export async function GET(context: APIContext) { switch (entry.collection) { case 'blog': return { - link: `/${entry.slug}`, + link: getBlogUrl(entry), title: entry.data.title, pubDate: entry.data.pubDate, description: await getBlogDescription(entry),