Files
RSSHub/lib/routes/8btc/author.js
T
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

52 lines
1.5 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
const { addNoReferrer } = require('@/utils/common-utils');
module.exports = async (ctx) => {
const authorid = ctx.params.authorid;
const response = await got.get(`https://webapi.8btc.com/bbt_api/comments/list?author_id=${authorid}&fetch_num=20`);
const ProcessFeed = (data) => {
const $ = cheerio.load(data);
addNoReferrer($, '.bbt-html');
// 提取内容
return $('.bbt-html').html();
};
const items = await Promise.all(
response.data.data.list.map(async (item) => {
const link = `https://www.8btc.com/article/${item.post_id}`;
const cache = await ctx.cache.get(link);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await got({
method: 'get',
url: link,
});
const description = ProcessFeed(response.data);
const single = {
title: item.post.title,
description,
pubDate: item.date_gmt,
link: link,
author: item.reviewer.name,
};
ctx.cache.set(link, JSON.stringify(single));
return Promise.resolve(single);
})
);
ctx.state.data = {
title: '巴比特作者专栏',
link: `https://www.8btc.com/author/${authorid}`,
description: '巴比特作者专栏',
item: items,
};
};