Skip to content

Commit

Permalink
label: 3.2.0
Browse files Browse the repository at this point in the history
fix: 修復當hexo的_config沒有設置description時,會導致pjax在頁面與文章間切換會無效 close jerryc127#381
improvement: 當隱藏部分沒配置時,左下角設置按鈕會消失 jerryc127#353
improvement: 網站背景可配置 (顏色(HEX值/RGB值/顔色單詞/漸變色)/漸變色/圖片鏈接)
improvement: 夜間模式下,背景顔色/top-img/footer-bg 設置為顔色時,不再強制顯示黑色,而是改為遮罩降低亮度
  • Loading branch information
jerryc127 committed Sep 28, 2020
1 parent d5670e2 commit de11040
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 92 deletions.
4 changes: 1 addition & 3 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -486,12 +486,10 @@ tag_ui: # 留空或 index

# Website Background (設置網站背景)
# can set it to color or image (可設置圖片 或者 顔色)
# The formal of color: '#49B202'
# The formal of image: url(http://xxxxxx.com/xxx.jpg)
# White color will be shown as default
background:

# Show the footer background image (same as top_img)
# Footer Background
footer_bg: false

# the position of bottom right button/default unit: px (右下角按鈕距離底部的距離/默認單位為px)
Expand Down
3 changes: 1 addition & 2 deletions layout/404.pug
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ html(lang=config.language data-theme=theme.display_mode)
canvas.fireworks

if theme.background
- var is_photo = theme.background.startsWith('url') ? 'photo':'color'
#web_bg(data-type=is_photo)
#web_bg

#error-wrap
.error-content
Expand Down
89 changes: 46 additions & 43 deletions layout/includes/head/darkmode.pug
Original file line number Diff line number Diff line change
@@ -1,50 +1,53 @@
if theme.darkmode.enable
script.
var activateDarkMode = function () {
document.documentElement.setAttribute('data-theme', 'dark')
if (document.querySelector('meta[name="theme-color"]') !== null) {
document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
(function () {
window.activateDarkMode = function () {
document.documentElement.setAttribute('data-theme', 'dark')
if (document.querySelector('meta[name="theme-color"]') !== null) {
document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
}
}
}
var activateLightMode = function () {
document.documentElement.setAttribute('data-theme', 'light')
if (document.querySelector('meta[name="theme-color"]') !== null) {
document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
window.activateLightMode = function () {
document.documentElement.setAttribute('data-theme', 'light')
if (document.querySelector('meta[name="theme-color"]') !== null) {
document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
}
}
}

var autoChangeMode = '#{theme.darkmode.autoChangeMode}'
var t = saveToLocal.get('theme')
if (autoChangeMode === '1') {
var isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
var isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
var isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
var hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified
const autoChangeMode = '#{theme.darkmode.autoChangeMode}'
const t = saveToLocal.get('theme')
if (autoChangeMode === '1') {
const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
const isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
const isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
const hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified

if (t === undefined) {
if (isLightMode) activateLightMode()
else if (isDarkMode) activateDarkMode()
else if (isNotSpecified || hasNoSupport) {
var now = new Date()
var hour = now.getHours()
var isNight = hour <= 6 || hour >= 18
isNight ? activateDarkMode() : activateLightMode()
}
window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
if (saveToLocal.get('theme') === undefined) {
e.matches ? activateDarkMode() : activateLightMode()
if (t === undefined) {
if (isLightMode) activateLightMode()
else if (isDarkMode) activateDarkMode()
else if (isNotSpecified || hasNoSupport) {
const now = new Date()
const hour = now.getHours()
const isNight = hour <= 6 || hour >= 18
isNight ? activateDarkMode() : activateLightMode()
}
})
} else if (t === 'light') activateLightMode()
else activateDarkMode()
} else if (autoChangeMode === '2') {
now = new Date()
hour = now.getHours()
isNight = hour <= 6 || hour >= 18
if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
else if (t === 'light') activateLightMode()
else activateDarkMode()
} else {
if (t === 'dark') activateDarkMode()
else if (t === 'light') activateLightMode()
}
window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
if (saveToLocal.get('theme') === undefined) {
e.matches ? activateDarkMode() : activateLightMode()
}
})
} else if (t === 'light') activateLightMode()
else activateDarkMode()
} else if (autoChangeMode === '2') {
const now = new Date()
const hour = now.getHours()
const isNight = hour <= 6 || hour >= 18
if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
else if (t === 'light') activateLightMode()
else activateDarkMode()
} else {
if (t === 'dark') activateDarkMode()
else if (t === 'light') activateLightMode()
}
})()

3 changes: 1 addition & 2 deletions layout/includes/layout.pug
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ html(lang=config.language data-theme=theme.display_mode)

#body-wrap
if theme.background
- var is_photo = theme.background.startsWith('url') ? 'photo':'color'
#web_bg(data-type=is_photo)
#web_bg

