diff --git a/layout/includes/additional-js.pug b/layout/includes/additional-js.pug index 9bae95a..6c8874e 100644 --- a/layout/includes/additional-js.pug +++ b/layout/includes/additional-js.pug @@ -52,7 +52,7 @@ div != partial("includes/third-party/umami_analytics", {}, { cache: true }) if theme.busuanzi.site_uv || theme.busuanzi.site_pv || theme.busuanzi.page_pv - script(async data-pjax src= theme.asset.busuanzi || '//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js') + script(async data-pjax src=url_for(theme.asset.busuanzi) || '//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js') != partial('includes/third-party/search/index', {}, { cache: true }) diff --git a/layout/includes/page/shuoshuo.pug b/layout/includes/page/shuoshuo.pug index ee36041..3e5f15b 100644 --- a/layout/includes/page/shuoshuo.pug +++ b/layout/includes/page/shuoshuo.pug @@ -49,6 +49,7 @@ if !page.shuoshuo_url script(type='application/json' id='shuoshuo-data')!= safeJSON(localDate) + - const { enable, native, placeholder, field } = theme.lazyload script. (() => { const limitConfig = !{ JSON.stringify(page.limit || {}) } @@ -84,6 +85,36 @@ return `${year}-${month}-${day} ${hour}:${minute}:${second}` } + const addLazyload = str => { + const config = { + enable: !{Boolean(enable)}, + native: !{Boolean(native)}, + field: '!{field}', + placeholder: '!{url_for(placeholder)}', + } + + if (!config.enable || config.field !== 'site') return str + const parser = new DOMParser() + const doc = parser.parseFromString(str, 'text/html') + const images = doc.querySelectorAll('img') + + images.forEach(img => { + if (config.native) { + img.setAttribute('loading', 'lazy') + } else { + const src = img.getAttribute('src') + img.setAttribute('data-lazy-src', src) + + if (config.placeholder) { + img.setAttribute('src', config.placeholder) + } else { + img.removeAttribute('src') + } + } + }) + return doc.body.innerHTML + } + let currentPage = 1 const itemsPerPage = 8 let totalPages = 0 @@ -117,7 +148,7 @@ -
${item.content}
+
${addLazyload(item.content)}