mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-06 13:08:14 +08:00
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
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { addNoReferrer } = require('@/utils/common-utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const link = 'https://developers.weixin.qq.com/community/plugins';
|
||||
@@ -37,11 +38,8 @@ module.exports = async (ctx) => {
|
||||
});
|
||||
const id = 'x-rsshub';
|
||||
const $ = cheerio.load(`<div id="${id}">${pluginDetail.data.data.Content}</div>`);
|
||||
$('img').each((index, item) => {
|
||||
item = $(item);
|
||||
item.attr('src', item.attr('data-src'));
|
||||
item.attr('referrerpolicy', 'no-referrer');
|
||||
});
|
||||
|
||||
addNoReferrer($, `#${id}`, 'data-src');
|
||||
|
||||
item.description = $(`#${id}`).html();
|
||||
ctx.cache.set(key, item.description);
|
||||
|
||||
Reference in New Issue
Block a user