feat: 随机背景(修正上次的错误)

This commit is contained in:
着火的冰块nya
2025-11-18 10:27:29 +08:00
parent 29a6fa455a
commit c882e84cd2
2 changed files with 11 additions and 7 deletions

View File

@@ -13,7 +13,17 @@ html(lang=config.language data-theme=theme.display_mode class=htmlClassHideAside
!=partial('includes/loading/index', {}, {cache: true})
if 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})

View File

@@ -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