Files
RSSHub/lib/routes/zreading/home.js
Henry Wang d09affa703 feat: add addNoReferrer in common-utils (#2571)
* fix: no-referrer tag

* chore: merge qdaily routes

* feat: add addNoReferrer in common-utils

This adds no-referrer attribute to images.
Parameters:

- add no-referrer attribute to images
- $: cheerio selector
- source: source selector, string
- target: target attribute name, typically for lazyload imgs, string
- srcPrefix: prefix for src, string
- removeAttr: attributes to remove, array: ['attrA','attrB']

* test: add test case

* doc: update
2019-07-08 11:45:02 +08:00

54 lines
1.4 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
const parser = require('@/utils/rss-parser');
const { addNoReferrer } = require('@/utils/common-utils');
module.exports = async (ctx) => {
const feed = await parser.parseURL('http://www.zreading.cn/feed');
const ProcessFeed = (data) => {
const $ = cheerio.load(data);
$('.grap script').remove();
$('.grap .adsbygoogle').remove();
addNoReferrer($, '.grap');
// 提取内容
return $('.grap').html();
};
const items = await Promise.all(
feed.items.map(async (item) => {
const cache = await ctx.cache.get(item.link);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await got({
method: 'get',
url: item.link,
});
const description = ProcessFeed(response.data);
const single = {
title: item.title,
description,
pubDate: item.pubDate,
link: item.link,
author: item.author,
};
ctx.cache.set(item.link, JSON.stringify(single));
return Promise.resolve(single);
})
);
ctx.state.data = {
title: feed.title,
link: feed.link,
description: feed.description,
item: items,
};
};