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:
Henry Wang
2019-07-08 04:45:02 +01:00
committed by DIYgod
parent ffcca63d36
commit d09affa703
30 changed files with 127 additions and 308 deletions

View File

@@ -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">');
});
});