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 a9e94d4 commit 5b27f6b
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions lib/routes/minecraft/news.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,26 @@ export const route: Route = {
url: 'https://www.minecraft.net/',
description: 'Catch up on the latest articles',
zh: {
name: 'Minecraft最近新闻',
name: 'Minecraft 最近新闻',
},
};

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';
handler: async (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';

const response = await got(jsonUrl);
const data = JSON.parse(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.description || '',
}));

ctx.state.data = {
title: 'Minecraft News',
link: baseUrl,
description: 'Catch up on the latest articles',
item: items,
};
}
ctx.state.data = {
title: 'Minecraft News',
link: baseUrl,
description: 'Catch up on the latest articles',
item: items,
};
},
};

0 comments on commit 5b27f6b

Please sign in to comment.