mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-12 22:17:06 +08:00
breaking changes: 移除 subtitle 一句網調用(api 已失效)
feat: 右下角按鈕增加預覽進度顯示 feat: toc可設置是否顯示預覽進度 fix: 修復 TypeError: require(...) is not a function 的報錯 #1102 improvement: 日期設置相對日期時,文章的日期格式和最新評論的日期格式統一為 年月日
This commit is contained in:
@@ -185,6 +185,7 @@ toc:
|
|||||||
number: true
|
number: true
|
||||||
expand: false
|
expand: false
|
||||||
style_simple: false # for post
|
style_simple: false # for post
|
||||||
|
scroll_percent: true
|
||||||
|
|
||||||
post_copyright:
|
post_copyright:
|
||||||
enable: true
|
enable: true
|
||||||
@@ -632,8 +633,7 @@ subtitle:
|
|||||||
# source 調用第三方服務
|
# source 調用第三方服務
|
||||||
# source: false 關閉調用
|
# source: false 關閉調用
|
||||||
# source: 1 調用一言網的一句話(簡體) https://hitokoto.cn/
|
# source: 1 調用一言網的一句話(簡體) https://hitokoto.cn/
|
||||||
# source: 2 調用一句網(簡體) http://yijuzhan.com/
|
# source: 2 調用今日詩詞(簡體) https://www.jinrishici.com/
|
||||||
# source: 3 調用今日詩詞(簡體) https://www.jinrishici.com/
|
|
||||||
# subtitle 會先顯示 source , 再顯示 sub 的內容
|
# subtitle 會先顯示 source , 再顯示 sub 的內容
|
||||||
source: false
|
source: false
|
||||||
# 如果關閉打字效果,subtitle 只會顯示 sub 的第一行文字
|
# 如果關閉打字效果,subtitle 只會顯示 sub 的第一行文字
|
||||||
@@ -753,6 +753,9 @@ darkmode:
|
|||||||
# autoChangeMode: false
|
# autoChangeMode: false
|
||||||
autoChangeMode: false
|
autoChangeMode: false
|
||||||
|
|
||||||
|
# show scroll percent in scroll-to-top button
|
||||||
|
rightside_scroll_percent: false
|
||||||
|
|
||||||
# Don't modify the following settings unless you know how they work (非必要請不要修改 )
|
# Don't modify the following settings unless you know how they work (非必要請不要修改 )
|
||||||
# Choose: readmode,translate,darkmode,hideAside,toc,chat,comment
|
# Choose: readmode,translate,darkmode,hideAside,toc,chat,comment
|
||||||
# Don't repeat 不要重複
|
# Don't repeat 不要重複
|
||||||
|
|||||||
@@ -120,5 +120,9 @@ script.
|
|||||||
},
|
},
|
||||||
isPhotoFigcaption: !{theme.photofigcaption},
|
isPhotoFigcaption: !{theme.photofigcaption},
|
||||||
islazyload: !{theme.lazyload.enable},
|
islazyload: !{theme.lazyload.enable},
|
||||||
isAnchor: !{theme.anchor.auto_update || false}
|
isAnchor: !{theme.anchor.auto_update || false},
|
||||||
|
percent: {
|
||||||
|
toc: !{theme.toc.scroll_percent},
|
||||||
|
rightside: !{theme.rightside_scroll_percent},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,4 +57,5 @@ mixin rightsideItem(array)
|
|||||||
+rightsideItem(showArray)
|
+rightsideItem(showArray)
|
||||||
|
|
||||||
button#go-up(type="button" title=_p("rightside.back_to_top"))
|
button#go-up(type="button" title=_p("rightside.back_to_top"))
|
||||||
|
span.scroll-percent
|
||||||
i.fas.fa-arrow-up
|
i.fas.fa-arrow-up
|
||||||
32
layout/includes/third-party/subtitle.pug
vendored
32
layout/includes/third-party/subtitle.pug
vendored
@@ -36,38 +36,6 @@ case source
|
|||||||
}
|
}
|
||||||
|
|
||||||
when 2
|
when 2
|
||||||
script.
|
|
||||||
function subtitleType () {
|
|
||||||
getScript('https://yijuzhan.com/api/word.php?m=js').then(() => {
|
|
||||||
const con = str[0]
|
|
||||||
if (!{effect}) {
|
|
||||||
const from = '出自 ' + str[1]
|
|
||||||
const sub = !{JSON.stringify(subContent)}
|
|
||||||
sub.unshift(con, from)
|
|
||||||
window.typed = new Typed('#subtitle', {
|
|
||||||
strings: sub,
|
|
||||||
startDelay: !{startDelay},
|
|
||||||
typeSpeed: !{typeSpeed},
|
|
||||||
loop: !{loop},
|
|
||||||
backSpeed: !{backSpeed},
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
document.getElementById('subtitle').innerHTML = con
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!{effect}) {
|
|
||||||
if (typeof Typed === 'function') {
|
|
||||||
subtitleType()
|
|
||||||
} else {
|
|
||||||
getScript('!{url_for(theme.asset.typed)}').then(subtitleType)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
subtitleType()
|
|
||||||
}
|
|
||||||
|
|
||||||
when 3
|
|
||||||
script.
|
script.
|
||||||
function subtitleType () {
|
function subtitleType () {
|
||||||
getScript('https://sdk.jinrishici.com/v2/browser/jinrishici.js').then(() => {
|
getScript('https://sdk.jinrishici.com/v2/browser/jinrishici.js').then(() => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hexo-theme-butterfly",
|
"name": "hexo-theme-butterfly",
|
||||||
"version": "4.5.1",
|
"version": "4.6.0-b1",
|
||||||
"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": {
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
const logger = require('hexo-log')()
|
|
||||||
|
|
||||||
hexo.extend.filter.register('before_generate', () => {
|
hexo.extend.filter.register('before_generate', () => {
|
||||||
// Get first two digits of the Hexo version number
|
// Get first two digits of the Hexo version number
|
||||||
const hexoVer = hexo.version.replace(/(^.*\..*)\..*/, '$1')
|
const hexoVer = hexo.version.replace(/(^.*\..*)\..*/, '$1')
|
||||||
|
const logger = hexo.log
|
||||||
|
|
||||||
if (hexoVer < 5.3) {
|
if (hexoVer < 5.3) {
|
||||||
logger.error('Please update Hexo to V5.3.0 or higher!')
|
logger.error('Please update Hexo to V5.3.0 or higher!')
|
||||||
@@ -13,7 +12,9 @@ hexo.extend.filter.register('before_generate', () => {
|
|||||||
if (hexo.locals.get) {
|
if (hexo.locals.get) {
|
||||||
const data = hexo.locals.get('data')
|
const data = hexo.locals.get('data')
|
||||||
if (data && data.butterfly) {
|
if (data && data.butterfly) {
|
||||||
logger.error(" 'butterfly.yml' is deprecated. Please use '_config.butterfly.yml' ")
|
logger.error(
|
||||||
|
" 'butterfly.yml' is deprecated. Please use '_config.butterfly.yml' "
|
||||||
|
)
|
||||||
logger.error(" 'butterfly.yml' 已經棄用,請使用 '_config.butterfly.yml' ")
|
logger.error(" 'butterfly.yml' 已經棄用,請使用 '_config.butterfly.yml' ")
|
||||||
process.exit(-1)
|
process.exit(-1)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,13 @@
|
|||||||
const logger = require('hexo-log')()
|
|
||||||
|
|
||||||
hexo.on('ready', () => {
|
hexo.on('ready', () => {
|
||||||
const { version } = require('../../package.json')
|
const { version } = require('../../package.json')
|
||||||
logger.info(`
|
hexo.log.info(`
|
||||||
===================================================================
|
===================================================================
|
||||||
|
|
||||||
##### # # ##### ##### ###### ##### ###### # # #
|
##### # # ##### ##### ###### ##### ###### # # #
|
||||||
# # # # # # # # # # # # #
|
# # # # # # # # # # # # #
|
||||||
##### # # # # ##### # # ##### # #
|
##### # # # # ##### # # ##### # #
|
||||||
# # # # # # # ##### # # #
|
# # # # # # # ##### # # #
|
||||||
# # # # # # # # # # # #
|
# # # # # # # # # # # #
|
||||||
##### #### # # ###### # # # ###### #
|
##### #### # # ###### # # # ###### #
|
||||||
|
|
||||||
${version}
|
${version}
|
||||||
===================================================================`)
|
===================================================================`)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -47,3 +47,22 @@
|
|||||||
+maxWidth900()
|
+maxWidth900()
|
||||||
#hide-aside-btn
|
#hide-aside-btn
|
||||||
display: none
|
display: none
|
||||||
|
|
||||||
|
if hexo-config('rightside_scroll_percent')
|
||||||
|
#go-up
|
||||||
|
.scroll-percent
|
||||||
|
display: none
|
||||||
|
|
||||||
|
&.show-percent
|
||||||
|
.scroll-percent
|
||||||
|
display: block
|
||||||
|
|
||||||
|
& + i
|
||||||
|
display: none
|
||||||
|
|
||||||
|
&:hover
|
||||||
|
.scroll-percent
|
||||||
|
display: none
|
||||||
|
|
||||||
|
& + i
|
||||||
|
display: block
|
||||||
|
|||||||
@@ -251,6 +251,21 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
getScript(`${GLOBAL_CONFIG.source.justifiedGallery.js}`).then(() => { btf.initJustifiedGallery(ele) })
|
getScript(`${GLOBAL_CONFIG.source.justifiedGallery.js}`).then(() => { btf.initJustifiedGallery(ele) })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* rightside scroll percent
|
||||||
|
*/
|
||||||
|
const rightsideScrollPercent = currentTop => {
|
||||||
|
const perNum = btf.getScrollPercent(currentTop,document.body)
|
||||||
|
const $goUp = document.getElementById('go-up')
|
||||||
|
if ( perNum < 95 ) {
|
||||||
|
$goUp.classList.add('show-percent')
|
||||||
|
$goUp.querySelector('.scroll-percent').textContent = perNum
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$goUp.classList.remove('show-percent')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 滾動處理
|
* 滾動處理
|
||||||
*/
|
*/
|
||||||
@@ -276,6 +291,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
const $header = document.getElementById('page-header')
|
const $header = document.getElementById('page-header')
|
||||||
const isChatBtnHide = typeof chatBtnHide === 'function'
|
const isChatBtnHide = typeof chatBtnHide === 'function'
|
||||||
const isChatBtnShow = typeof chatBtnShow === 'function'
|
const isChatBtnShow = typeof chatBtnShow === 'function'
|
||||||
|
const isShowPercent = GLOBAL_CONFIG.percent.rightside
|
||||||
|
|
||||||
const scrollTask = btf.throttle(() => {
|
const scrollTask = btf.throttle(() => {
|
||||||
const currentTop = window.scrollY || document.documentElement.scrollTop
|
const currentTop = window.scrollY || document.documentElement.scrollTop
|
||||||
@@ -305,9 +321,12 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
$rightside.style.cssText = "opacity: ''; transform: ''"
|
$rightside.style.cssText = "opacity: ''; transform: ''"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isShowPercent && rightsideScrollPercent(currentTop)
|
||||||
|
|
||||||
if (document.body.scrollHeight <= innerHeight) {
|
if (document.body.scrollHeight <= innerHeight) {
|
||||||
$rightside.style.cssText = 'opacity: 0.8; transform: translateX(-58px)'
|
$rightside.style.cssText = 'opacity: 0.8; transform: translateX(-58px)'
|
||||||
}
|
}
|
||||||
|
|
||||||
}, 200)
|
}, 200)
|
||||||
|
|
||||||
window.scrollCollect = scrollTask
|
window.scrollCollect = scrollTask
|
||||||
@@ -325,26 +344,15 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
|
|
||||||
if (!($article && (isToc || isAnchor))) return
|
if (!($article && (isToc || isAnchor))) return
|
||||||
|
|
||||||
let $tocLink, $cardToc, scrollPercent, autoScrollToc, isExpand
|
let $tocLink, $cardToc, autoScrollToc, $tocPercentage, isExpand
|
||||||
|
|
||||||
if (isToc) {
|
if (isToc) {
|
||||||
const $cardTocLayout = document.getElementById('card-toc')
|
const $cardTocLayout = document.getElementById('card-toc')
|
||||||
$cardToc = $cardTocLayout.getElementsByClassName('toc-content')[0]
|
$cardToc = $cardTocLayout.getElementsByClassName('toc-content')[0]
|
||||||
$tocLink = $cardToc.querySelectorAll('.toc-link')
|
$tocLink = $cardToc.querySelectorAll('.toc-link')
|
||||||
const $tocPercentage = $cardTocLayout.querySelector('.toc-percentage')
|
$tocPercentage = $cardTocLayout.querySelector('.toc-percentage')
|
||||||
isExpand = $cardToc.classList.contains('is-expand')
|
isExpand = $cardToc.classList.contains('is-expand')
|
||||||
|
|
||||||
scrollPercent = currentTop => {
|
|
||||||
const docHeight = $article.clientHeight
|
|
||||||
const winHeight = document.documentElement.clientHeight
|
|
||||||
const headerHeight = $article.offsetTop
|
|
||||||
const contentMath = (docHeight > winHeight) ? (docHeight - winHeight) : (document.documentElement.scrollHeight - winHeight)
|
|
||||||
const scrollPercent = (currentTop - headerHeight) / (contentMath)
|
|
||||||
const scrollPercentRounded = Math.round(scrollPercent * 100)
|
|
||||||
const percentage = (scrollPercentRounded > 100) ? 100 : (scrollPercentRounded <= 0) ? 0 : scrollPercentRounded
|
|
||||||
$tocPercentage.textContent = percentage
|
|
||||||
}
|
|
||||||
|
|
||||||
window.mobileToc = {
|
window.mobileToc = {
|
||||||
open: () => {
|
open: () => {
|
||||||
$cardTocLayout.style.cssText = 'animation: toc-open .3s; opacity: 1; right: 55px'
|
$cardTocLayout.style.cssText = 'animation: toc-open .3s; opacity: 1; right: 55px'
|
||||||
@@ -433,13 +441,14 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// main of scroll
|
// main of scroll
|
||||||
window.tocScrollFn = function () {
|
window.tocScrollFn = btf.throttle(()=>{
|
||||||
return btf.throttle(function () {
|
|
||||||
const currentTop = window.scrollY || document.documentElement.scrollTop
|
const currentTop = window.scrollY || document.documentElement.scrollTop
|
||||||
isToc && scrollPercent(currentTop)
|
if (isToc && GLOBAL_CONFIG.percent.toc) {
|
||||||
|
$tocPercentage.textContent = btf.getScrollPercent(currentTop,$article)
|
||||||
|
}
|
||||||
findHeadPosition(currentTop)
|
findHeadPosition(currentTop)
|
||||||
}, 100)()
|
}, 100)
|
||||||
}
|
|
||||||
window.addEventListener('scroll', tocScrollFn)
|
window.addEventListener('scroll', tocScrollFn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ const btf = {
|
|||||||
const minuteCount = dateDiff / minute
|
const minuteCount = dateDiff / minute
|
||||||
|
|
||||||
if (monthCount > 12) {
|
if (monthCount > 12) {
|
||||||
result = datePost.toLocaleDateString().replace(/\//g, '-')
|
result = datePost.toISOString().slice(0,10)
|
||||||
} else if (monthCount >= 1) {
|
} else if (monthCount >= 1) {
|
||||||
result = parseInt(monthCount) + ' ' + GLOBAL_CONFIG.date_suffix.month
|
result = parseInt(monthCount) + ' ' + GLOBAL_CONFIG.date_suffix.month
|
||||||
} else if (dayCount >= 1) {
|
} else if (dayCount >= 1) {
|
||||||
@@ -274,5 +274,16 @@ const btf = {
|
|||||||
title: title
|
title: title
|
||||||
}, title, anchor)
|
}, title, anchor)
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
getScrollPercent: (currentTop,ele) => {
|
||||||
|
const docHeight = ele.clientHeight
|
||||||
|
const winHeight = document.documentElement.clientHeight
|
||||||
|
const headerHeight = ele.offsetTop
|
||||||
|
const contentMath = (docHeight > winHeight) ? (docHeight - winHeight) : (document.documentElement.scrollHeight - winHeight)
|
||||||
|
const scrollPercent = (currentTop - headerHeight) / (contentMath)
|
||||||
|
const scrollPercentRounded = Math.round(scrollPercent * 100)
|
||||||
|
const percentage = (scrollPercentRounded > 100) ? 100 : (scrollPercentRounded <= 0) ? 0 : scrollPercentRounded
|
||||||
|
return percentage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user