mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-10 21:17:07 +08:00
breaking changes: cover 的顯示優化 #1101
feature: default_cover 可配置顏色 fix: 修復使用本地搜索時,輸入特殊符號沒有顯示結果的 bug closed #1110 fix: 修復 頂部圖和 footer 配置帶有/的顏色參數時,無法顯示顏色的 bug improvement: 鼠標移動到分頁時,文章分頁按鈕增加説明文字 improvement: 文章頁的頂部圖顯示次序為 top_img > cover > default_top_img improvement: canonical 的鏈接根據配置生成 #1111
This commit is contained in:
@@ -26,7 +26,7 @@ meta(name="theme-color" content=themeColor)
|
|||||||
include ./head/Open_Graph.pug
|
include ./head/Open_Graph.pug
|
||||||
|
|
||||||
!=favicon_tag(theme.favicon || config.favicon)
|
!=favicon_tag(theme.favicon || config.favicon)
|
||||||
link(rel="canonical" href=urlNoIndex())
|
link(rel="canonical" href=urlNoIndex(null,config.pretty_urls.trailing_index,config.pretty_urls.trailing_html))
|
||||||
|
|
||||||
//- 預解析
|
//- 預解析
|
||||||
!=partial('includes/head/preconnect', {}, {cache: true})
|
!=partial('includes/head/preconnect', {}, {cache: true})
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
if theme.Open_Graph_meta.enable
|
if theme.Open_Graph_meta.enable
|
||||||
-
|
-
|
||||||
|
const coverVal = page.cover_type === 'img' ? page.cover : theme.avatar.img
|
||||||
let ogOption = Object.assign({
|
let ogOption = Object.assign({
|
||||||
type: is_post() ? 'article' : 'website',
|
type: is_post() ? 'article' : 'website',
|
||||||
image: (page.cover || theme.avatar.img) ? full_url_for(page.cover || theme.avatar.img) : '',
|
image: coverVal ? full_url_for(coverVal) : '',
|
||||||
fb_admins: theme.facebook_comments.user_id || '',
|
fb_admins: theme.facebook_comments.user_id || '',
|
||||||
fb_app_id: theme.facebook_comments.app_id || '',
|
fb_app_id: theme.facebook_comments.app_id || '',
|
||||||
}, theme.Open_Graph_meta.option)
|
}, theme.Open_Graph_meta.option)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
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 || page.randomcover
|
- var 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
|
- var top_img = page.top_img || theme.default_top_img
|
||||||
else if is_tag()
|
else if is_tag()
|
||||||
@@ -17,7 +17,7 @@ if !theme.disable_top_img && page.top_img !== false
|
|||||||
- var top_img = page.top_img || theme.default_top_img
|
- var top_img = page.top_img || theme.default_top_img
|
||||||
|
|
||||||
if top_img !== false
|
if top_img !== false
|
||||||
- var imgSource = top_img && top_img.indexOf('/') !== -1 ? `background-image: url('${url_for(top_img)}')` : `background: ${top_img}`
|
- var imgSource = top_img && isImgOrUrl(top_img) ? `background-image: url('${url_for(top_img)}')` : `background: ${top_img}`
|
||||||
- var bg_img = top_img ? imgSource : ''
|
- var bg_img = top_img ? imgSource : ''
|
||||||
- var site_title = page.title || page.tag || page.category || config.title
|
- var site_title = page.title || page.tag || page.category || config.title
|
||||||
- var isHomeClass = is_home() ? 'full_page' : 'not-home-page'
|
- var isHomeClass = is_home() ? 'full_page' : 'not-home-page'
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ html(lang=config.language data-theme=theme.display_mode class=htmlClassHideAside
|
|||||||
if (footerBg === true)
|
if (footerBg === true)
|
||||||
- var footer_bg = bg_img
|
- var footer_bg = bg_img
|
||||||
else
|
else
|
||||||
- var footer_bg = theme.footer_bg.indexOf('/') !== -1 ? `background-image: url('${url_for(footerBg)}')` : `background: ${footerBg}`
|
- var footer_bg = isImgOrUrl(theme.footer_bg) ? `background-image: url('${url_for(footerBg)}')` : `background: ${footerBg}`
|
||||||
else
|
else
|
||||||
- var footer_bg = ''
|
- var footer_bg = ''
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,10 @@ mixin articleSort(posts)
|
|||||||
.article-sort-item(class=no_cover)
|
.article-sort-item(class=no_cover)
|
||||||
if article.cover && theme.cover.archives_enable
|
if article.cover && theme.cover.archives_enable
|
||||||
a.article-sort-item-img(href=url_for(article.path) title=title)
|
a.article-sort-item-img(href=url_for(article.path) title=title)
|
||||||
img(src=url_for(article.cover) alt=title onerror=`this.onerror=null;this.src='${url_for(theme.error_img.post_page)}'`)
|
if article.cover_type === 'img'
|
||||||
|
img(src=url_for(article.cover) alt=title onerror=`this.onerror=null;this.src='${url_for(theme.error_img.post_page)}'`)
|
||||||
|
else
|
||||||
|
div(style=`background: ${article.cover}`)
|
||||||
.article-sort-item-info
|
.article-sort-item-info
|
||||||
.article-sort-item-time
|
.article-sort-item-time
|
||||||
i.far.fa-calendar-alt
|
i.far.fa-calendar-alt
|
||||||
|
|||||||
@@ -14,7 +14,10 @@ mixin postUI(posts)
|
|||||||
if post_cover && theme.cover.index_enable
|
if post_cover && theme.cover.index_enable
|
||||||
.post_cover(class=leftOrRight)
|
.post_cover(class=leftOrRight)
|
||||||
a(href=url_for(link) title=title)
|
a(href=url_for(link) title=title)
|
||||||
img.post_bg(src=url_for(post_cover) onerror=`this.onerror=null;this.src='`+ url_for(theme.error_img.post_page) + `'` alt=title)
|
if article.cover_type === 'img'
|
||||||
|
img.post-bg(src=url_for(post_cover) onerror=`this.onerror=null;this.src='${url_for(theme.error_img.post_page)}'` alt=title)
|
||||||
|
else
|
||||||
|
div.post-bg(style=`background: ${post_cover}`)
|
||||||
.recent-post-info(class=no_cover)
|
.recent-post-info(class=no_cover)
|
||||||
a.article-title(href=url_for(link) title=title)= title
|
a.article-title(href=url_for(link) title=title)= title
|
||||||
.article-meta-wrap
|
.article-meta-wrap
|
||||||
|
|||||||
@@ -13,19 +13,23 @@ if is_post()
|
|||||||
if(prev)
|
if(prev)
|
||||||
- var hasPageNext = next ? 'pull-left' : 'pull-full'
|
- var hasPageNext = next ? 'pull-left' : 'pull-full'
|
||||||
.prev-post(class=hasPageNext)
|
.prev-post(class=hasPageNext)
|
||||||
- var pagination_cover = prev.cover === false ? prev.randomcover : prev.cover
|
a(href=url_for(prev.path) title=prev.title)
|
||||||
a(href=url_for(prev.path))
|
if prev.cover_type === 'img'
|
||||||
img.prev-cover(src=url_for(pagination_cover) onerror=`onerror=null;src='${url_for(theme.error_img.post_page)}'` alt='cover of previous post')
|
img.cover(src=url_for(prev.cover) onerror=`onerror=null;src='${url_for(theme.error_img.post_page)}'` alt='cover of previous post')
|
||||||
|
else
|
||||||
|
.cover(style=`background: ${prev.cover || 'var(--default-bg-color)'}`)
|
||||||
.pagination-info
|
.pagination-info
|
||||||
.label=_p('pagination.prev')
|
.label=_p('pagination.prev')
|
||||||
.prev_info=prev.title
|
.prev_info=prev.title
|
||||||
|
|
||||||
if(next)
|
if(next)
|
||||||
- var hasPagePrev = prev ? 'pull-right' : 'pull-full'
|
- var hasPagePrev = prev ? 'pull-right' : 'pull-full'
|
||||||
- var pagination_cover = next.cover == false ? next.randomcover : next.cover
|
|
||||||
.next-post(class=hasPagePrev)
|
.next-post(class=hasPagePrev)
|
||||||
a(href=url_for(next.path))
|
a(href=url_for(next.path) title=next.title)
|
||||||
img.next-cover(src=url_for(pagination_cover) onerror=`onerror=null;src='${url_for(theme.error_img.post_page)}'` alt='cover of next post')
|
if next.cover_type === 'img'
|
||||||
|
img.cover(src=url_for(next.cover) onerror=`onerror=null;src='${url_for(theme.error_img.post_page)}'` alt='cover of next post')
|
||||||
|
else
|
||||||
|
.cover(style=`background: ${next.cover || 'var(--default-bg-color)'}`)
|
||||||
.pagination-info
|
.pagination-info
|
||||||
.label=_p('pagination.next')
|
.label=_p('pagination.next')
|
||||||
.next_info=next.title
|
.next_info=next.title
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
.social-share(data-image=url_for(page.cover|| theme.avatar.img) data-sites= theme.sharejs.sites)
|
- const coverVal = page.cover_type === 'img' ? page.cover : theme.avatar.img
|
||||||
|
.social-share(data-image=url_for(coverVal) data-sites= theme.sharejs.sites)
|
||||||
link(rel='stylesheet' href=url_for(theme.asset.sharejs_css) media="print" onload="this.media='all'")
|
link(rel='stylesheet' href=url_for(theme.asset.sharejs_css) media="print" onload="this.media='all'")
|
||||||
script(src=url_for(theme.asset.sharejs) defer)
|
script(src=url_for(theme.asset.sharejs) defer)
|
||||||
@@ -14,7 +14,10 @@ if theme.aside.card_recent_post.enable
|
|||||||
.aside-list-item(class=no_cover)
|
.aside-list-item(class=no_cover)
|
||||||
if post_cover && theme.cover.aside_enable
|
if post_cover && theme.cover.aside_enable
|
||||||
a.thumbnail(href=url_for(link) title=title)
|
a.thumbnail(href=url_for(link) title=title)
|
||||||
img(src=url_for(post_cover) onerror=`this.onerror=null;this.src='${url_for(theme.error_img.post_page)}'` alt=title)
|
if article.cover_type === 'img'
|
||||||
|
img(src=url_for(post_cover) onerror=`this.onerror=null;this.src='${url_for(theme.error_img.post_page)}'` alt=title)
|
||||||
|
else
|
||||||
|
div(style=`background: ${post_cover}`)
|
||||||
.content
|
.content
|
||||||
a.title(href=url_for(link) title=title)= title
|
a.title(href=url_for(link) title=title)= title
|
||||||
if theme.aside.card_recent_post.sort === 'updated'
|
if theme.aside.card_recent_post.sort === 'updated'
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hexo-theme-butterfly",
|
"name": "hexo-theme-butterfly",
|
||||||
"version": "4.6.0-b1",
|
"version": "4.6.0-b2",
|
||||||
"description": "A Simple and Card UI Design theme for Hexo",
|
"description": "A Simple and Card UI Design theme for Hexo",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -6,40 +6,40 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
hexo.extend.filter.register('before_post_render', function (data) {
|
hexo.extend.filter.register('before_post_render', function (data) {
|
||||||
const { config } = this
|
const imgTestReg = /\.(png|jpe?g|gif|svg|webp)(\?.*)?$/
|
||||||
if (config.post_asset_folder) {
|
let randomCover
|
||||||
const imgTestReg = /\.(png|jpe?g|gif|svg|webp)(\?.*)?$/
|
let coverVal = data.cover
|
||||||
|
|
||||||
|
// Add path to top_img and cover if post_asset_folder is enabled
|
||||||
|
if (hexo.config.post_asset_folder) {
|
||||||
const topImg = data.top_img
|
const topImg = data.top_img
|
||||||
const cover = data.cover
|
|
||||||
if (topImg && topImg.indexOf('/') === -1 && imgTestReg.test(topImg)) data.top_img = data.path + topImg
|
if (topImg && topImg.indexOf('/') === -1 && imgTestReg.test(topImg)) data.top_img = data.path + topImg
|
||||||
if (cover && cover.indexOf('/') === -1) data.cover = data.path + cover
|
if (coverVal && coverVal.indexOf('/') === -1 && imgTestReg.test(coverVal)) data.cover = data.path + coverVal
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.cover === false) {
|
const randomCoverFn = () => {
|
||||||
data.randomcover = randomCover()
|
const theme = hexo.theme.config
|
||||||
return data
|
if (!(theme.cover && theme.cover.default_cover)) return false
|
||||||
|
if (!Array.isArray(theme.cover.default_cover)) return theme.cover.default_cover
|
||||||
|
const num = Math.floor(Math.random() * theme.cover.default_cover.length)
|
||||||
|
return theme.cover.default_cover[num]
|
||||||
|
}
|
||||||
|
|
||||||
|
if (coverVal === false) return data
|
||||||
|
|
||||||
|
// If cover is not set, use random cover
|
||||||
|
if (!coverVal) {
|
||||||
|
randomCover = randomCoverFn()
|
||||||
|
data.cover = randomCover
|
||||||
|
coverVal = randomCover // update coverVal
|
||||||
}
|
}
|
||||||
|
|
||||||
data.cover = data.cover || randomCover()
|
if (coverVal) {
|
||||||
return data
|
if (coverVal.indexOf('//') !== -1 || imgTestReg.test(coverVal)) {
|
||||||
})
|
data.cover_type = 'img'
|
||||||
|
return data
|
||||||
function randomCover () {
|
|
||||||
const theme = hexo.theme.config
|
|
||||||
let cover
|
|
||||||
let num
|
|
||||||
|
|
||||||
if (theme.cover && theme.cover.default_cover) {
|
|
||||||
if (!Array.isArray(theme.cover.default_cover)) {
|
|
||||||
cover = theme.cover.default_cover
|
|
||||||
return cover
|
|
||||||
} else {
|
|
||||||
num = Math.floor(Math.random() * theme.cover.default_cover.length)
|
|
||||||
cover = theme.cover.default_cover[num]
|
|
||||||
return cover
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
cover = theme.default_top_img || 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'
|
|
||||||
return cover
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
return data
|
||||||
|
})
|
||||||
@@ -54,8 +54,8 @@ hexo.extend.helper.register('cloudTags', function (options = {}) {
|
|||||||
return result
|
return result
|
||||||
})
|
})
|
||||||
|
|
||||||
hexo.extend.helper.register('urlNoIndex', function (url = null) {
|
hexo.extend.helper.register('urlNoIndex', function (url = null, trailingIndex = false, trailingHtml = false) {
|
||||||
return prettyUrls(url || this.url, { trailing_index: false, trailing_html: false })
|
return prettyUrls(url || this.url, { trailing_index: trailingIndex, trailing_html: trailingHtml })
|
||||||
})
|
})
|
||||||
|
|
||||||
hexo.extend.helper.register('md5', function (path) {
|
hexo.extend.helper.register('md5', function (path) {
|
||||||
@@ -95,3 +95,11 @@ hexo.extend.helper.register('findArchivesTitle', function (page, menu, date) {
|
|||||||
|
|
||||||
return loop(menu) || defaultTitle
|
return loop(menu) || defaultTitle
|
||||||
})
|
})
|
||||||
|
|
||||||
|
hexo.extend.helper.register('isImgOrUrl', function (path) {
|
||||||
|
const imgTestReg = /\.(png|jpe?g|gif|svg|webp)(\?.*)?$/
|
||||||
|
if (path.indexOf('//') !== -1 || imgTestReg.test(path)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
})
|
||||||
@@ -15,7 +15,7 @@ hexo.extend.helper.register('related_posts', function (currentPost, allPosts) {
|
|||||||
title: post.title,
|
title: post.title,
|
||||||
path: post.path,
|
path: post.path,
|
||||||
cover: post.cover,
|
cover: post.cover,
|
||||||
randomcover: post.randomcover,
|
cover_type: post.cover_type,
|
||||||
weight: 1,
|
weight: 1,
|
||||||
updated: post.updated,
|
updated: post.updated,
|
||||||
created: post.date
|
created: post.date
|
||||||
@@ -50,13 +50,14 @@ hexo.extend.helper.register('related_posts', function (currentPost, allPosts) {
|
|||||||
result += '<div class="relatedPosts-list">'
|
result += '<div class="relatedPosts-list">'
|
||||||
|
|
||||||
for (let i = 0; i < Math.min(relatedPosts.length, limitNum); i++) {
|
for (let i = 0; i < Math.min(relatedPosts.length, limitNum); i++) {
|
||||||
const cover =
|
const cover = relatedPosts[i].cover || 'var(--default-bg-color)'
|
||||||
relatedPosts[i].cover === false
|
|
||||||
? relatedPosts[i].randomcover
|
|
||||||
: relatedPosts[i].cover
|
|
||||||
const title = this.escape_html(relatedPosts[i].title)
|
const title = this.escape_html(relatedPosts[i].title)
|
||||||
result += `<div><a href="${this.url_for(relatedPosts[i].path)}" title="${title}">`
|
result += `<div><a href="${this.url_for(relatedPosts[i].path)}" title="${title}">`
|
||||||
result += `<img class="cover" src="${this.url_for(cover)}" alt="cover">`
|
if (relatedPosts[i].cover_type === 'img') {
|
||||||
|
result += `<img class="cover" src="${this.url_for(cover)}" alt="cover">`
|
||||||
|
} else {
|
||||||
|
result += `<div class="cover" style="background: ${cover}"></div>`
|
||||||
|
}
|
||||||
if (dateType === 'created') {
|
if (dateType === 'created') {
|
||||||
result += `<div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> ${this.date(relatedPosts[i].created, hexoConfig.date_format)}</div>`
|
result += `<div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> ${this.date(relatedPosts[i].created, hexoConfig.date_format)}</div>`
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -36,11 +36,11 @@
|
|||||||
|
|
||||||
.postImgHover
|
.postImgHover
|
||||||
&:hover
|
&:hover
|
||||||
img
|
.cover
|
||||||
opacity: .8
|
opacity: .8
|
||||||
transform: scale(1.1)
|
transform: scale(1.1)
|
||||||
|
|
||||||
img
|
.cover
|
||||||
position: absolute
|
position: absolute
|
||||||
width: 100%
|
width: 100%
|
||||||
height: 100%
|
height: 100%
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
--pseudo-hover: $pseudo-hover
|
--pseudo-hover: $pseudo-hover
|
||||||
--headline-presudo: #a0a0a0
|
--headline-presudo: #a0a0a0
|
||||||
--scrollbar-color: $scrollbar-color
|
--scrollbar-color: $scrollbar-color
|
||||||
|
--default-bg-color: $theme-color
|
||||||
|
|
||||||
body
|
body
|
||||||
position: relative
|
position: relative
|
||||||
|
|||||||
@@ -115,7 +115,7 @@
|
|||||||
width: w = 4.2em
|
width: w = 4.2em
|
||||||
height: w
|
height: w
|
||||||
|
|
||||||
& > img
|
:first-child
|
||||||
@extend .imgHover
|
@extend .imgHover
|
||||||
|
|
||||||
.content
|
.content
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#footer
|
#footer
|
||||||
position: relative
|
position: relative
|
||||||
background: $light-blue
|
background-color: $light-blue
|
||||||
background-attachment: scroll
|
background-attachment: scroll
|
||||||
background-position: bottom
|
background-position: bottom
|
||||||
background-size: cover
|
background-size: cover
|
||||||
|
|||||||
@@ -101,7 +101,7 @@
|
|||||||
width: 80px
|
width: 80px
|
||||||
height: 80px
|
height: 80px
|
||||||
|
|
||||||
img
|
:first-child
|
||||||
@extend .imgHover
|
@extend .imgHover
|
||||||
|
|
||||||
&-info
|
&-info
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
height: auto
|
height: auto
|
||||||
|
|
||||||
&:hover
|
&:hover
|
||||||
img.post_bg
|
img.post-bg
|
||||||
transform: scale(1.1)
|
transform: scale(1.1)
|
||||||
|
|
||||||
&.ads-wrap
|
&.ads-wrap
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
width: 100%
|
width: 100%
|
||||||
height: 230px
|
height: 230px
|
||||||
|
|
||||||
img.post_bg
|
.post-bg
|
||||||
@extend .imgHover
|
@extend .imgHover
|
||||||
|
|
||||||
&.right
|
&.right
|
||||||
|
|||||||
@@ -84,8 +84,11 @@ window.addEventListener('load', () => {
|
|||||||
$input.addEventListener('input', function () {
|
$input.addEventListener('input', function () {
|
||||||
const keywords = this.value.trim().toLowerCase().split(/[\s]+/)
|
const keywords = this.value.trim().toLowerCase().split(/[\s]+/)
|
||||||
if (keywords[0] !== '') $loadingStatus.innerHTML = '<i class="fas fa-spinner fa-pulse"></i>'
|
if (keywords[0] !== '') $loadingStatus.innerHTML = '<i class="fas fa-spinner fa-pulse"></i>'
|
||||||
|
else {
|
||||||
|
$resultContent.innerHTML = ''
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
$resultContent.innerHTML = ''
|
|
||||||
let str = '<div class="search-result-list">'
|
let str = '<div class="search-result-list">'
|
||||||
if (keywords.length <= 0) return
|
if (keywords.length <= 0) return
|
||||||
let count = 0
|
let count = 0
|
||||||
@@ -150,7 +153,12 @@ window.addEventListener('load', () => {
|
|||||||
|
|
||||||
// highlight all keywords
|
// highlight all keywords
|
||||||
keywords.forEach(keyword => {
|
keywords.forEach(keyword => {
|
||||||
const regS = new RegExp(keyword, 'gi')
|
let regexStr = keyword
|
||||||
|
const specialRegex = new RegExp("[^\\w\\s]+") // match special characters
|
||||||
|
if (keyword.length === 1 && specialRegex.test(keyword)) {
|
||||||
|
regexStr = `\\${keyword}`
|
||||||
|
}
|
||||||
|
const regS = new RegExp(regexStr, 'gi')
|
||||||
matchContent = matchContent.replace(regS, '<span class="search-keyword">' + keyword + '</span>')
|
matchContent = matchContent.replace(regS, '<span class="search-keyword">' + keyword + '</span>')
|
||||||
dataTitle = dataTitle.replace(regS, '<span class="search-keyword">' + keyword + '</span>')
|
dataTitle = dataTitle.replace(regS, '<span class="search-keyword">' + keyword + '</span>')
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user