fix: 修復 pagination UI 顯示異常的 bug

fix: 修復 footer_img 配置不生效的 bug
improvement: 優化 背景url 的判斷
feat: 背景圖片配置不再需要添加 url()
This commit is contained in:
Jerry
2024-08-05 16:04:05 +08:00
parent 06f543ed96
commit 48212b9610
7 changed files with 43 additions and 43 deletions

View File

@@ -90,8 +90,7 @@ category_per_img:
footer_img: false footer_img: false
# Website Background # Website Background
# Can set it to color or image # Can set it to color or image url
# The formal of image: url(http://xxxxxx.com/xxx.jpg)
background: background:
cover: cover:

View File

@@ -1,43 +1,41 @@
-
const returnTopImg = img => img !== false ? img || theme.default_top_img : false
const isFixedClass = theme.nav.fixed ? ' fixed' : ''
var top_img = false
let headerClassName = 'not-top-img'
var bg_img = ''
if !theme.disable_top_img && page.top_img !== false if !theme.disable_top_img && page.top_img !== false
if is_post() if is_post()
- var top_img = page.top_img || page.cover || theme.default_top_img - top_img = page.top_img || page.cover || theme.default_top_img
else if is_page() else if is_page()
- var top_img = page.top_img || theme.default_top_img - top_img = page.top_img || theme.default_top_img
else if is_tag() else if is_tag()
- var top_img = theme.tag_per_img && theme.tag_per_img[page.tag] - top_img = theme.tag_per_img && theme.tag_per_img[page.tag]
- top_img = top_img ? top_img : (theme.tag_img !== false ? theme.tag_img || theme.default_top_img : false) - top_img = top_img || returnTopImg(theme.tag_img)
else if is_category() else if is_category()
- var top_img = theme.category_per_img && theme.category_per_img[page.category] - top_img = theme.category_per_img && theme.category_per_img[page.category]
- top_img = top_img ? top_img : (theme.category_img !== false ? theme.category_img || theme.default_top_img : false) - top_img = top_img || returnTopImg(theme.category_img)
else if is_home() else if is_home()
- var top_img = theme.index_img !== false ? theme.index_img || theme.default_top_img : false - top_img = returnTopImg(theme.index_img)
else if is_archive() else if is_archive()
- var top_img = theme.archive_img !== false ? theme.archive_img || theme.default_top_img : false - top_img = returnTopImg(theme.archive_img)
else else
- var top_img = page.top_img || theme.default_top_img - top_img = page.top_img || theme.default_top_img
if top_img !== false if top_img !== false
- var imgSource = top_img && isImgOrUrl(top_img) ? `background-image: url('${url_for(top_img)}')` : `background: ${top_img}` - bg_img = getBgPath(top_img)
- var bg_img = top_img ? imgSource : '' - headerClassName = is_home() ? 'full_page' : 'not-home-page'
- var site_title = page.title || page.tag || page.category || config.title - headerClassName = is_post() ? 'post-bg' : headerClassName
- var isHomeClass = is_home() ? 'full_page' : 'not-home-page'
- is_post() ? isHomeClass = 'post-bg' : isHomeClass
else
- var isHomeClass = 'not-top-img'
else
- var top_img = false
- var isHomeClass = 'not-top-img'
- const isFixedClass = theme.nav.fixed ? ' fixed' : '' header#page-header(class=`${headerClassName+isFixedClass}` style=bg_img)
header#page-header(class=`${isHomeClass+isFixedClass}` style=bg_img)
!=partial('includes/header/nav', {}, {cache: true}) !=partial('includes/header/nav', {}, {cache: true})
if top_img !== false if top_img !== false
if is_post() if is_post()
include ./post-info.pug include ./post-info.pug
else if is_home() else if is_home()
#site-info #site-info
h1#site-title=site_title h1#site-title=config.title
if theme.subtitle.enable if theme.subtitle.enable
- var loadSubJs = true - var loadSubJs = true
#site-subtitle #site-subtitle
@@ -49,4 +47,4 @@ header#page-header(class=`${isHomeClass+isFixedClass}` style=bg_img)
i.fas.fa-angle-down.scroll-down-effects i.fas.fa-angle-down.scroll-down-effects
else else
#page-site-info #page-site-info
h1#site-title=site_title h1#site-title=page.title || page.tag || page.category

