mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-16 20:30:53 +08:00
✨ 提升highlight-tool的加載速度
✨ 可設置取消谷歌自動廣告代碼加載 🐛 修復pjax下側邊欄分類打開/收縮按鈕 直接跳轉的bugs 🐛 修復代碼塊向右偏移的bugs 🐛 修復子目錄下,404頁面的回到首頁鏈接錯誤的bugs
This commit is contained in:
@@ -22,7 +22,7 @@ html(lang=config.language data-theme=theme.display_mode)
|
|||||||
.error-info
|
.error-info
|
||||||
h1.error_title= '404'
|
h1.error_title= '404'
|
||||||
.error_subtitle= theme.error_404.subtitle
|
.error_subtitle= theme.error_404.subtitle
|
||||||
a.button--animated(href=url_for(config.root))
|
a.button--animated(href=config.root)
|
||||||
i.fas.fa-rocket
|
i.fas.fa-rocket
|
||||||
= _p('error404.back_button')
|
= _p('error404.back_button')
|
||||||
|
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ div
|
|||||||
else if commentsJsLoad
|
else if commentsJsLoad
|
||||||
!=partial('includes/comments/js-load-all', {}, {cache:theme.fragment_cache})
|
!=partial('includes/comments/js-load-all', {}, {cache:theme.fragment_cache})
|
||||||
|
|
||||||
if theme.aplayerInject
|
if theme.aplayerInject && !config.aplayer.asset_inject
|
||||||
if theme.pjax
|
if theme.pjax
|
||||||
include ./head/aplayer.pug
|
include ./head/aplayer.pug
|
||||||
else if page.aplayer
|
else if page.aplayer
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
if (theme.google_adsense && theme.google_adsense.enable)
|
if (theme.google_adsense && theme.google_adsense.enable)
|
||||||
script(async src=theme.google_adsense.js)
|
script(async src=theme.google_adsense.js)
|
||||||
script.
|
|
||||||
(adsbygoogle = window.adsbygoogle || []).push({
|
if theme.google_adsense.auto_ads
|
||||||
google_ad_client: '!{theme.google_adsense.client}',
|
script.
|
||||||
enable_page_level_ads: '!{theme.google_adsense.enable_page_level_ads}'
|
(adsbygoogle = window.adsbygoogle || []).push({
|
||||||
});
|
google_ad_client: '!{theme.google_adsense.client}',
|
||||||
|
enable_page_level_ads: '!{theme.google_adsense.enable_page_level_ads}'
|
||||||
|
});
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
- var hideAside = !theme.aside.enable || page.aside === false ? 'hide-aside' : ''
|
- var hideAside = !theme.aside.enable || page.aside === false ? 'hide-aside' : ''
|
||||||
- var pageHighlightShrinkSet = page.highlight_shrink === true || page.highlight_shrink === false ? page.highlight_shrink : theme.highlight_shrink
|
|
||||||
- var pageHighlightShrink = theme.highlight_shrink !== 'none' && pageHighlightShrinkSet ? 'code-close' : ''
|
|
||||||
|
|
||||||
doctype html
|
doctype html
|
||||||
html(lang=config.language data-theme=theme.display_mode)
|
html(lang=config.language data-theme=theme.display_mode)
|
||||||
@@ -15,7 +13,7 @@ html(lang=config.language data-theme=theme.display_mode)
|
|||||||
|
|
||||||
!=partial('includes/mobile-sidebar/index', {}, {cache:theme.fragment_cache})
|
!=partial('includes/mobile-sidebar/index', {}, {cache:theme.fragment_cache})
|
||||||
|
|
||||||
#body-wrap(class=pageHighlightShrink)
|
#body-wrap
|
||||||
if theme.background
|
if theme.background
|
||||||
- var is_photo = theme.background.startsWith('url') ? 'photo':'color'
|
- var is_photo = theme.background.startsWith('url') ? 'photo':'color'
|
||||||
#web_bg(data-type=is_photo)
|
#web_bg(data-type=is_photo)
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ hexo.extend.helper.register('aside_categories', function (categories, options) {
|
|||||||
const categoryDir = this.url_for(config.category_dir)
|
const categoryDir = this.url_for(config.category_dir)
|
||||||
const limit = options.limit === 0 ? categories.length : options.limit
|
const limit = options.limit === 0 ? categories.length : options.limit
|
||||||
const isExpand = options.expand !== 'none'
|
const isExpand = options.expand !== 'none'
|
||||||
const expandClass = isExpand && options.expand === true ? 'card-category-list-icon expand' : 'card-category-list-icon'
|
const expandClass = isExpand && options.expand === true ? 'expand' : ''
|
||||||
|
|
||||||
const buttonLabel = this._p('aside.more_button')
|
const buttonLabel = this._p('aside.more_button')
|
||||||
const prepareQuery = (parent) => {
|
const prepareQuery = (parent) => {
|
||||||
|
|||||||
@@ -135,6 +135,9 @@ blockquote
|
|||||||
color: $highlight-tools.color
|
color: $highlight-tools.color
|
||||||
font-size: 14px
|
font-size: 14px
|
||||||
|
|
||||||
|
&.closed + table
|
||||||
|
display: none
|
||||||
|
|
||||||
.expand
|
.expand
|
||||||
position: absolute
|
position: absolute
|
||||||
padding: .4rem .7rem
|
padding: .4rem .7rem
|
||||||
@@ -215,9 +218,3 @@ blockquote
|
|||||||
|
|
||||||
.code-lang
|
.code-lang
|
||||||
left: 3.8rem !important
|
left: 3.8rem !important
|
||||||
|
|
||||||
// when the page.highlight_shrink set to true
|
|
||||||
#body-wrap.code-close
|
|
||||||
figure.highlight
|
|
||||||
& > :not(.highlight-tools)
|
|
||||||
display: none
|
|
||||||
|
|||||||
@@ -195,15 +195,15 @@
|
|||||||
width: calc(100% - 70% - 20px)
|
width: calc(100% - 70% - 20px)
|
||||||
text-align: right
|
text-align: right
|
||||||
|
|
||||||
&-icon
|
i
|
||||||
float: right
|
float: right
|
||||||
margin-right: -.35rem
|
margin-right: -.35rem
|
||||||
padding: .35rem
|
padding: .35rem
|
||||||
transition: transform .3s
|
transition: transform .3s
|
||||||
transform: rotate(0)
|
transform: rotate(0)
|
||||||
|
|
||||||
&.expand
|
&.expand
|
||||||
transform: rotate(-90deg)
|
transform: rotate(-90deg)
|
||||||
|
|
||||||
if hexo-config('aside.card_categories.expand') == false
|
if hexo-config('aside.card_categories.expand') == false
|
||||||
+ .child
|
+ .child
|
||||||
|
|||||||
@@ -1,4 +1,12 @@
|
|||||||
#vcomment
|
#vcomment
|
||||||
|
.vbtn
|
||||||
|
border: none
|
||||||
|
background: var(--btn-bg)
|
||||||
|
color: var(--btn-color)
|
||||||
|
|
||||||
|
&:hover
|
||||||
|
background: var(--btn-hover-color)
|
||||||
|
|
||||||
if hexo-config('valine.bg')
|
if hexo-config('valine.bg')
|
||||||
textarea
|
textarea
|
||||||
background: url(hexo-config('valine.bg')) 100% 100% no-repeat
|
background: url(hexo-config('valine.bg')) 100% 100% no-repeat
|
||||||
|
|||||||
@@ -209,40 +209,46 @@ const indexScrollDown = () => {
|
|||||||
*/
|
*/
|
||||||
const addHighlightTool = function () {
|
const addHighlightTool = function () {
|
||||||
const $figureHighlight = $('figure.highlight')
|
const $figureHighlight = $('figure.highlight')
|
||||||
if ($figureHighlight.length) {
|
const isHighlightCopy = GLOBAL_CONFIG.highlightCopy
|
||||||
const isHighlightCopy = GLOBAL_CONFIG.highlightCopy
|
const isHighlightLang = GLOBAL_CONFIG.highlightLang
|
||||||
const isHighlightLang = GLOBAL_CONFIG.highlightLang
|
const isHighlightShrink = GLOBAL_CONFIG_SITE.isHighlightShrink
|
||||||
const isHighlightShrink = GLOBAL_CONFIG_SITE.isHighlightShrink
|
|
||||||
|
|
||||||
if (isHighlightCopy || isHighlightLang || isHighlightShrink !== undefined) {
|
if ($figureHighlight.length && (isHighlightCopy || isHighlightLang || isHighlightShrink !== undefined)) {
|
||||||
$figureHighlight.prepend('<div class="highlight-tools"></div>')
|
let highlightShrinkEle = ''
|
||||||
|
let highlightCopyEle = ''
|
||||||
|
const highlightShrinkClass = isHighlightShrink === true ? 'closed' : ''
|
||||||
|
|
||||||
|
if (isHighlightShrink !== undefined) {
|
||||||
|
highlightShrinkEle = `<i class="fas fa-angle-down expand ${highlightShrinkClass}"></i>`
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isHighlightCopy) {
|
||||||
|
highlightCopyEle = '<div class="copy-notice"></div><i class="fas fa-paste copy-button"></i>'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isHighlightLang) {
|
||||||
|
let langName
|
||||||
|
$figureHighlight.each(function () {
|
||||||
|
const $this = $(this)
|
||||||
|
langName = $this.attr('class').split(' ')[1]
|
||||||
|
if (langName === 'plain' || langName === undefined) langName = 'Code'
|
||||||
|
const highlightLangEle = `<div class="code-lang">${langName}</div>`
|
||||||
|
$this.prepend(`<div class="highlight-tools ${highlightShrinkClass}">${highlightShrinkEle + highlightLangEle + highlightCopyEle}</div>`)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
$figureHighlight.prepend(`<div class="highlight-tools ${highlightShrinkClass}">${highlightShrinkEle + highlightCopyEle}</div>`)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 代碼收縮
|
* 代碼收縮
|
||||||
*/
|
*/
|
||||||
const $highlightTools = $('.highlight-tools')
|
|
||||||
if (isHighlightShrink === true) {
|
|
||||||
$highlightTools.append('<i class="fas fa-angle-down expand closed"></i>')
|
|
||||||
} else if (isHighlightShrink === false) {
|
|
||||||
$highlightTools.append('<i class="fas fa-angle-down expand"></i>')
|
|
||||||
}
|
|
||||||
|
|
||||||
$highlightTools.find('>.expand').on('click', function () {
|
if (isHighlightShrink !== undefined) {
|
||||||
const $this = $(this)
|
$figureHighlight.find('.highlight-tools >.expand').on('click', function () {
|
||||||
$this.parent().nextAll().toggle()
|
const $this = $(this)
|
||||||
$this.toggleClass('closed')
|
const $table = $this.parent().nextAll()
|
||||||
})
|
$this.toggleClass('closed')
|
||||||
|
$table.is(':visible') ? $table.css('display', 'none') : $table.css('display', 'block')
|
||||||
/**
|
|
||||||
* 代碼語言
|
|
||||||
*/
|
|
||||||
if (isHighlightLang) {
|
|
||||||
let langNameIndex, langName
|
|
||||||
$figureHighlight.each(function () {
|
|
||||||
langNameIndex = langName = $(this).attr('class').split(' ')[1]
|
|
||||||
if (langNameIndex === 'plain' || langNameIndex === undefined) langName = 'Code'
|
|
||||||
$(this).find('.highlight-tools').append('<div class="code-lang">' + langName + '</div>')
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,43 +256,23 @@ const addHighlightTool = function () {
|
|||||||
* 代碼copy
|
* 代碼copy
|
||||||
*/
|
*/
|
||||||
if (isHighlightCopy) {
|
if (isHighlightCopy) {
|
||||||
$highlightTools.append('<div class="copy-notice"></div><i class="fas fa-paste copy-button"></i>')
|
|
||||||
const copy = function (text, ctx) {
|
const copy = function (text, ctx) {
|
||||||
if (document.queryCommandSupported && document.queryCommandSupported('copy')) {
|
if (document.queryCommandSupported && document.queryCommandSupported('copy')) {
|
||||||
try {
|
document.execCommand('copy')
|
||||||
document.execCommand('copy') // Security exception may be thrown by some browsers.
|
if (GLOBAL_CONFIG.Snackbar !== undefined) {
|
||||||
if (GLOBAL_CONFIG.Snackbar !== undefined) {
|
snackbarShow(GLOBAL_CONFIG.copy.success)
|
||||||
snackbarShow(GLOBAL_CONFIG.copy.success)
|
} else {
|
||||||
} else {
|
$(ctx).prev('.copy-notice')
|
||||||
$(ctx).prev('.copy-notice')
|
.text(GLOBAL_CONFIG.copy.success)
|
||||||
.text(GLOBAL_CONFIG.copy.success)
|
.animate({
|
||||||
.animate({
|
opacity: 1
|
||||||
opacity: 1
|
}, 450, function () {
|
||||||
}, 450, function () {
|
setTimeout(function () {
|
||||||
setTimeout(function () {
|
$(ctx).prev('.copy-notice').animate({
|
||||||
$(ctx).prev('.copy-notice').animate({
|
opacity: 0
|
||||||
opacity: 0
|
}, 650)
|
||||||
}, 650)
|
}, 400)
|
||||||
}, 400)
|
})
|
||||||
})
|
|
||||||
}
|
|
||||||
} catch (ex) {
|
|
||||||
if (GLOBAL_CONFIG.Snackbar !== undefined) {
|
|
||||||
snackbarShow(GLOBAL_CONFIG.copy.success)
|
|
||||||
} else {
|
|
||||||
$(ctx).prev('.copy-notice')
|
|
||||||
.text(GLOBAL_CONFIG.copy.error)
|
|
||||||
.animate({
|
|
||||||
opacity: 1
|
|
||||||
}, 650, function () {
|
|
||||||
setTimeout(function () {
|
|
||||||
$(ctx).prev('.copy-notice').animate({
|
|
||||||
opacity: 0
|
|
||||||
}, 650)
|
|
||||||
}, 400)
|
|
||||||
})
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (GLOBAL_CONFIG.Snackbar !== undefined) {
|
if (GLOBAL_CONFIG.Snackbar !== undefined) {
|
||||||
@@ -298,7 +284,7 @@ const addHighlightTool = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// click events
|
// click events
|
||||||
$highlightTools.find('>.copy-button').on('click', function () {
|
$figureHighlight.find('.highlight-tools >.copy-button').on('click', function () {
|
||||||
const $buttonParent = $(this).parents('figure.highlight')
|
const $buttonParent = $(this).parents('figure.highlight')
|
||||||
$buttonParent.addClass('copy-true')
|
$buttonParent.addClass('copy-true')
|
||||||
const selection = window.getSelection()
|
const selection = window.getSelection()
|
||||||
@@ -747,20 +733,18 @@ const tabsClick = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const cardCategoryToggle = function () {
|
const cardCategoryToggle = function () {
|
||||||
const $cardCategory = $('.card-category-list-item.parent a')
|
const $cardCategory = $('.card-category-list-item.parent i')
|
||||||
$cardCategory.on('click', function (e) {
|
$cardCategory.on('click', function (e) {
|
||||||
if ($(event.target).hasClass('card-category-list-icon')) {
|
e.preventDefault()
|
||||||
const $this = $(this)
|
const $this = $(this)
|
||||||
$this.find('.card-category-list-icon').toggleClass('expand')
|
$this.toggleClass('expand')
|
||||||
$this.parent().next().toggle()
|
$this.parents('.parent').next().toggle()
|
||||||
return false
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const switchComments = function () {
|
const switchComments = function () {
|
||||||
let switchDone = false
|
let switchDone = false
|
||||||
$('#switch-comments-btn').change(function () {
|
$('#switch-comments-btn').on('click', function () {
|
||||||
$('#post-comment > .comment-wrap > div').each(function () {
|
$('#post-comment > .comment-wrap > div').each(function () {
|
||||||
if ($(this).is(':visible')) {
|
if ($(this).is(':visible')) {
|
||||||
$(this).hide()
|
$(this).hide()
|
||||||
|
|||||||
@@ -84,7 +84,7 @@
|
|||||||
}
|
}
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
function translateInitilization () {
|
function translateInitialization () {
|
||||||
translateButtonObject = document.getElementById('translateLink')
|
translateButtonObject = document.getElementById('translateLink')
|
||||||
if (translateButtonObject) {
|
if (translateButtonObject) {
|
||||||
if (currentEncoding !== targetEncoding) {
|
if (currentEncoding !== targetEncoding) {
|
||||||
@@ -94,6 +94,6 @@
|
|||||||
translateButtonObject.addEventListener('click', translatePage, false)
|
translateButtonObject.addEventListener('click', translatePage, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
translateInitilization()
|
translateInitialization()
|
||||||
document.addEventListener('pjax:complete', translateInitilization)
|
document.addEventListener('pjax:complete', translateInitialization)
|
||||||
})()
|
})()
|
||||||
|
|||||||
Reference in New Issue
Block a user