Files
hexo-theme-butterfly/scripts/post-lazyload.js
hwy0127@gmail.com 6cdd19e07f 1. Feature: 可關閉圖片懶加載
2. Feature: 增加頁面排版,可選擇把右邊欄放在左邊
3. Feature: 增加 Note (Bootstrap Callout) (移植於next主題)
4. Feature: 手機上能夠查看TOC
5. Feature: 增加直達評論按鈕
6. Fix: 修復post頁在寬度1024px下的顯示bug
7. Fix: 修復代碼框部分語言沒有顯示正確的代碼語言
8. Fix: 修復設置裏把Disqus註釋掉無法運行的bug
2019-08-11 19:57:09 +08:00

20 lines
504 B
JavaScript

'use strict';
let cheerio;
hexo.extend.filter.register('after_post_render', data => {
var theme = hexo.theme.config;
if (!theme.lazyload.enable) return;
if (!cheerio) cheerio = require('cheerio');
const $ = cheerio.load(data.content, {decodeEntities: false});
const images = $('img');
if (!images.length) return;
images.each((i, o) => {
let src = $(o).attr('src');
$(o).attr('data-src', src).removeAttr('src');
$(o).addClass('lozad');
});
data.content = $.html();
}, 0);