diff --git a/docs/README.md b/docs/README.md
index f8dc0bd85a..ca33b6dfee 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -3077,7 +3077,7 @@ type 为 all 时,category 参数不支持 cost 和 free
-### instapaper
+### Instapaper
@@ -3093,7 +3093,7 @@ type 为 all 时,category 参数不支持 cost 和 free
### 北京天文馆
-
+
### 洛谷
diff --git a/lib/routes/bjp/apod.js b/lib/routes/bjp/apod.js
index 2e86997dd1..488a980971 100644
--- a/lib/routes/bjp/apod.js
+++ b/lib/routes/bjp/apod.js
@@ -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 = `
`;
+
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);
})
);