diff --git a/src/lib/date-time-formatter.ts b/src/lib/date-time-formatter.ts
deleted file mode 100644
index aa7fc6c..0000000
--- a/src/lib/date-time-formatter.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-import { SITE_LANG, SITE_REGION } from '../consts';
-
-const locale = `${SITE_LANG}-${SITE_REGION}`;
-
-const defaultDateTimeFormatter = new Intl.DateTimeFormat(locale, {
- dateStyle: 'long',
-});
-
-export function renderDateHtml(date: Date) {
- return ``;
-}
-
-// YYYY-MM
-type ProjectDate = `${number}${number}${number}${number}-${number}${number}`;
-
-const projectDateTimeFormatter = new Intl.DateTimeFormat(locale, {
- year: 'numeric',
- month: 'long',
-});
-
-function renderProjectDateHtml(date: ProjectDate) {
- return ``;
-}
-
-export function renderProjectDateRangeHtml(startDate: ProjectDate, endDate?: ProjectDate) {
- const parts = [renderProjectDateHtml(startDate), '—'];
- if (endDate) {
- parts.push(renderProjectDateHtml(endDate));
- }
- return parts.join(' ');
-}
diff --git a/src/lib/render-date.ts b/src/lib/render-date.ts
new file mode 100644
index 0000000..64a82c5
--- /dev/null
+++ b/src/lib/render-date.ts
@@ -0,0 +1,54 @@
+import { SITE_LANG, SITE_REGION } from '../consts';
+
+const locale = `${SITE_LANG}-${SITE_REGION}`;
+
+const dateFormatter = new Intl.DateTimeFormat(locale, {
+ dateStyle: 'long',
+});
+
+export function renderDateToHtml(date: Date) {
+ return ``;
+}
+
+if (import.meta.vitest) {
+ const { test, expect } = import.meta.vitest;
+ test('renderDateHtml', () => {
+ expect(renderDateToHtml(new Date('2000-01-01'))).toMatchInlineSnapshot(
+ `""`,
+ );
+ });
+}
+
+interface YearMonth {
+ year: number;
+ month: number;
+}
+
+const yearMonthFormatter = new Intl.DateTimeFormat(locale, {
+ year: 'numeric',
+ month: 'long',
+});
+
+function renderYearMonthToHtml({ year, month }: YearMonth) {
+ const date = new Date(Date.UTC(year, month - 1));
+ return ``;
+}
+
+if (import.meta.vitest) {
+ const { test, expect } = import.meta.vitest;
+ test('renderYearMonthHtml', () => {
+ expect(renderYearMonthToHtml({ year: 2000, month: 1 })).toMatchInlineSnapshot(
+ `""`,
+ );
+ });
+}
+
+export function renderYearMonthRangeToHtml(startYearMonth: YearMonth, endYearMonth?: YearMonth) {
+ const parts = [renderYearMonthToHtml(startYearMonth), '—'];
+ if (endYearMonth) {
+ parts.push(renderYearMonthToHtml(endYearMonth));
+ }
+ return parts.join(' ');
+}
diff --git a/src/pages/[...slug].astro b/src/pages/[...slug].astro
index 9b8b7c4..ba7eead 100644
--- a/src/pages/[...slug].astro
+++ b/src/pages/[...slug].astro
@@ -2,7 +2,7 @@
import { getCollection } from 'astro:content';
import PageHeader from '../components/PageHeader.astro';
import Layout from '../layouts/Layout.astro';
-import { renderDateHtml } from '../lib/date-time-formatter';
+import { renderDateToHtml } from '../lib/render-date';
export async function getStaticPaths() {
return (await getCollection('blog')).map((entry) => ({
@@ -23,7 +23,7 @@ const { Content, remarkPluginFrontmatter } = await entry.render();
twitterCard={entry.data.twitterCard}
>
-
+
diff --git a/src/pages/blog.astro b/src/pages/blog.astro
index ccf8c8d..2d790fa 100644
--- a/src/pages/blog.astro
+++ b/src/pages/blog.astro
@@ -3,7 +3,7 @@ import { getCollection } from 'astro:content';
import DetailsList from '../components/DetailsList.astro';
import PageHeader from '../components/PageHeader.astro';
import Layout from '../layouts/Layout.astro';
-import { renderDateHtml } from '../lib/date-time-formatter';
+import { renderDateToHtml } from '../lib/render-date';
const title = 'ブログ';
@@ -20,7 +20,7 @@ const blogEntries = (await getCollection('blog')).toSorted(
items={blogEntries.map((entry) => ({
title: entry.data.title,
link: `/${entry.slug}`,
- meta: renderDateHtml(entry.data.pubDate),
+ meta: renderDateToHtml(entry.data.pubDate),
}))}
/>
diff --git a/src/pages/index.astro b/src/pages/index.astro
index 137c616..3cf5835 100644
--- a/src/pages/index.astro
+++ b/src/pages/index.astro
@@ -6,7 +6,7 @@ import type { DetailsListItem } from '../components/DetailsList.astro';
import PageHeader from '../components/PageHeader.astro';
import { SITE_TITLE, SITE_DESCRIPTION } from '../consts';
import Layout from '../layouts/Layout.astro';
-import { renderDateHtml, renderProjectDateRangeHtml } from '../lib/date-time-formatter';
+import { renderDateToHtml, renderYearMonthRangeToHtml } from '../lib/render-date';
const everylayoutEntry = await getEntry('blog', '20211011-publication-of-everylayout');
@@ -72,39 +72,39 @@ const projectItems = [
{
title: 'sdenv',
link: 'https://github.com/yuheiy/sdenv',
- meta: renderProjectDateRangeHtml('2023-07'),
+ meta: renderYearMonthRangeToHtml({ year: 2023, month: 7 }),
description:
'ウェブサイト構築のためのベストプラクティスに基づいて構成された、Astro、Tailwind CSS、Alpine.jsを中心とした開発環境。',
},
{
title: 'wordpress-starter',
link: 'https://github.com/yuheiy/wordpress-starter',
- meta: renderProjectDateRangeHtml('2020-08', '2022-10'),
+ meta: renderYearMonthRangeToHtml({ year: 2020, month: 8 }, { year: 2022, month: 10 }),
description: 'WordPressテーマ構築のための開発環境。',
},
{
title: 'accrefs',
link: 'https://accrefs.jp/',
- meta: renderProjectDateRangeHtml('2019-09'),
+ meta: renderYearMonthRangeToHtml({ year: 2019, month: 9 }),
description:
'ウェブアクセシビリティの参考資料をまとめたサイト。日本語の資料を中心にリンク数は200を超える。サイトのデザインおよび実装に携わる。有志のメンバーにより制作・運営されている。',
},
{
title: 'shifted',
link: 'https://github.com/yuheiy/shifted',
- meta: renderProjectDateRangeHtml('2019-05', '2023-07'),
+ meta: renderYearMonthRangeToHtml({ year: 2019, month: 5 }, { year: 2023, month: 7 }),
description: '静的サイト構築のための開発環境。',
},
{
title: 'シフトブレイン/スタンダードデザインユニット',
link: 'https://standard.shiftbrain.com/',
- meta: renderProjectDateRangeHtml('2018-10', '2020-06'),
+ meta: renderYearMonthRangeToHtml({ year: 2018, month: 10 }, { year: 2020, month: 6 }),
description: '自社で所属していたチームのウェブサイト。',
},
{
title: 'yuhei blog',
link: 'https://yuheiy.hatenablog.com/',
- meta: renderProjectDateRangeHtml('2015-10', '2020-11'),
+ meta: renderYearMonthRangeToHtml({ year: 2015, month: 10 }, { year: 2020, month: 11 }),
description: '過去に更新していた個人ブログ。',
},
] satisfies DetailsListItem[];
@@ -163,7 +163,7 @@ const blogEntries = (await getCollection('blog')).toSorted(
items={blogEntries.slice(0, 3).map((entry) => ({
title: entry.data.title,
link: `/${entry.slug}`,
- meta: renderDateHtml(entry.data.pubDate),
+ meta: renderDateToHtml(entry.data.pubDate),
}))}
/>