From 3acdb19dad8d0a626d167a5fe0a303dc6abb20c0 Mon Sep 17 00:00:00 2001 From: OutlinedArc217 <67988913+OutlinedArc217@users.noreply.github.com> Date: Sun, 22 Dec 2024 14:13:30 +0800 Subject: [PATCH] Update news.ts --- lib/routes/minecraft/news.ts | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/lib/routes/minecraft/news.ts b/lib/routes/minecraft/news.ts index eff406ad23cc29..4096c42f7cb6c1 100644 --- a/lib/routes/minecraft/news.ts +++ b/lib/routes/minecraft/news.ts @@ -31,23 +31,19 @@ export async function handler(ctx: any) { const jsonUrl = 'https://www.minecraft.net/content/minecraftnet/language-masters/en-us/articles/jcr:content/root/container/image_grid_a.articles.page-1.json'; const baseUrl = 'https://www.minecraft.net'; - try { - const response = await got(jsonUrl, { responseType: 'json' }); - const data = response.body; + const response = await got(jsonUrl); + const data = JSON.parse(response.body); - const items = data.article_grid.map((article: any) => ({ - title: article.default_tile?.title || 'No title available', - link: new URL(article.article_url, baseUrl).href, - description: article.default_tile?.subtitle || '', - })); + const items = data.article_grid.map((article: any) => ({ + title: article.default_tile.title || 'No title available', + link: new URL(article.article_url, baseUrl).href, + description: article.default_tile.subtitle || '', + })); - ctx.state.data = { - title: 'Minecraft News', - link: baseUrl, - description: 'Catch up on the latest articles', - item: items, - }; - } catch (error) { - ctx.throw(500, `Error fetching articles: ${error.message}`); - } + ctx.state.data = { + title: 'Minecraft News', + link: baseUrl, + description: 'Catch up on the latest articles', + item: items, + }; }