mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-08 05:59:00 +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,7 +1,19 @@
|
||||
const utils = require('../../lib/utils/common-utils');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
describe('common-utils', () => {
|
||||
it('toTitleCase', async () => {
|
||||
expect(utils.toTitleCase('RSSHub IS AS aweSOme aS henry')).toBe('Rsshub Is As Awesome As Henry');
|
||||
});
|
||||
|
||||
it('addNoReferrer', async () => {
|
||||
const data = "<div><img data-src='user-images.githubusercontent.com/5896343/60762836-02746d80-a060-11e9-8947-76b3b3d3b731.png' remove='remove' remove2='remove2'></div>";
|
||||
|
||||
const $ = cheerio.load(data);
|
||||
|
||||
utils.addNoReferrer($, 'div', 'data-src', 'https://', ['remove', 'remove2']);
|
||||
const result = $('div').html();
|
||||
|
||||
expect(result).toBe('<img src="https://user-images.githubusercontent.com/5896343/60762836-02746d80-a060-11e9-8947-76b3b3d3b731.png" referrerpolicy="no-referrer">');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user