rss: new /rsshub/rss

This commit is contained in:
DIYgod
2019-01-17 18:41:35 +08:00
parent 850bbf4166
commit 7850b43834

View File

@@ -4,33 +4,40 @@ const cheerio = require('cheerio');
module.exports = async (ctx) => { module.exports = async (ctx) => {
const response = await axios({ const response = await axios({
method: 'get', method: 'get',
url: 'https://github.com/DIYgod/RSSHub/releases.atom', url: 'https://docs.rsshub.app',
headers: {
Referer: 'https://github.com/DIYgod/RSSHub',
},
}); });
const data = response.data; const data = response.data;
const $ = cheerio.load(data, { const $ = cheerio.load(data);
xmlMode: true, const list = $('.routeBlock');
});
const list = $('entry');
ctx.state.data = { ctx.state.data = {
title: 'RSSHub 有新的 RSS 支持', title: 'RSSHub 有新路由啦',
link: 'https://github.com/DIYgod/RSSHub', link: 'https://docs.rsshub.app',
description: '万物皆可 RSS', description: '万物皆可 RSS',
item: item:
list && list &&
list list
.map((index, item) => { .map((index, item) => {
item = $(item); item = $(item);
item.find('.header-anchor').remove();
const titleEle = item.prevAll('h3').eq(0);
return { return {
title: item.find('title').text(), title: `${titleEle.text().slice(2)} - ${item
description: item.find('content').text(), .find('.name')
pubDate: item.find('updated').text(), .contents()
link: item.find('link').attr('href'), .eq(0)
.text()}`,
description: item.html(),
link: `https://docs.rsshub.app#${encodeURIComponent(
titleEle.find('.header-anchor').attr('href') &&
titleEle
.find('.header-anchor')
.attr('href')
.slice(1)
)}`,
guid: item.attr('id'),
}; };
}) })
.get(), .get(),