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/layout/includes/layout.pug b/layout/includes/layout.pug index ef6a46b..44913e2 100644 --- a/layout/includes/layout.pug +++ b/layout/includes/layout.pug @@ -13,7 +13,29 @@ 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.bg-animation(style=getBgPath(theme.background)) + else + #web_bg.bg-animation + - const bgStyleArr = theme.background.map(getBgPath) + script. + (() => { + const arr = !{JSON.stringify(bgStyleArr)} + const webBgDiv = document.getElementById('web_bg') + + const setRandomBg = () => { + webBgDiv.style = arr[Math.floor(Math.random() * arr.length)] + requestAnimationFrame(() => webBgDiv.classList.add('bg-animation')) + } + + document.addEventListener('pjax:send', () => { + webBgDiv.style = '' + webBgDiv.classList.remove('bg-animation') + }) + + document.addEventListener('pjax:complete', setRandomBg) + document.addEventListener('DOMContentLoaded', setRandomBg) + })() !=partial('includes/sidebar', {}, {cache: true}) diff --git a/layout/includes/pagination.pug b/layout/includes/pagination.pug index 361fbf1..f954945 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)'}`) diff --git a/scripts/filters/random_cover.js b/scripts/filters/random_cover.js index b18e209..d814c35 100644 --- a/scripts/filters/random_cover.js +++ b/scripts/filters/random_cover.js @@ -41,7 +41,7 @@ hexo.extend.generator.register('post', locals => { const coverGenerator = createCoverGenerator() const handleImg = data => { - 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 (postAssetFolder) { @@ -51,6 +51,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 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