Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route/nintendo): Add 任天堂官网 #17255

Closed
wants to merge 11 commits into from
3 changes: 3 additions & 0 deletions lib/routes/nintendo/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ import type { Namespace } from '@/types';
export const namespace: Namespace = {
name: 'Nintendo',
url: 'nintendo.com',
zh: {
name: '任天堂 官方网站(日本、香港)',
},
};
72 changes: 72 additions & 0 deletions lib/routes/nintendo/news-hk.ts
Original file line number Diff line number Diff line change
@@ -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) {

Check failure

Code scanning / ESLint

Disallow unused variables Error

'ctx' is defined but never used.
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),

Check failure

Code scanning / ESLint

Enforce consistent spacing before and after commas Error

A space is required after ','.
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”的第一个元素
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,
};
}
68 changes: 68 additions & 0 deletions lib/routes/nintendo/news-jp.ts
Original file line number Diff line number Diff line change
@@ -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) {

Check failure

Code scanning / ESLint

Disallow unused variables Error

'ctx' is defined but never used.
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,
Fixed Show fixed Hide fixed
// 文章链接
link: item.topic_url,
Fixed Show fixed Hide fixed
// 文章发布日期
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,
Fixed Show fixed Hide fixed
category:item.categorylarge.name,
Fixed Show fixed Hide fixed
}));
// 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(日本)主页资讯',
Fixed Show fixed Hide fixed
link: 'https://www.nintendo.com/jp/topics',
Fixed Show fixed Hide fixed
description: 'Nintendo JP',
Fixed Show fixed Hide fixed
item:items,
Fixed Show fixed Hide fixed
};
}
Loading