mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-11 07:40:26 +08:00
* 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
64 lines
1.7 KiB
JavaScript
64 lines
1.7 KiB
JavaScript
const got = require('@/utils/got');
|
|
const cheerio = require('cheerio');
|
|
const { addNoReferrer } = require('@/utils/common-utils');
|
|
|
|
module.exports = async (ctx) => {
|
|
const baseUrl = 'http://weekly.dockone.io';
|
|
const response = await got({
|
|
method: 'get',
|
|
url: baseUrl,
|
|
headers: {
|
|
Referer: baseUrl,
|
|
},
|
|
});
|
|
|
|
const data = response.data;
|
|
const $ = cheerio.load(data);
|
|
const list = $('.aw-common-list .article').get();
|
|
|
|
const ProcessFeed = (data) => {
|
|
const $ = cheerio.load(data);
|
|
|
|
addNoReferrer($, '.aw-question-detail .content');
|
|
|
|
// 提取内容
|
|
return $('.aw-question-detail .content').html();
|
|
};
|
|
|
|
const items = await Promise.all(
|
|
list.map(async (item) => {
|
|
const $ = cheerio.load(item);
|
|
const $a = $('.aw-question-content a');
|
|
const link = $a.attr('href');
|
|
|
|
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: $a.text(),
|
|
description,
|
|
link: link,
|
|
author: $('.aw-user-name').text(),
|
|
};
|
|
ctx.cache.set(link, JSON.stringify(single));
|
|
return Promise.resolve(single);
|
|
})
|
|
);
|
|
|
|
ctx.state.data = {
|
|
title: $('title').text(),
|
|
link: baseUrl,
|
|
description: $('meta[name="description"]').attr('content') || $('title').text(),
|
|
item: items,
|
|
};
|
|
};
|