Files
RSSHub/lib/routes/zhihu/utils.js
T
Sukka d82847f541 style/chore(eslint): enforce new rules (#8040)
* style: prefer object shorthand syntax
* refactor: prefer Array#map over Array#forEach
* style: prefer arrow callback
* chore(eslint): update rules
* style: auto fix by eslint
2021-08-17 22:23:23 +08:00

40 lines
1.3 KiB
JavaScript

const cheerio = require('cheerio');
module.exports = {
header: {
'x-api-version': '3.0.91',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36',
},
ProcessImage(content) {
const $ = cheerio.load(content, { xmlMode: true });
$('noscript').remove();
$('a[data-draft-type="mcn-link-card"]').remove();
$('img.content_image, img.origin_image, img.content-image, img.data-actualsrc, figure>img').each((i, e) => {
if (e.attribs['data-actualsrc']) {
$(e).attr({
src: e.attribs['data-actualsrc'].replace('_b.jpg', '_1440w.jpg'),
width: null,
height: null,
});
} else if (e.attribs['data-original']) {
$(e).attr({
src: e.attribs['data-original'].replace('_r.jpg', '_1440w.jpg'),
width: null,
height: null,
});
} else {
$(e).attr({
src: e.attribs.src.replace('_b.jpg', '_1440w.jpg'),
width: null,
height: null,
});
}
});
return $.html();
},
};