View File

@@ -13,7 +13,7 @@ html(lang=config.language data-theme=theme.display_mode class=htmlClassHideAside
!=partial('includes/loading/index', {}, {cache: true}) !=partial('includes/loading/index', {}, {cache: true})
if theme.background if theme.background
#web_bg #web_bg(style=getBgPath(theme.background))
!=partial('includes/sidebar', {}, {cache: true}) !=partial('includes/sidebar', {}, {cache: true})
@@ -28,15 +28,8 @@ html(lang=config.language data-theme=theme.display_mode class=htmlClassHideAside
if theme.aside.enable && page.aside !== false if theme.aside.enable && page.aside !== false
include widget/index.pug include widget/index.pug
- var footerBg = theme.footer_img - const footerBg = theme.footer_img
if (footerBg) - const footer_bg = footerBg ? footerBg === true ? bg_img : getBgPath(footerBg) : ''
if (footerBg === true)
- var footer_bg = bg_img
else
- var footer_bg = isImgOrUrl(theme.footer_bg) ? `background-image: url('${url_for(footerBg)}')` : `background: ${footerBg}`
else
- var footer_bg = ''
footer#footer(style=footer_bg) footer#footer(style=footer_bg)
!=partial('includes/footer', {}, {cache: true}) !=partial('includes/footer', {}, {cache: true})

View File

@@ -87,7 +87,18 @@ hexo.extend.helper.register('findArchivesTitle', function (page, menu, date) {
return loop(menu) || defaultTitle return loop(menu) || defaultTitle
}) })
hexo.extend.helper.register('isImgOrUrl', function (path) { hexo.extend.helper.register('getBgPath', function (path) {
const imgTestReg = /\.(png|jpe?g|gif|svg|webp)(\?.*)?$/i if (!path) return ''
return path.includes('//') || imgTestReg.test(path)
const absoluteUrlPattern = /^(?:[a-z][a-z\d+.-]*:)?\/\//i
const relativeUrlPattern = /^(\.\/|\.\.\/|\/|[^/]+\/).*$/
const colorPattern = /^(#|rgb|rgba|hsl|hsla|linear-gradient|radial-gradient)/i
if (colorPattern.test(path)) {
return `background-color: ${path};`
} else if (absoluteUrlPattern.test(path) || relativeUrlPattern.test(path)) {
return `background-image: url(${path});`
} else {
return `background: ${path};`
}
}) })

View File

@@ -75,13 +75,12 @@ body
input::placeholder input::placeholder
color: var(--font-color) color: var(--font-color)
if $web-bg if hexo-config('background')
#web_bg #web_bg
position: fixed position: fixed
z-index: -999 z-index: -999
width: 100% width: 100%
height: 100% height: 100%
background: $web-bg
background-attachment: local background-attachment: local
background-position: center background-position: center
background-size: cover background-size: cover

View File

@@ -38,6 +38,7 @@
.next-post .next-post
@extend .postImgHover @extend .postImgHover
position: relative position: relative
display: block
overflow: hidden overflow: hidden
width: 50% width: 50%
height: 150px height: 150px

View File

@@ -34,7 +34,6 @@ $font-size = hexo-config('font.global-font-size') ? convert(hexo-config('font.gl
$code-font-size = hexo-config('font.code-font-size') ? convert(hexo-config('font.code-font-size')) : var(--global-font-size) $code-font-size = hexo-config('font.code-font-size') ? convert(hexo-config('font.code-font-size')) : var(--global-font-size)
$font-color = #1F2D3D $font-color = #1F2D3D
$text-line-height = 2 $text-line-height = 2
$web-bg = hexo-config('background') && unquote(hexo-config('background'))
$index_top_img_height = hexo-config('index_top_img_height') ? convert(hexo-config('index_top_img_height')) : 100vh $index_top_img_height = hexo-config('index_top_img_height') ? convert(hexo-config('index_top_img_height')) : 100vh
$index_site_info_top = hexo-config('index_site_info_top') ? convert(hexo-config('index_site_info_top')) : 43% $index_site_info_top = hexo-config('index_site_info_top') ? convert(hexo-config('index_site_info_top')) : 43%
// Global color & SVG // Global color & SVG