Skip to content

Commit

Permalink
Update news.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
OutlinedArc217 authored Dec 22, 2024
1 parent 6c11730 commit 3acdb19
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions lib/routes/minecraft/news.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

0 comments on commit 3acdb19

Please sign in to comment.