From 1f89ef4003a7e92ca94efb3ff0ff1e2a38f0de76 Mon Sep 17 00:00:00 2001 From: -akku- <151517253+akku1139@users.noreply.github.com> Date: Fri, 16 Feb 2024 17:48:00 +0900 Subject: [PATCH] =?UTF-8?q?=E3=81=84=E3=81=84=E6=84=9F=E3=81=98=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Articles.astro | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/components/Articles.astro b/src/components/Articles.astro index e8443ab..4a7da4f 100644 --- a/src/components/Articles.astro +++ b/src/components/Articles.astro @@ -51,16 +51,22 @@ type QiitaArticle = { }; type QiitaContent = QiitaArticle[]; -const zennData: ZennContent = await ofetch("https://zenn.dev/api/articles?publication_name=trans&order=latest", { - parseResponse: (res: string) => {return {site: "zenn", ...JSON.parse(res)}}, +const zennData: ZennArticle[] = await ofetch("https://zenn.dev/api/articles?publication_name=trans&order=latest", { + parseResponse: (res: string) => { + return JSON.parse(res).articles.map((article) => {return {site: "zenn", ...article}}); + } }); -const noteData: NoteContent = await ofetch("https://note.com/api/v1/layout/magazine/me3717a077c16/section?page=1", { - parseResponse: (res: string) => {return {site: "note", ...JSON.parse(res)}}, +const noteData: NoteArticle[] = await ofetch("https://note.com/api/v1/layout/magazine/me3717a077c16/section?page=1", { + parseResponse: (res: string) => { + return JSON.parse(res).data.section.contents.map((article) => {return {site: "note", ...article}}); + }, }); -const qiitaData: QiitaContent = await ofetch("https://qiita.com/api/v2/items?page=1&per_page=20&query=org%3Atrans-dev&sort=created", { - parseResponse: (res: string) => {return {site: "qiita", ...JSON.parse(res)}}, +const qiitaData: QiitaArticle[] = await ofetch("https://qiita.com/api/v2/items?page=1&per_page=20&query=org%3Atrans-dev&sort=created", { + parseResponse: (res: string) => { + return JSON.parse(res).map((article) => {return {site: "qiita", ...article}}); + }, }); -const combinedData: (ZennArticle | NoteArticle | QiitaArticle)[] = [...zennData.articles, ...noteData.data.section.contents, ...qiitaData]; +const combinedData: (ZennArticle | NoteArticle | QiitaArticle)[] = zennData + noteData + qiitaData; const compareDates = (a: { published_at: string } | { publish_at: string } | { created_at: string}, b: { published_at: string } | { publish_at: string } | { created_at: string}, ): number => { @@ -82,7 +88,7 @@ console.log(sortedData); poster_name={article.user.name} poster_icon_url={article.user.avatar_small_url} tag={(article.article_type === "idea" ? {text: "IDEA", bg: "bg-violet-500"} : {text: "TECH", bg: "bg-blue-200"})} - > + >
{article.emoji}
); } else if(article.site === "note") {