diff --git a/lib/routes/nintendo/namespace.ts b/lib/routes/nintendo/namespace.ts index 99783728bf0ad4..b9ad6e4c33c492 100644 --- a/lib/routes/nintendo/namespace.ts +++ b/lib/routes/nintendo/namespace.ts @@ -3,4 +3,7 @@ import type { Namespace } from '@/types'; export const namespace: Namespace = { name: 'Nintendo', url: 'nintendo.com', + zh: { + name: '任天堂 官方网站(日本、香港)', + }, }; diff --git a/lib/routes/nintendo/news-hk.ts b/lib/routes/nintendo/news-hk.ts new file mode 100644 index 00000000000000..3481edca1c6172 --- /dev/null +++ b/lib/routes/nintendo/news-hk.ts @@ -0,0 +1,72 @@ +import { Route } from '@/types'; +import cache from '@/utils/cache'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; + +export const route: Route = { + path: '/news/hk', + categories: ['game'], + example: '/nintendo/news/hk', + parameters: {}, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['nintendo.com.hk/topics', 'nintendo.com.hk/'], + }, + ], + name: 'News(Hong Kong)', + maintainers: ['benzking'], + handler, + url: 'nintendo.com.hk/topics', +}; + +async function handler(ctx) { + const response = await got('https://www.nintendo.com.hk/api/top/topics_pickup'); + const data = response.data.slice(0, 10); + // console.log(data); + const list = data.map((item) => ({ + // 文章标题 + title: item.title, + // 文章链接 + link: `https://www.nintendo.com.hk${item.href}`, + // 文章发布日期 + pubDate: timezone(parseDate(item.displayDate, 'YYYY.M.D'),+8), + itunes_item_image:item.banner.url, + category:item.category, + })); + // console.log(list); + // 获取新闻正文 + const items = await Promise.all( + list.map((item) => + cache.tryGet(item.link, async () => { + // 判断 + // console.log(item.link); + const { data: response } = await got(item.link); + // console.log(data); + // console.log(response); + const $ = load(response); + // 选择类名为“comment-body”的第一个元素1 + item.description = $('div.topics-articleBody').first().html(); + // 上面每个列表项的每个属性都在此重用, + // 并增加了一个新属性“description” + return item; + }) + ) + ); + // console.log(items); + return { + title: 'Nintendo(香港)主页资讯', + link: 'https://www.nintendo.com.hk/topics/', + description: 'Nintendo 香港有限公司官网刊登的资讯', + item:items, + }; +} diff --git a/lib/routes/nintendo/news-jp.ts b/lib/routes/nintendo/news-jp.ts new file mode 100644 index 00000000000000..f3aba59460af15 --- /dev/null +++ b/lib/routes/nintendo/news-jp.ts @@ -0,0 +1,68 @@ +import { Route } from '@/types'; +import cache from '@/utils/cache'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; + +export const route: Route = { + path: '/news/jp', + categories: ['game'], + example: '/nintendo/news/jp', + parameters: {}, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['nintendo.com/jp'], + }, + ], + name: 'News(JP)', + maintainers: ['benzking'], + handler, + url: 'nintendo.com/jp', +}; + +async function handler(ctx) { + const response = await got('https://www.nintendo.com/jp/topics/c/api/json_list?key=newtopics'); + // console.log(response); + const data = response.data.slice(0, 10); + // console.log(data); + const list = data.map((item) => ({ + // 文章标题 + title: item.title, + // 文章链接 + link: item.topic_url, + // 文章发布日期 + pubDate: parseDate(item.release_date, 'YYYY/M/D HH:mm:ss'), // "release_date": "2024/10/18 17:00:00" + itunes_item_image:item.thumbnail.large.medium, + category:item.categorylarge.name, + })); + // console.log(list); + // 获取新闻正文 + const items = await Promise.all( + list.map((item) => + cache.tryGet(item.link, async () => { + const { data: response } = await got(item.link); + const $ = load(response); + // 选择类名为“comment-body”的第一个元素 + item.description = $('div.topics-articleBody').first().html(); + // 上面每个列表项的每个属性都在此重用, + // 并增加了一个新属性“description” + return item; + }) + ) + ); + // console.log(items); + return { + title: 'Nintendo(日本)主页资讯', + link: 'https://www.nintendo.com/jp/topics', + description: 'Nintendo JP', + item:items, + }; +}