themes\icarus\includes\filters\images.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| const cheerio = require('cheerio');
module.exports = function (hexo) { function normalizeImages(content) { var $ = cheerio.load(content, { decodeEntities: false });
$('img').each(function() { var path = $(this).attr('src'); $(this).attr('src', 'https://images.hongfs.cn' + path); });
return $.html(); }
hexo.extend.filter.register('after_post_render', function (data) { var toprocess = ['excerpt', 'more', 'content'];
for(var i = 0; i < toprocess.length; i++) { var key = toprocess[i];
data[key] = data[key] ? normalizeImages(data[key]) : data[key]; }
return data; }); }
|
themes\icarus\scripts\index.js
1 2
| ... require('../includes/filters/images')(hexo);
|