From eb263085cfc2eaee9ecd2ea74cc168130c2b46e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9D=80=E7=81=AB=E7=9A=84=E5=86=B0=E5=9D=97nya?= Date: Sun, 16 Nov 2025 10:34:08 +0800 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20=E9=9A=8F=E6=9C=BA=E8=83=8C?= =?UTF-8?q?=E6=99=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _config.yml | 3 ++- scripts/helpers/page.js | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/_config.yml b/_config.yml index cc4f6e0..f8eeacb 100644 --- a/_config.yml +++ b/_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/scripts/helpers/page.js b/scripts/helpers/page.js index cb1044d..05a43d2 100644 --- a/scripts/helpers/page.js +++ b/scripts/helpers/page.js @@ -89,6 +89,12 @@ hexo.extend.helper.register('findArchivesTitle', function (page, menu, date) { hexo.extend.helper.register('getBgPath', function (path) { if (!path) return '' + // Random background + if (Array.isArray(path)) { + const i = Math.floor(Math.random() * path.length) + path = path[i] + } + const absoluteUrlPattern = /^(?:[a-z][a-z\d+.-]*:)?\/\//i const relativeUrlPattern = /^(\.\/|\.\.\/|\/|[^/]+\/).*$/ const colorPattern = /^(#|rgb|rgba|hsl|hsla)/i From c882e84cd2646b0c639b1f50b7e3156b1f938a8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9D=80=E7=81=AB=E7=9A=84=E5=86=B0=E5=9D=97nya?= Date: Tue, 18 Nov 2025 10:27:29 +0800 Subject: [PATCH 2/6] =?UTF-8?q?feat:=20=E9=9A=8F=E6=9C=BA=E8=83=8C?= =?UTF-8?q?=E6=99=AF=EF=BC=88=E4=BF=AE=E6=AD=A3=E4=B8=8A=E6=AC=A1=E7=9A=84?= =?UTF-8?q?=E9=94=99=E8=AF=AF=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- layout/includes/layout.pug | 12 +++++++++++- scripts/helpers/page.js | 6 ------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/layout/includes/layout.pug b/layout/includes/layout.pug index ef6a46b..60b2fe1 100644 --- a/layout/includes/layout.pug +++ b/layout/includes/layout.pug @@ -13,7 +13,17 @@ 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(style=getBgPath(theme.background)) + else + #web_bg + - const bgStyleArr = theme.background.map(getBgPath) + script. + (function () { + const arr = !{JSON.stringify(bgStyleArr)} + const randomBgStyle = arr[Math.floor(Math.random() * arr.length)] + document.getElementById('web_bg').style = randomBgStyle + })() !=partial('includes/sidebar', {}, {cache: true}) diff --git a/scripts/helpers/page.js b/scripts/helpers/page.js index 05a43d2..cb1044d 100644 --- a/scripts/helpers/page.js +++ b/scripts/helpers/page.js @@ -89,12 +89,6 @@ hexo.extend.helper.register('findArchivesTitle', function (page, menu, date) { hexo.extend.helper.register('getBgPath', function (path) { if (!path) return '' - // Random background - if (Array.isArray(path)) { - const i = Math.floor(Math.random() * path.length) - path = path[i] - } - const absoluteUrlPattern = /^(?:[a-z][a-z\d+.-]*:)?\/\//i const relativeUrlPattern = /^(\.\/|\.\.\/|\/|[^/]+\/).*$/ const colorPattern = /^(#|rgb|rgba|hsl|hsla)/i From 57a7db7a52c89c0dfcdad7c266ce364615e65fc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9D=80=E7=81=AB=E7=9A=84=E5=86=B0=E5=9D=97nya?= Date: Tue, 25 Nov 2025 12:29:48 +0800 Subject: [PATCH 3/6] =?UTF-8?q?fix:=20=E9=9A=8F=E6=9C=BA=E8=83=8C=E6=99=AF?= =?UTF-8?q?=E9=80=82=E9=85=8D=20Pjax?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- layout/includes/layout.pug | 22 +++++++++++++++++----- source/css/_global/function.styl | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/layout/includes/layout.pug b/layout/includes/layout.pug index 60b2fe1..60ef023 100644 --- a/layout/includes/layout.pug +++ b/layout/includes/layout.pug @@ -14,15 +14,27 @@ html(lang=config.language data-theme=theme.display_mode class=htmlClassHideAside if theme.background if !Array.isArray(theme.background) - #web_bg(style=getBgPath(theme.background)) + #web_bg.bg-animation(style=getBgPath(theme.background)) else - #web_bg + #web_bg.bg-animation - const bgStyleArr = theme.background.map(getBgPath) script. - (function () { + (() => { const arr = !{JSON.stringify(bgStyleArr)} - const randomBgStyle = arr[Math.floor(Math.random() * arr.length)] - document.getElementById('web_bg').style = randomBgStyle + const webBgDiv = document.getElementById('web_bg') + + function setRandomBg() { + webBgDiv.style = arr[Math.floor(Math.random() * arr.length)] + } + + setRandomBg() + document.addEventListener('pjax:send', () => { + setRandomBg() + // Reload CSS animation + webBgDiv.classList.remove('bg-animation') + void webBgDiv.offsetWidth + webBgDiv.classList.add('bg-animation') + }) })() !=partial('includes/sidebar', {}, {cache: true}) diff --git a/source/css/_global/function.styl b/source/css/_global/function.styl index 2b6da53..5039b86 100644 --- a/source/css/_global/function.styl +++ b/source/css/_global/function.styl @@ -159,7 +159,7 @@ if hexo-config('enter_transitions') animation: titleScale 1s canvas:not(#ribbon-canvas), - #web_bg + #web_bg.bg-animation animation: to_show 4s #ribbon-canvas From 8ae57ac9bf027de26117710129ab5de0c4547797 Mon Sep 17 00:00:00 2001 From: Jerry Wong Date: Tue, 25 Nov 2025 14:52:42 +0800 Subject: [PATCH 4/6] Update layout.pug --- layout/includes/layout.pug | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/layout/includes/layout.pug b/layout/includes/layout.pug index 60ef023..73799a9 100644 --- a/layout/includes/layout.pug +++ b/layout/includes/layout.pug @@ -23,18 +23,18 @@ html(lang=config.language data-theme=theme.display_mode class=htmlClassHideAside const arr = !{JSON.stringify(bgStyleArr)} const webBgDiv = document.getElementById('web_bg') - function setRandomBg() { + const setRandomBg = () => { webBgDiv.style = arr[Math.floor(Math.random() * arr.length)] + requestAnimationFrame(() => webBgDiv.classList.add('bg-animation')) } - setRandomBg() document.addEventListener('pjax:send', () => { - setRandomBg() - // Reload CSS animation + webBgDiv.style = '' webBgDiv.classList.remove('bg-animation') - void webBgDiv.offsetWidth - webBgDiv.classList.add('bg-animation') }) + + document.addEventListener('pjax:complete', setRandomBg) + document.addEventListener('DOMContentLoaded', setRandomBg) })() !=partial('includes/sidebar', {}, {cache: true}) @@ -56,4 +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 \ No newline at end of file + include ./additional-js.pug From 586805ceb21838c6547e5158f3007efe541d82ff Mon Sep 17 00:00:00 2001 From: Void4m0n Date: Tue, 25 Nov 2025 21:37:21 +0100 Subject: [PATCH 5/6] Search post pagination_cover yaml for prev/next card img --- layout/includes/pagination.pug | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/layout/includes/pagination.pug b/layout/includes/pagination.pug index 361fbf1..168d504 100644 --- a/layout/includes/pagination.pug +++ b/layout/includes/pagination.pug @@ -19,7 +19,7 @@ if page.total !== 1 a.pagination-related(class=className href=url_for(direction.path) title=direction.title) if direction.cover_type === 'img' - img.cover(src=url_for(direction.cover) onerror=`onerror=null;src='${url_for(theme.error_img.post_page)}'` alt=`cover of ${key === 'prev' ? 'previous' : 'next'} post`) + img.cover(src=url_for(direction.pagination_cover || direction.cover) onerror=`onerror=null;src='${url_for(theme.error_img.post_page)}'` alt=`cover of ${key === 'prev' ? 'previous' : 'next'} post`) else .cover(style=`background: ${direction.cover || 'var(--default-bg-color)'}`) @@ -35,4 +35,4 @@ if page.total !== 1 .pagination if globalPageType === 'home' - options.format = 'page/%d/#content-inner' - !=paginator(options) \ No newline at end of file + !=paginator(options) From bb7b206369b7f6c0e6bdec21e56388a4735806cb Mon Sep 17 00:00:00 2001 From: Void4m0n Date: Tue, 25 Nov 2025 21:37:48 +0100 Subject: [PATCH 6/6] support asset_folder for pagination_cover yaml --- scripts/filters/random_cover.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/filters/random_cover.js b/scripts/filters/random_cover.js index 7bccbee..a62af64 100644 --- a/scripts/filters/random_cover.js +++ b/scripts/filters/random_cover.js @@ -34,7 +34,7 @@ hexo.extend.generator.register('post', locals => { const handleImg = data => { const imgTestReg = /\.(png|jpe?g|gif|svg|webp|avif)(\?.*)?$/i - let { cover: coverVal, top_img: topImg } = data + let { cover: coverVal, top_img: topImg, pagination_cover: paginationCover } = data // Add path to top_img and cover if post_asset_folder is enabled if (hexo.config.post_asset_folder) { @@ -44,6 +44,9 @@ hexo.extend.generator.register('post', locals => { if (coverVal && coverVal.indexOf('/') === -1 && imgTestReg.test(coverVal)) { data.cover = `${data.path}${coverVal}` } + if (paginationCover && paginationCover.indexOf('/') === -1 && imgTestReg.test(paginationCover)) { + data.pagination_cover = `${data.path}${paginationCover}` + } } if (coverVal === false) return data