feat(route): famitsu (#11682)

This commit is contained in:
Tony 2023-01-24 17:14:48 +02:00 committed by GitHub
parent 5fd912eece
commit c32a46f80a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 105 additions and 0 deletions

View File

@ -337,3 +337,15 @@ News data from https://warthunder.com/en/news/
The year, month and day provided under UTC time zone are the same as the official website, so please ignore the specific time!!!
</RouteEn>
## ファミ通
### Category
<RouteEn author="TonyRL" example="/famitsu/category/new-article" path="/famitsu/category/:category?" :paramsDesc="['Category, see table below, `new-article` by default']" radar="1">
| 新着 | PS5 | Switch | PS4 | ニュース | ゲームニュース | PR TIMES | 動画 | 特集・企画記事 | インタビュー | 取材・リポート | レビュー | インディーゲーム |
| ----------- | --- | ------ | --- | ---- | --------- | -------- | ------ | --------------- | --------- | ------------ | ------ | ---------- |
| new-article | ps5 | switch | ps4 | news | news-game | prtimes | videos | special-article | interview | event-report | review | indie-game |
</RouteEn>

View File

@ -967,6 +967,18 @@ Example`https://www.iyingdi.com/tz/people/55547` id 是 `55547`
<Route author="magic-akari" example="/kirara/news" path="/kirara/news"/>
## ファミ通
### 分类
<Route author="TonyRL" example="/famitsu/category/new-article" path="/famitsu/category/:category?" :paramsDesc="['分类,见下表,预设为 `new-article`']" radar="1">
| 新着 | PS5 | Switch | PS4 | ニュース | ゲームニュース | PR TIMES | 動画 | 特集・企画記事 | インタビュー | 取材・リポート | レビュー | インディーゲーム |
| ----------- | --- | ------ | --- | ---- | --------- | -------- | ------ | --------------- | --------- | ------------ | ------ | ---------- |
| new-article | ps5 | switch | ps4 | news | news-game | prtimes | videos | special-article | interview | event-report | review | indie-game |
</Route>
## マギアレコードMagia Record, 魔法纪录)
### 游戏公告

View File

@ -0,0 +1,62 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const baseUrl = 'https://www.famitsu.com';
module.exports = async (ctx) => {
const { category = 'new-article' } = ctx.params;
const url = `${baseUrl}/search/?category=${category}`;
const { data } = await got(url);
const $ = cheerio.load(data);
const list = $('.col-12 .card__body')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.find('.card__title').text(),
link: new URL(item.find('.card__title a').attr('href'), baseUrl).href,
pubDate: timezone(parseDate(item.find('time').attr('datetime'), 'YYYY.MM.DDTHH:mm'), +9),
};
})
.filter((item) => item.link.startsWith('https://www.famitsu.com/news/'));
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data } = await got(item.link);
const $ = cheerio.load(data);
// remove ads
$('.article-body__contents-pr-primary').remove();
// fix header image
$('.article-body div.media-image').each((_, e) => {
e.tagName = 'img';
e.attribs.src = e.attribs.style.match(/url\((.+?)\);/)[1];
delete e.attribs['data-src'];
delete e.attribs.style;
});
// remove white space
$('.article-body__contents-img-block, .article-body__contents-img-common-col').each((_, e) => {
delete e.attribs.style;
});
item.description = $('.article-body').html();
return item;
})
)
);
ctx.state.data = {
title: $('head title').text(),
description: $('head meta[name="description"]').attr('content'),
image: 'https://www.famitsu.com/img/1812/favicons/apple-touch-icon.png',
link: url,
item: items,
language: 'ja',
};
};

View File

@ -0,0 +1,3 @@
module.exports = {
'/category/:category?': ['TonyRL'],
};

13
lib/v2/famitsu/radar.js Normal file
View File

@ -0,0 +1,13 @@
module.exports = {
'famitsu.com': {
_name: 'ファミ通',
'.': [
{
title: '分类',
docs: 'https://docs.rsshub.app/game.html#ファミ-tong',
source: ['/search'],
target: (_, url) => `/famitsu/category/${new URL(url).searchParams.get('category')}`,
},
],
},
};

3
lib/v2/famitsu/router.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/category/:category?', require('./category'));
};