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] =?UTF-8?q?feat:=20=E9=9A=8F=E6=9C=BA=E8=83=8C=E6=99=AF?= =?UTF-8?q?=EF=BC=88=E4=BF=AE=E6=AD=A3=E4=B8=8A=E6=AC=A1=E7=9A=84=E9=94=99?= =?UTF-8?q?=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