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