mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
+2
-2
@@ -3077,7 +3077,7 @@ type 为 all 时,category 参数不支持 cost 和 free
|
||||
|
||||
</route>
|
||||
|
||||
### instapaper
|
||||
### Instapaper
|
||||
|
||||
<route name="个人分享" author="LogicJake" example="/instapaper/person/viridiano" path="/instapaper/person"/>
|
||||
|
||||
@@ -3093,7 +3093,7 @@ type 为 all 时,category 参数不支持 cost 和 free
|
||||
|
||||
### 北京天文馆
|
||||
|
||||
<route name="每日一图" author="radaiming" example="/bjp/apod" path="/bjp/apod"/>
|
||||
<route name="每日一图" author="HenryQW" example="/bjp/apod" path="/bjp/apod"/>
|
||||
|
||||
### 洛谷
|
||||
|
||||
|
||||
+31
-27
@@ -5,41 +5,45 @@ module.exports = async (ctx) => {
|
||||
const baseUrl = 'http://www.bjp.org.cn';
|
||||
const indexUrl = baseUrl + '/col/col89/index.html';
|
||||
|
||||
let limit = parseInt(ctx.query.limit);
|
||||
if (isNaN(limit) || limit === 0) {
|
||||
limit = 5;
|
||||
}
|
||||
const res = await axios.get(indexUrl);
|
||||
const data = res.data;
|
||||
const $ = cheerio.load(data);
|
||||
const list = $('b > a');
|
||||
const urls = [];
|
||||
const titles = [];
|
||||
for (let i = 0; i < limit && i < list.length; i++) {
|
||||
urls.push(baseUrl + list[i].attribs.href);
|
||||
titles.push(list[i].attribs.title);
|
||||
}
|
||||
|
||||
const $ = cheerio.load(res.data);
|
||||
|
||||
const list = $('b > a')
|
||||
.slice(0, 10)
|
||||
.get()
|
||||
.map((e) => $(e));
|
||||
|
||||
const items = await Promise.all(
|
||||
urls.map(async (url, i) => {
|
||||
const cache = await ctx.cache.get(url);
|
||||
list.map(async (e) => {
|
||||
const link = `${baseUrl}${e.attr('href')}`;
|
||||
|
||||
const cache = await ctx.cache.get(link);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
const data = (await axios.get(url)).data;
|
||||
const $ = cheerio.load(data);
|
||||
const time = $('meta[name=pubDate]').attr('content');
|
||||
const title = titles[i];
|
||||
|
||||
const data = await axios.get(link);
|
||||
const $ = cheerio.load(data.data);
|
||||
|
||||
const content = $($('body > table')[1]);
|
||||
|
||||
const image = `<img referrerpolicy="no-referrer" src="${baseUrl}${content.find('img').attr('src')}">`;
|
||||
|
||||
const item = {
|
||||
title,
|
||||
pubDate: new Date(time).toUTCString(),
|
||||
description: $('body > table > tbody')
|
||||
.eq(1)
|
||||
.html(),
|
||||
link: url,
|
||||
guid: url,
|
||||
title: $(e).attr('title'),
|
||||
pubDate: new Date($('meta[name=pubDate]').attr('content')).toUTCString(),
|
||||
description:
|
||||
image +
|
||||
content
|
||||
.find('table')
|
||||
.last()
|
||||
.html(),
|
||||
link,
|
||||
guid: link,
|
||||
};
|
||||
ctx.cache.set(url, JSON.stringify(item), limit * 24 * 60 * 60);
|
||||
ctx.cache.set(link, JSON.stringify(item), 5 * 24 * 60 * 60);
|
||||
|
||||
return Promise.resolve(item);
|
||||
})
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user