Merge branch 'master' of github.com:DIYgod/RSSHub
This commit is contained in:
commit
a65934834b
|
|
@ -33,8 +33,8 @@ module.exports = async (ctx) => {
|
|||
list &&
|
||||
list
|
||||
.map((index, item) => ({
|
||||
title: `第${index + 1}话 ${$(item)
|
||||
.find('p.fs12 a')
|
||||
title: `${$(item)
|
||||
.find('p.site-piclist_info_title a')
|
||||
.text()}`,
|
||||
description: `<img referrerpolicy="no-referrer" src="${$(item)
|
||||
.find('img')
|
||||
|
|
|
|||
|
|
@ -1,38 +1,53 @@
|
|||
const axios = require('axios');
|
||||
const config = require('../../config');
|
||||
|
||||
// 参考:https://github.com/izzyleung/ZhihuDailyPurify/wiki/%E7%9F%A5%E4%B9%8E%E6%97%A5%E6%8A%A5-API-%E5%88%86%E6%9E%90
|
||||
// 文章给出了v4版 api的信息,包含全文api
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const today = await axios({
|
||||
const listRes = await axios({
|
||||
method: 'get',
|
||||
url: 'https://news-at.zhihu.com/api/2/news/latest', // 旧版api,可以获取文章的url。参考:https://github.com/izzyleung/ZhihuDailyPurify/wiki/%E7%9F%A5%E4%B9%8E%E6%97%A5%E6%8A%A5-API-%E5%88%86%E6%9E%90
|
||||
url: 'https://news-at.zhihu.com/api/4/news/latest',
|
||||
headers: {
|
||||
'User-Agent': config.ua,
|
||||
Referer: 'https://daily.zhihu.com', // 不知道应该写什么比较好,随便写一个吧
|
||||
Referer: 'https://news-at.zhihu.com/api/4/news/latest',
|
||||
},
|
||||
});
|
||||
const d = new Date();
|
||||
// todayfmt: YYYYMMDD
|
||||
const todayfmt = `${d.getFullYear()}${d.getMonth() > 8 ? d.getMonth() + 1 : '0' + (d.getMonth() + 1)}${d.getDate()}`;
|
||||
// 根据api的说明,过滤掉极个别站外链接
|
||||
const storyList = listRes.data.stories.filter((el) => el.type === 0);
|
||||
const resultItem = [];
|
||||
for (let i = 0; i < storyList.length; i++) {
|
||||
const url = 'https://news-at.zhihu.com/api/4/news/' + storyList[i].id;
|
||||
const item = {
|
||||
title: storyList[i].title,
|
||||
description: '',
|
||||
link: url,
|
||||
};
|
||||
const key = 'daily' + storyList[i].id;
|
||||
const value = await ctx.cache.get(key);
|
||||
|
||||
const yesterday = await axios({
|
||||
method: 'get',
|
||||
url: `https://news-at.zhihu.com/api/2/news/before/${todayfmt}`, // 旧版api,可以获取文章的url。参考:https://github.com/izzyleung/ZhihuDailyPurify/wiki/%E7%9F%A5%E4%B9%8E%E6%97%A5%E6%8A%A5-API-%E5%88%86%E6%9E%90
|
||||
headers: {
|
||||
'User-Agent': config.ua,
|
||||
Referer: 'https://daily.zhihu.com',
|
||||
},
|
||||
});
|
||||
if (value) {
|
||||
item.description = value;
|
||||
} else {
|
||||
const storyDetail = await axios({
|
||||
method: 'get',
|
||||
url: url,
|
||||
headers: {
|
||||
'User-Agent': config.ua,
|
||||
Referer: url,
|
||||
},
|
||||
});
|
||||
item.description = storyDetail.data.body;
|
||||
ctx.cache.set(key, storyDetail.data.body, 24 * 60 * 60);
|
||||
}
|
||||
|
||||
const items = today.data.news.concat(yesterday.data.news);
|
||||
resultItem.push(item);
|
||||
}
|
||||
|
||||
ctx.state.data = {
|
||||
title: '知乎日报',
|
||||
link: 'https://daily.zhihu.com',
|
||||
description: '每天3次,每次7分钟',
|
||||
item: items.map((item) => ({
|
||||
title: item.title,
|
||||
description: `<img referrerpolicy="no-referrer" src='${item.image}'/>`, // 暂时没有找到包含正文的api,所以就放一张图吧
|
||||
link: item.share_url,
|
||||
})),
|
||||
item: resultItem,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue