feat(route/pcr/news): Fetch full text (#14559)

* feat(route/pcr/news): Fetch full text

* fix(route/pcr/news): add missing language code

* fix(route/pcr/news) Use cache.tryGet()

* refactor: migrate to v2

---------
This commit is contained in:
randompasser
2024-02-28 02:39:33 +08:00
committed by GitHub
parent b8a1a5d98b
commit a98079239b
7 changed files with 94 additions and 52 deletions
+1 -1
View File
@@ -1005,7 +1005,7 @@ router.get('/avgle/videos/:order?/:time?/:top?', lazyloadRouteHandler('./routes/
router.get('/avgle/search/:keyword/:order?/:time?/:top?', lazyloadRouteHandler('./routes/avgle/videos.js'));
// 公主链接公告
router.get('/pcr/news', lazyloadRouteHandler('./routes/pcr/news'));
// router.get('/pcr/news', lazyloadRouteHandler('./routes/pcr/news'));
router.get('/pcr/news-tw', lazyloadRouteHandler('./routes/pcr/news-tw'));
router.get('/pcr/news-cn', lazyloadRouteHandler('./routes/pcr/news-cn'));
-31
View File
@@ -1,31 +0,0 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const response = await got({
method: 'get',
url: 'https://priconne-redive.jp/news/',
});
const data = response.data;
const $ = cheerio.load(data);
const list = $('.article_box');
let itemPicUrl;
ctx.state.data = {
title: '公主链接日服-新闻',
link: 'https://priconne-redive.jp/news/',
item:
list &&
list
.map((index, item) => {
item = $(item);
itemPicUrl = item.find('img.attachment-news-thumbnail').attr('src');
return {
title: item.find('h4').text(),
description: `${item.find('.description p').text()}<br><img src="${itemPicUrl}">`,
link: item.find('a').first().attr('href'),
pubDate: item.find('.time').text(),
};
})
.get(),
};
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
'/news': ['SayaSS'],
};
+54
View File
@@ -0,0 +1,54 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const parseContent = (htmlString) => {
const $ = cheerio.load(htmlString);
$('.contents-body h3').remove();
const time = $('.meta-info .time').text().trim();
$('.meta-info').remove();
const content = $('.contents-body');
return {
description: content.html(),
pubDate: new Date(time),
};
};
const response = await got({
method: 'get',
url: 'https://priconne-redive.jp/news/',
});
const data = response.data;
const $ = cheerio.load(data);
const list = $('.article_box');
const out = await Promise.all(
list.map((index, item) => {
item = $(item);
const link = item.find('a').first().attr('href');
return ctx.cache.tryGet(link, async () => {
const rssitem = {
title: item.find('h4').text(),
link,
};
const response = await got(link);
const result = parseContent(response.data);
rssitem.description = result.description;
rssitem.pubDate = result.pubDate;
return rssitem;
});
})
);
ctx.state.data = {
title: '公主链接日服-新闻',
link: 'https://priconne-redive.jp/news/',
language: 'ja',
item: out,
};
};
+13
View File
@@ -0,0 +1,13 @@
module.exports = {
'priconne-redive.jp': {
_name: 'プリンセスコネクト!Re:Dive',
'.': [
{
title: 'News',
docs: 'https://docs.rsshub.app/routes/game#princess-connect-re-dive-%E3%83%97%E3%83%AA%E3%83%B3%E3%82%BB%E3%82%B9%E3%82%B3%E3%83%8D%E3%82%AF%E3%83%88%EF%BC%81re-dive',
source: ['/news'],
target: '/priconne-redive/news',
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/news', require('./news'));
};
+20 -20
View File
@@ -447,13 +447,27 @@
<Route author="justjustCC" example="/ps/monthly-games" path="/ps/monthly-games" />
## psnine {#psnine}
## PRINCESS CONNECT! Re Dive プリンセスコネクト!Re Dive {#princess-connect-re-dive-%E3%83%97%E3%83%AA%E3%83%B3%E3%82%BB%E3%82%B9%E3%82%B3%E3%83%8D%E3%82%AF%E3%83%88%EF%BC%81re-dive}
### 首页 - 白金攻略 / 游戏开箱 {#psnine-shou-ye-bai-jin-gong-lve-you-xi-kai-xiang}
### 日服公告 {#princess-connect-re-dive-%E3%83%97%E3%83%AA%E3%83%B3%E3%82%BB%E3%82%B9%E3%82%B3%E3%83%8D%E3%82%AF%E3%83%88%EF%BC%81re-dive-ri-fu-gong-gao}
<Route author="SayaSS" example="/priconne-redive/news" path="/priconne-redive/news" radar="1" />
### 台服公告 {#princess-connect-re-dive-%E3%83%97%E3%83%AA%E3%83%B3%E3%82%BB%E3%82%B9%E3%82%B3%E3%83%8D%E3%82%AF%E3%83%88%EF%BC%81re-dive-tai-fu-gong-gao}
<Route author="hoilc" example="/pcr/news-tw" path="/pcr/news-tw" />
### 国服公告 {#princess-connect-re-dive-%E3%83%97%E3%83%AA%E3%83%B3%E3%82%BB%E3%82%B9%E3%82%B3%E3%83%8D%E3%82%AF%E3%83%88%EF%BC%81re-dive-guo-fu-gong-gao}
<Route author="KotoriK" example="/pcr/news-cn" path="/pcr/news-cn" />
## PSN 中文站 {#psn-zhong-wen-zhan}
### 首页 - 白金攻略 / 游戏开箱 {#psn-zhong-wen-zhan-shou-ye-bai-jin-gong-lve-you-xi-kai-xiang}
<Route author="LightStrawberry" example="/psnine/index" path="/psnine/index" />
### 节点 {#psnine-jie-dian}
### 节点 {#psn-zhong-wen-zhan-jie-dian}
<Route author="nczitzk" example="/psnine/node/news" path="/psnine/node/:id?/:order?" paramsDesc={['节点 id,见下表,默认为 news', '排序,可选 `date` 即最新,默认为 `obdate` 即综合排序']}>
| 站务 | 活动 | 旅记 | 折扣 | 会免 |
@@ -473,15 +487,15 @@
| famitsu | ign | ucg |
</Route>
### 数折 - 折扣信息推送 {#psnine-shu-zhe-zhe-kou-xin-xi-tui-song}
### 数折 - 折扣信息推送 {#psn-zhong-wen-zhan-shu-zhe-zhe-kou-xin-xi-tui-song}
<Route author="LightStrawberry" example="/psnine/shuzhe" path="/psnine/shuzhe" />
### 闲游 - 二手盘信息 {#psnine-xian-you-er-shou-pan-xin-xi}
### 闲游 - 二手盘信息 {#psn-zhong-wen-zhan-xian-you-er-shou-pan-xin-xi}
<Route author="LightStrawberry" example="/psnine/trade" path="/psnine/trade" />
### 游戏 - 新游戏奖杯信息 {#psnine-you-xi-xin-you-xi-jiang-bei-xin-xi}
### 游戏 - 新游戏奖杯信息 {#psn-zhong-wen-zhan-you-xi-xin-you-xi-jiang-bei-xin-xi}
<Route author="LightStrawberry" example="/psnine/game" path="/psnine/game" />
@@ -640,20 +654,6 @@ Due to the regional restrictions, an RSSHub deployment in China Mainland may not
<Route author="wushijishan" example="/diershoubing/news" path="/diershoubing/news" />
## 公主链接 {#gong-zhu-lian-jie}
### 日服公告 {#gong-zhu-lian-jie-ri-fu-gong-gao}
<Route author="SayaSS" example="/pcr/news" path="/pcr/news" />
### 台服公告 {#gong-zhu-lian-jie-tai-fu-gong-gao}
<Route author="hoilc" example="/pcr/news-tw" path="/pcr/news-tw" />
### 国服公告 {#gong-zhu-lian-jie-guo-fu-gong-gao}
<Route author="KotoriK" example="/pcr/news-cn" path="/pcr/news-cn" />
## 怪物猎人世界 {#guai-wu-lie-ren-shi-jie}
### 更新情报 {#guai-wu-lie-ren-shi-jie-geng-xin-qing-bao}