From 9619cab07b41be833ad276fc321becaec0ad6af4 Mon Sep 17 00:00:00 2001 From: bisnsh Date: Mon, 5 Jan 2026 19:48:25 +0800 Subject: [PATCH] update theme to butterfly --- themes/butterfly/.gitignore | 2 + themes/butterfly/_config.yml | 3 +- .../layout/includes/additional-js.pug | 2 +- themes/butterfly/layout/includes/layout.pug | 28 +- .../layout/includes/page/shuoshuo.pug | 33 +- .../butterfly/layout/includes/pagination.pug | 2 +- .../includes/third-party/comments/artalk.pug | 4 +- .../includes/third-party/math/mermaid.pug | 6 +- .../layout/includes/third-party/pjax.pug | 9 +- .../layout/includes/third-party/prismjs.pug | 6 +- .../includes/third-party/umami_analytics.pug | 14 +- themes/butterfly/package.json | 4 +- themes/butterfly/plugins.yml | 26 +- themes/butterfly/scripts/events/cdn.js | 38 +- themes/butterfly/scripts/events/comment.js | 24 - themes/butterfly/scripts/events/init.js | 4 +- .../butterfly/scripts/events/merge_config.js | 593 ------------------ .../butterfly/scripts/filters/random_cover.js | 54 +- .../scripts/helpers/aside_archives.js | 75 +-- .../scripts/helpers/aside_categories.js | 35 +- .../scripts/helpers/getArchiveLength.js | 35 +- .../scripts/helpers/inject_head_js.js | 6 +- themes/butterfly/scripts/helpers/page.js | 64 +- .../butterfly/scripts/helpers/related_post.js | 114 ++-- themes/butterfly/scripts/tag/link.js | 70 --- themes/butterfly/scripts/tag/mermaid.js | 3 +- .../source/css/_global/function.styl | 2 +- .../source/css/_highlight/highlight.styl | 53 +- .../butterfly/source/css/_mode/darkmode.styl | 5 +- .../butterfly/source/css/_mode/readmode.styl | 1 + themes/butterfly/source/css/_tags/hide.styl | 19 +- themes/butterfly/source/js/main.js | 73 ++- themes/butterfly/source/js/utils.js | 32 +- 33 files changed, 440 insertions(+), 999 deletions(-) create mode 100644 themes/butterfly/.gitignore delete mode 100644 themes/butterfly/scripts/events/comment.js delete mode 100644 themes/butterfly/scripts/events/merge_config.js delete mode 100644 themes/butterfly/scripts/tag/link.js diff --git a/themes/butterfly/.gitignore b/themes/butterfly/.gitignore new file mode 100644 index 0000000..646ac51 --- /dev/null +++ b/themes/butterfly/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +node_modules/ diff --git a/themes/butterfly/_config.yml b/themes/butterfly/_config.yml index eb18c64..39df33c 100644 --- a/themes/butterfly/_config.yml +++ b/themes/butterfly/_config.yml @@ -91,7 +91,8 @@ category_per_img: footer_img: false # Website Background -# Can set it to color or image url +# Can set it to color, image URL or an array containing colors and/or image URLs +# If an array is provided, a random background will be selected from the array on each load background: cover: diff --git a/themes/butterfly/layout/includes/additional-js.pug b/themes/butterfly/layout/includes/additional-js.pug index ebc8c99..fdaa364 100644 --- a/themes/butterfly/layout/includes/additional-js.pug +++ b/themes/butterfly/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=theme.asset.busuanzi ? 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/themes/butterfly/layout/includes/layout.pug b/themes/butterfly/layout/includes/layout.pug index 53e33db..8acabde 100644 --- a/themes/butterfly/layout/includes/layout.pug +++ b/themes/butterfly/layout/includes/layout.pug @@ -13,9 +13,32 @@ html(lang=config.language data-theme=theme.display_mode class=htmlClassHideAside !=partial('includes/loading/index', {}, {cache: true}) if theme.background - #web_bg(style=getBgPath(theme.background)) + if !Array.isArray(theme.background) + #web_bg.bg-animation(style=getBgPath(theme.background)) + else + #web_bg.bg-animation + - const bgStyleArr = theme.background.map(getBgPath) + script. + (() => { + const arr = !{JSON.stringify(bgStyleArr)} + const webBgDiv = document.getElementById('web_bg') + + const setRandomBg = () => { + webBgDiv.style = arr[Math.floor(Math.random() * arr.length)] + requestAnimationFrame(() => webBgDiv.classList.add('bg-animation')) + } + + document.addEventListener('pjax:send', () => { + webBgDiv.style = '' + webBgDiv.classList.remove('bg-animation') + }) + + document.addEventListener('pjax:complete', setRandomBg) + document.addEventListener('DOMContentLoaded', setRandomBg) + })() !=partial('includes/sidebar', {}, {cache: true}) + #body-wrap(class=pageType) include ./header/index.pug @@ -33,5 +56,4 @@ html(lang=config.language data-theme=theme.display_mode class=htmlClassHideAside !=partial('includes/footer', {}, {cache: true}) include ./rightside.pug - include ./additional-js.pug - !=partial('includes/rightmenu',{}, {cache:true}) \ No newline at end of file + include ./additional-js.pug \ No newline at end of file diff --git a/themes/butterfly/layout/includes/page/shuoshuo.pug b/themes/butterfly/layout/includes/page/shuoshuo.pug index 1e2dbee..37f3c4b 100644 --- a/themes/butterfly/layout/includes/page/shuoshuo.pug +++ b/themes/butterfly/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)}