diff --git a/layout/404.pug b/layout/404.pug index 2de0d72..0e6c394 100644 --- a/layout/404.pug +++ b/layout/404.pug @@ -22,7 +22,7 @@ html(lang=config.language data-theme=theme.display_mode) .error-info h1.error_title= '404' .error_subtitle= theme.error_404.subtitle - a.button--animated(href=url_for(config.root)) + a.button--animated(href=config.root) i.fas.fa-rocket = _p('error404.back_button') diff --git a/layout/includes/additional-js.pug b/layout/includes/additional-js.pug index 2607711..6710a45 100644 --- a/layout/includes/additional-js.pug +++ b/layout/includes/additional-js.pug @@ -83,7 +83,7 @@ div else if commentsJsLoad !=partial('includes/comments/js-load-all', {}, {cache:theme.fragment_cache}) - if theme.aplayerInject + if theme.aplayerInject && !config.aplayer.asset_inject if theme.pjax include ./head/aplayer.pug else if page.aplayer diff --git a/layout/includes/head/google_adsense.pug b/layout/includes/head/google_adsense.pug index b3210ef..3ef1af9 100644 --- a/layout/includes/head/google_adsense.pug +++ b/layout/includes/head/google_adsense.pug @@ -1,7 +1,9 @@ if (theme.google_adsense && theme.google_adsense.enable) script(async src=theme.google_adsense.js) - script. - (adsbygoogle = window.adsbygoogle || []).push({ - google_ad_client: '!{theme.google_adsense.client}', - enable_page_level_ads: '!{theme.google_adsense.enable_page_level_ads}' - }); \ No newline at end of file + + if theme.google_adsense.auto_ads + script. + (adsbygoogle = window.adsbygoogle || []).push({ + google_ad_client: '!{theme.google_adsense.client}', + enable_page_level_ads: '!{theme.google_adsense.enable_page_level_ads}' + }); \ No newline at end of file diff --git a/layout/includes/layout.pug b/layout/includes/layout.pug index 7fa71cc..6e52f4e 100644 --- a/layout/includes/layout.pug +++ b/layout/includes/layout.pug @@ -1,6 +1,4 @@ - 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 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}) - #body-wrap(class=pageHighlightShrink) + #body-wrap if theme.background - var is_photo = theme.background.startsWith('url') ? 'photo':'color' #web_bg(data-type=is_photo) diff --git a/scripts/helpers/aside_categories.js b/scripts/helpers/aside_categories.js index d597862..19587e2 100644 --- a/scripts/helpers/aside_categories.js +++ b/scripts/helpers/aside_categories.js @@ -24,7 +24,7 @@ hexo.extend.helper.register('aside_categories', function (categories, options) { const categoryDir = this.url_for(config.category_dir) const limit = options.limit === 0 ? categories.length : options.limit 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 prepareQuery = (parent) => { diff --git a/source/css/_highlight/highlight.styl b/source/css/_highlight/highlight.styl index 8ca0ffa..7d3e6e9 100644 --- a/source/css/_highlight/highlight.styl +++ b/source/css/_highlight/highlight.styl @@ -135,6 +135,9 @@ blockquote color: $highlight-tools.color font-size: 14px + &.closed + table + display: none + .expand position: absolute padding: .4rem .7rem @@ -215,9 +218,3 @@ blockquote .code-lang left: 3.8rem !important - -// when the page.highlight_shrink set to true -#body-wrap.code-close - figure.highlight - & > :not(.highlight-tools) - display: none diff --git a/source/css/_layout/aside.styl b/source/css/_layout/aside.styl index 1fba958..365af45 100644 --- a/source/css/_layout/aside.styl +++ b/source/css/_layout/aside.styl @@ -195,15 +195,15 @@ width: calc(100% - 70% - 20px) text-align: right - &-icon - float: right - margin-right: -.35rem - padding: .35rem - transition: transform .3s - transform: rotate(0) + i + float: right + margin-right: -.35rem + padding: .35rem + transition: transform .3s + transform: rotate(0) - &.expand - transform: rotate(-90deg) + &.expand + transform: rotate(-90deg) if hexo-config('aside.card_categories.expand') == false + .child diff --git a/source/css/_layout/third-party.styl b/source/css/_layout/third-party.styl index fff86cc..80610f9 100644 --- a/source/css/_layout/third-party.styl +++ b/source/css/_layout/third-party.styl @@ -1,4 +1,12 @@ #vcomment + .vbtn + border: none + background: var(--btn-bg) + color: var(--btn-color) + + &:hover + background: var(--btn-hover-color) + if hexo-config('valine.bg') textarea background: url(hexo-config('valine.bg')) 100% 100% no-repeat diff --git a/source/js/main.js b/source/js/main.js index 4609bea..b03b1e0 100644 --- a/source/js/main.js +++ b/source/js/main.js @@ -209,40 +209,46 @@ const indexScrollDown = () => { */ const addHighlightTool = function () { const $figureHighlight = $('figure.highlight') - if ($figureHighlight.length) { - const isHighlightCopy = GLOBAL_CONFIG.highlightCopy - const isHighlightLang = GLOBAL_CONFIG.highlightLang - const isHighlightShrink = GLOBAL_CONFIG_SITE.isHighlightShrink + const isHighlightCopy = GLOBAL_CONFIG.highlightCopy + const isHighlightLang = GLOBAL_CONFIG.highlightLang + const isHighlightShrink = GLOBAL_CONFIG_SITE.isHighlightShrink - if (isHighlightCopy || isHighlightLang || isHighlightShrink !== undefined) { - $figureHighlight.prepend('
') + if ($figureHighlight.length && (isHighlightCopy || isHighlightLang || isHighlightShrink !== undefined)) { + let highlightShrinkEle = '' + let highlightCopyEle = '' + const highlightShrinkClass = isHighlightShrink === true ? 'closed' : '' + + if (isHighlightShrink !== undefined) { + highlightShrinkEle = `` + } + + if (isHighlightCopy) { + highlightCopyEle = '
' + } + + 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 = `
${langName}
` + $this.prepend(`
${highlightShrinkEle + highlightLangEle + highlightCopyEle}
`) + }) + } else { + $figureHighlight.prepend(`
${highlightShrinkEle + highlightCopyEle}
`) } /** * 代碼收縮 */ - const $highlightTools = $('.highlight-tools') - if (isHighlightShrink === true) { - $highlightTools.append('') - } else if (isHighlightShrink === false) { - $highlightTools.append('') - } - $highlightTools.find('>.expand').on('click', function () { - const $this = $(this) - $this.parent().nextAll().toggle() - $this.toggleClass('closed') - }) - - /** - * 代碼語言 - */ - 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('
' + langName + '
') + if (isHighlightShrink !== undefined) { + $figureHighlight.find('.highlight-tools >.expand').on('click', function () { + const $this = $(this) + const $table = $this.parent().nextAll() + $this.toggleClass('closed') + $table.is(':visible') ? $table.css('display', 'none') : $table.css('display', 'block') }) } @@ -250,43 +256,23 @@ const addHighlightTool = function () { * 代碼copy */ if (isHighlightCopy) { - $highlightTools.append('
') const copy = function (text, ctx) { if (document.queryCommandSupported && document.queryCommandSupported('copy')) { - try { - document.execCommand('copy') // Security exception may be thrown by some browsers. - if (GLOBAL_CONFIG.Snackbar !== undefined) { - snackbarShow(GLOBAL_CONFIG.copy.success) - } else { - $(ctx).prev('.copy-notice') - .text(GLOBAL_CONFIG.copy.success) - .animate({ - opacity: 1 - }, 450, function () { - setTimeout(function () { - $(ctx).prev('.copy-notice').animate({ - opacity: 0 - }, 650) - }, 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 - } + document.execCommand('copy') + if (GLOBAL_CONFIG.Snackbar !== undefined) { + snackbarShow(GLOBAL_CONFIG.copy.success) + } else { + $(ctx).prev('.copy-notice') + .text(GLOBAL_CONFIG.copy.success) + .animate({ + opacity: 1 + }, 450, function () { + setTimeout(function () { + $(ctx).prev('.copy-notice').animate({ + opacity: 0 + }, 650) + }, 400) + }) } } else { if (GLOBAL_CONFIG.Snackbar !== undefined) { @@ -298,7 +284,7 @@ const addHighlightTool = function () { } // click events - $highlightTools.find('>.copy-button').on('click', function () { + $figureHighlight.find('.highlight-tools >.copy-button').on('click', function () { const $buttonParent = $(this).parents('figure.highlight') $buttonParent.addClass('copy-true') const selection = window.getSelection() @@ -747,20 +733,18 @@ const tabsClick = 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) { - if ($(event.target).hasClass('card-category-list-icon')) { - const $this = $(this) - $this.find('.card-category-list-icon').toggleClass('expand') - $this.parent().next().toggle() - return false - } + e.preventDefault() + const $this = $(this) + $this.toggleClass('expand') + $this.parents('.parent').next().toggle() }) } const switchComments = function () { let switchDone = false - $('#switch-comments-btn').change(function () { + $('#switch-comments-btn').on('click', function () { $('#post-comment > .comment-wrap > div').each(function () { if ($(this).is(':visible')) { $(this).hide() diff --git a/source/js/tw_cn.js b/source/js/tw_cn.js index f2c029c..e9d28f1 100644 --- a/source/js/tw_cn.js +++ b/source/js/tw_cn.js @@ -84,7 +84,7 @@ } return str } - function translateInitilization () { + function translateInitialization () { translateButtonObject = document.getElementById('translateLink') if (translateButtonObject) { if (currentEncoding !== targetEncoding) { @@ -94,6 +94,6 @@ translateButtonObject.addEventListener('click', translatePage, false) } } - translateInitilization() - document.addEventListener('pjax:complete', translateInitilization) + translateInitialization() + document.addEventListener('pjax:complete', translateInitialization) })()