From 65a7d502850626598d785f58bf6e554b68124c8c Mon Sep 17 00:00:00 2001 From: ueiu <39592269+ueiu@users.noreply.github.com> Date: Sun, 30 Mar 2025 00:40:24 +0800 Subject: [PATCH] =?UTF-8?q?feat(route/gamekee):=20=E5=A2=9E=E5=8A=A0=20Gam?= =?UTF-8?q?ekee=20=E6=96=B0=E9=97=BB=E8=B7=AF=E7=94=B1=20(#18727)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route/gamekee): 增加 Gamekee 新闻路由 * feat(route/gamekee): 改用 API 请求列表数据 * feat(route/gamekee): remove timezone offset --- lib/routes/gamekee/namespace.ts | 6 ++++ lib/routes/gamekee/news.ts | 64 +++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 lib/routes/gamekee/namespace.ts create mode 100644 lib/routes/gamekee/news.ts diff --git a/lib/routes/gamekee/namespace.ts b/lib/routes/gamekee/namespace.ts new file mode 100644 index 000000000..3e78ecdff --- /dev/null +++ b/lib/routes/gamekee/namespace.ts @@ -0,0 +1,6 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'GameKee | 游戏百科攻略', + url: 'www.gamekee.com', +}; diff --git a/lib/routes/gamekee/news.ts b/lib/routes/gamekee/news.ts new file mode 100644 index 000000000..20c69d8b3 --- /dev/null +++ b/lib/routes/gamekee/news.ts @@ -0,0 +1,64 @@ +import { Route } from '@/types'; +import ofetch from '@/utils/ofetch'; +import { load } from 'cheerio'; +import cache from '@/utils/cache'; +import { parseDate } from '@/utils/parse-date'; +import { config } from '@/config'; + +export const route: Route = { + path: '/news', + categories: ['game'], + example: '/gamekee/news', + radar: [ + { + source: ['gamekee.com', 'gamekee.com/news'], + target: '/news', + }, + ], + name: '游戏情报', + maintainers: ['ueiu'], + handler, + url: 'gamekee.com/news', +}; + +async function handler() { + const rootUrl = 'https://www.gamekee.com'; + const url = `${rootUrl}/v1/index/newsList`; + const { data } = await ofetch(url, { + headers: { + 'game-alias': 'www', + 'device-num': '1', + 'User-Agent': config.ua, + }, + query: { + page_no: 1, + limit: 20, + }, + }); + const list = data.map((item) => { + const link = new URL(`${item.id}.html`, rootUrl).href; + const title = item.title; + const pubDate = parseDate(item.created_at, 'X'); + return { + link, + title, + pubDate, + }; + }); + const items = await Promise.all( + list.map((item) => + cache.tryGet(item.link, async () => { + const response = await ofetch(item.link); + const $ = load(response); + item.description = $('div.content').html(); + return item; + }) + ) + ); + + return { + link: `${rootUrl}/news`, + title: '游戏情报|Gamekee', + item: items, + }; +}