mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-08 05:59:00 +08:00
feat: add 公主连结台服公告 (#3944)
This commit is contained in:
@@ -207,6 +207,10 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的
|
||||
|
||||
<Route author="SayaSS" example="/pcr/news" path="/pcr/news"/>
|
||||
|
||||
### 台服公告
|
||||
|
||||
<Route author="hoilc" example="/pcr/news-tw" path="/pcr/news-tw"/>
|
||||
|
||||
## 篝火营地
|
||||
|
||||
### 游戏资讯
|
||||
|
||||
@@ -2118,8 +2118,9 @@ router.get('/ddrk/tag/:tag', require('./routes/ddrk/list'));
|
||||
router.get('/ddrk/category/:category', require('./routes/ddrk/list'));
|
||||
router.get('/ddrk/index', require('./routes/ddrk/list'));
|
||||
|
||||
// 公主链接日服公告
|
||||
// 公主链接公告
|
||||
router.get('/pcr/news', require('./routes/pcr/news'));
|
||||
router.get('/pcr/news-tw', require('./routes/pcr/news-tw'));
|
||||
|
||||
// project-zero issues
|
||||
router.get('/project-zero-issues', require('./routes/project-zero-issues/index'));
|
||||
|
||||
71
lib/routes/pcr/news-tw.js
Normal file
71
lib/routes/pcr/news-tw.js
Normal file
@@ -0,0 +1,71 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
const base = 'http://www.princessconnect.so-net.tw';
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const url = `${base}/news`;
|
||||
|
||||
const list_response = await got.get(url);
|
||||
const $ = cheerio.load(list_response.data);
|
||||
|
||||
const list = $('.news_con dl dd').get();
|
||||
|
||||
const parseContent = (htmlString) => {
|
||||
const $ = cheerio.load(htmlString);
|
||||
|
||||
$('.news_con h2 > span').remove();
|
||||
const time = $('.news_con h2')
|
||||
.text()
|
||||
.trim();
|
||||
$('.news_con section h4')
|
||||
.first()
|
||||
.remove();
|
||||
const content = $('.news_con section');
|
||||
|
||||
return {
|
||||
description: content.html(),
|
||||
pubDate: new Date(time),
|
||||
};
|
||||
};
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map(async (item) => {
|
||||
const $ = cheerio.load(item);
|
||||
|
||||
const title = $('a');
|
||||
const path = title.attr('href');
|
||||
|
||||
const link = base + path;
|
||||
|
||||
const cache = await ctx.cache.get(link);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
|
||||
const rssitem = {
|
||||
title: title.text().trim(),
|
||||
link: link,
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await got.get(link);
|
||||
const result = parseContent(response.data);
|
||||
|
||||
rssitem.author = '《超異域公主連結☆Re:Dive》營運團隊';
|
||||
rssitem.description = result.description;
|
||||
rssitem.pubDate = result.pubDate;
|
||||
} catch (err) {
|
||||
return Promise.resolve('');
|
||||
}
|
||||
ctx.cache.set(link, JSON.stringify(rssitem));
|
||||
return Promise.resolve(rssitem);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '公主连结 - 台服公告',
|
||||
link: url,
|
||||
item: out.filter((item) => item !== ''),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user