mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-12 22:17:06 +08:00
feat: 随机背景
This commit is contained in:
@@ -91,7 +91,8 @@ category_per_img:
|
|||||||
footer_img: false
|
footer_img: false
|
||||||
|
|
||||||
# Website Background
|
# 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:
|
background:
|
||||||
|
|
||||||
cover:
|
cover:
|
||||||
|
|||||||
@@ -89,6 +89,12 @@ hexo.extend.helper.register('findArchivesTitle', function (page, menu, date) {
|
|||||||
hexo.extend.helper.register('getBgPath', function (path) {
|
hexo.extend.helper.register('getBgPath', function (path) {
|
||||||
if (!path) return ''
|
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 absoluteUrlPattern = /^(?:[a-z][a-z\d+.-]*:)?\/\//i
|
||||||
const relativeUrlPattern = /^(\.\/|\.\.\/|\/|[^/]+\/).*$/
|
const relativeUrlPattern = /^(\.\/|\.\.\/|\/|[^/]+\/).*$/
|
||||||
const colorPattern = /^(#|rgb|rgba|hsl|hsla)/i
|
const colorPattern = /^(#|rgb|rgba|hsl|hsla)/i
|
||||||
|
|||||||
Reference in New Issue
Block a user