include ./sidebar.pug
include ./header/index.pug
Expand Down
35 changes: 19 additions & 16 deletions layout/includes/rightside.pug
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
section#rightside
#rightside-config-hide
if is_post()
if theme.readmode
button#readmode(type="button" title=_p('rightside.readmode_title'))
i.fas.fa-book-open
if theme.translate && theme.translate.enable
if is_post() && theme.readmode
button#readmode(type="button" title=_p('rightside.readmode_title'))
i.fas.fa-book-open
if theme.translate.enable
button#translateLink(type="button" title=_p('rightside.translate_title'))= theme.translate.default
if theme.darkmode.enable && theme.darkmode.button
button#darkmode(type="button" title=_p('rightside.night_mode_title'))
i.fas.fa-adjust
#rightside-config-show
button#rightside_config(type="button" title=_p("rightside.setting"))
i.fas.fa-cog
if is_post() && page.comments !== false && theme.comments.use
a#to_comment(href="#post-comment" title=_p("rightside.scroll_to_comment"))
i.fas.fa-comments
if showToc
button#mobile-toc-button.close(type="button" title=_p("rightside.toc"))
i.fas.fa-list-ul
if is_post()
if (theme.readmode || theme.translate.enable || (theme.darkmode.enable && theme.darkmode.button))
button#rightside_config(type="button" title=_p("rightside.setting"))
i.fas.fa-cog
if commentsJsLoad
a#to_comment(href="#post-comment" title=_p("rightside.scroll_to_comment"))
i.fas.fa-comments
if showToc
button#mobile-toc-button.close(type="button" title=_p("rightside.toc"))
i.fas.fa-list-ul
else if theme.translate.enable || (theme.darkmode.enable && theme.darkmode.button)
button#rightside_config(type="button" title=_p("rightside.setting"))
i.fas.fa-cog

if theme.chat_btn
button#chat_btn(type="button" title=_p("rightside.chat_btn"))
i.fas.fa-sms

button#go-up(type="button" title=_p("rightside.back_to_top"))
i.fas.fa-arrow-up


i.fas.fa-arrow-up
1 change: 0 additions & 1 deletion layout/includes/third-party/pjax.pug
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ script(src=url_for(theme.CDN.pjax))
script.
let pjaxSelectors = [
'title',
'meta[name=description]',
'#config_change',
'#body-wrap',
'#rightside-config-hide',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hexo-theme-butterfly",
"version": "3.2.0-b7",
"version": "3.2.0",
"description": "A Simple and Card UI Design theme for Hexo",
"main": "package.json",
"scripts": {
Expand Down
12 changes: 9 additions & 3 deletions scripts/filters/random_cover.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
'use strict'

hexo.extend.filter.register('before_post_render', function (data) {
if (data.top_img && data.top_img.indexOf('/') === -1) data.top_img = data.path + data.top_img
if (data.cover && data.cover.indexOf('/') === -1) data.cover = data.path + data.cover
if (hexo.theme.config.rootConfig.post_asset_folder) {
const imgTestReg = /\.(png|jpe?g|gif|svg|webp)(\?.*)?$/
const topImg = data.top_img
const cover = data.cover
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 (data.cover === false) {
data.randomcover = randomCover()
Expand All @@ -33,6 +38,7 @@ function randomCover () {
return cover
}
} else {
return theme.default_top_img
cover = 'https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg'
return cover
}
}
1 change: 0 additions & 1 deletion source/css/_layout/head.styl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
position: relative
width: 100%
background-color: $light-blue
background-attachment: scroll
background-position: center center
background-size: cover
background-repeat: no-repeat
Expand Down
23 changes: 4 additions & 19 deletions source/css/_mode/darkmode.styl
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,15 @@ if hexo-config('darkmode.enable') || hexo-config('display_mode') == 'dark'
--reward-pop: lighten(#121212, 10)
--sidebar-icon-color: alpha(#FFFFFF, .7)

// 網站背景,footer背景
#web_bg[data-type=color]
background: darken(#121212, 2)

#web_bg[data-type=photo]:before
#web_bg:before,
#footer:before,
#page-header:before
position: absolute
width: 100%
height: 100%
background-color: alpha($dark-black, .7)
content: ''

#footer
&:before
background-color: alpha($dark-black, .7)

#article-container
code
background: #2c2c2c
Expand All @@ -56,16 +50,6 @@ if hexo-config('darkmode.enable') || hexo-config('display_mode') == 'dark'

// 頭部
#page-header
&:before
position: absolute
top: 0
left: 0
display: block
width: 100%
height: 100%
background-color: alpha($dark-black, .7)
content: ''

& > #nav.fixed,
&.no-top-img #nav
background: alpha(#121212, .8)
Expand Down Expand Up @@ -165,5 +149,6 @@ if hexo-config('darkmode.enable') || hexo-config('display_mode') == 'dark'

#artitalk_main #lazy
background: #121212

#operare_artitalk .c2
background: #121212
2 changes: 1 addition & 1 deletion source/css/var.styl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ $code-font-size = hexo-config('font.code-font-size') ? convert(hexo-config('font
$font-color = #1F2D3D
$rem = 20px
$text-line-height = 2
$web-bg = hexo-config('background') && convert(hexo-config('background'))
$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_site_info_top = hexo-config('index_site_info_top') ? convert(hexo-config('index_site_info_top')) : 43%
// Global color & SVG
Expand Down

0 comments on commit de11040

Please sign in to comment.