From c1cc8ef47e4a405697cd9855667e3df5593bd557 Mon Sep 17 00:00:00 2001 From: Fushihara <1039534+fushihara@users.noreply.github.com> Date: Mon, 23 Sep 2024 21:26:42 +0900 Subject: =?UTF-8?q?=E3=82=BF=E3=82=B0=E4=B8=80=E8=A6=A7=E3=81=AE=E3=83=87?= =?UTF-8?q?=E3=83=BC=E3=82=BF=E3=81=AE=E4=BB=95=E7=B5=84=E3=81=BF=E5=A4=89?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/article/all/[pageId]/page.tsx | 3 -- src/app/article/tag/[tagName]/page.tsx | 4 +- src/app/article/tag/page.tsx | 70 +++++++++++++++++++++++++++++----- 3 files changed, 62 insertions(+), 15 deletions(-) (limited to 'src/app/article') diff --git a/src/app/article/all/[pageId]/page.tsx b/src/app/article/all/[pageId]/page.tsx index fd72772..0374401 100644 --- a/src/app/article/all/[pageId]/page.tsx +++ b/src/app/article/all/[pageId]/page.tsx @@ -149,9 +149,6 @@ export async function generateStaticParams() { return { pageId: `page-${index + 1}`, data: data }; }); } -// export const generateStaticParams = async () => { -// return [{ articleid: "123" }]; -// }; function chunk(list: T[], len: number) { if (len <= 0) { diff --git a/src/app/article/tag/[tagName]/page.tsx b/src/app/article/tag/[tagName]/page.tsx index 3df1f1e..b783e82 100644 --- a/src/app/article/tag/[tagName]/page.tsx +++ b/src/app/article/tag/[tagName]/page.tsx @@ -8,7 +8,7 @@ type PageType = { } export async function generateMetadata(context: PageType) { return { - title: `アキバ総研アーカイブ:ページ ${context.params.tagName}`, + title: `アキバ総研アーカイブ:タグの記事一覧 ${context.params.tagName}`, } } export default async function Page(context: PageType) { @@ -35,6 +35,6 @@ export default async function Page(context: PageType) { export async function generateStaticParams() { const tagList = await new ArticleLoader().getTagList(); return tagList.map((data, index) => { - return { tagName: data.name }; + return { tagName: encodeURIComponent(data.tag) }; }); } diff --git a/src/app/article/tag/page.tsx b/src/app/article/tag/page.tsx index 211ca94..f1d161b 100644 --- a/src/app/article/tag/page.tsx +++ b/src/app/article/tag/page.tsx @@ -14,17 +14,67 @@ export async function generateMetadata(context: PageType) { } export default async function Page(context: PageType) { const tagList = await new ArticleLoader().getTagList(); - const tagsElement: JSX.Element[] = []; - tagList.forEach(t => { - tagsElement.push({t.name}({t.count})) - }) + type TAG = { tag: string, count: number, primary?: boolean }; + const elementListPcPart: TAG[] = []; + const elementListAkiba: TAG[] = []; + const elementListAnime: TAG[] = []; + const elementListAnimeSeason: TAG[] = []; + const elementListGame: TAG[] = []; + const elementListHobby: TAG[] = []; + const elementListOther: TAG[] = []; + for (const tag of tagList) { + if (tag.category == "PCパーツ") { + elementListPcPart.push({ tag: tag.tag, count: tag.count, primary: tag.tag == "PCパーツ" }); + } else if (tag.category == "アキバ") { + elementListAkiba.push({ tag: tag.tag, count: tag.count, primary: tag.tag == "アキバ" }); + } else if (tag.category == "アニメ") { + elementListAnime.push({ tag: tag.tag, count: tag.count, primary: tag.tag == "アニメ" }); + } else if (tag.category == "ゲーム") { + elementListGame.push({ tag: tag.tag, count: tag.count, primary: tag.tag == "ゲーム" }); + } else if (tag.category == "ホビー") { + elementListHobby.push({ tag: tag.tag, count: tag.count, primary: tag.tag == "ホビー" }); + } else if (tag.tag.match(/^\d+(春|夏|秋|冬)?アニメ$/)) { + elementListAnimeSeason.push({ tag: tag.tag, count: tag.count }); + } else if (tag.tag == "G.E.M.シリーズ") { + elementListHobby.push({ tag: tag.tag, count: tag.count }); + } else if (["3DS", "PS4ゲームレビュー", "PS Vita", "PS5ゲームレビュー", "Switchインディーズ", "ポケモンGO", "Steamゲームレビュー"].includes(tag.tag)) { + elementListGame.push({ tag: tag.tag, count: tag.count }); + } else { + elementListOther.push({ tag: tag.tag, count: tag.count }); + } + } return ( -
-

著名なタグ一覧

-

記事にセットされているタグの一覧

-
- {tagsElement} -
+
+ {createList("PCパーツ", elementListPcPart)} + {createList("アキバ", elementListAkiba)} + {createList("ゲーム", elementListGame)} + {createList("ホビー", elementListHobby)} + {createList("カテゴリなし", elementListOther)} + {createList("アニメ", elementListAnime)} + {createList("アニメ(時期別)", elementListAnimeSeason)}
); } +function createList(headerLabel: string, tagList: { tag: string, count: number, primary?: boolean }[]) { + const sortedList = tagList.toSorted((a, b) => { + if (a.primary == true) { + return -1; + } else if (b.primary == true) { + return 1; + } else { + return b.count - a.count; + }; + }) + const elementList: JSX.Element[] = []; + sortedList.forEach(t => { + elementList.push( + {t.tag}({t.count}) + ) + }) + return (<> +

{headerLabel}

+
+ {elementList} +
+ ); +} \ No newline at end of file -- cgit v1.2.3