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

Open
wants to merge 11 commits into
base: master
Choose a base branch
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: '任天堂 官方网站(日本、香港)',
},
};
73 changes: 73 additions & 0 deletions lib/routes/nintendo/news-hk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
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, 2);
console.log(data);
Fixed Show fixed Hide fixed
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);
Fixed Show fixed Hide fixed
// 获取新闻正文
const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
//判断
Fixed Show fixed Hide fixed
console.log(item.link);
Fixed Show fixed Hide fixed
const { data: response } = await got(item.link);
console.log(data);
Fixed Show fixed Hide fixed
console.log(response);
Fixed Show fixed Hide fixed
const $ = load(response);
// 选择类名为“comment-body”的第一个元素
item.description = $('div.topics-articleBody').first().html();
// 上面每个列表项的每个属性都在此重用,
// 并增加了一个新属性“description”
return item;
})
)
);

Fixed Show fixed Hide fixed
console.log(items);
Fixed Show fixed Hide fixed
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);
Fixed Show fixed Hide fixed
const data = response.data.slice(0, 10);
console.log(data);
Fixed Show fixed Hide fixed
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);
Fixed Show fixed Hide fixed
// 获取新闻正文
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);
Fixed Show fixed Hide fixed
return {
title: 'Nintendo(日本)主页资讯',
link: 'https://www.nintendo.com/jp/topics',
description: 'Nintendo JP',
item:items,
};
}
Loading