From 597f0d2019464cb2fcd501f160045cc30dc09717 Mon Sep 17 00:00:00 2001 From: Jerry Date: Fri, 23 Apr 2021 18:06:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=BE=A9=E9=96=8B=E5=95=9Fanch?= =?UTF-8?q?or=E5=BE=8C,=E7=80=8F=E8=A6=BD=E5=99=A8=E4=B8=8A=E4=B8=80?= =?UTF-8?q?=E9=A0=81/=E4=B8=8B=E4=B8=80=E9=A0=81=20=E8=B7=B3=E8=BD=89?= =?UTF-8?q?=E6=9C=83404=E7=9A=84bug=20(=E6=96=87=E7=AB=A0=E9=A0=81?= =?UTF-8?q?=E7=9A=84url=20hash=20=E5=9C=A8pjax=E4=B8=8B=E8=AE=8A=E6=88=90?= =?UTF-8?q?=20undefined)=20fix:=20=E4=BF=AE=E5=BE=A9=E9=96=8B=E5=95=9Fanch?= =?UTF-8?q?or=E5=BE=8C=EF=BC=8C=E6=96=87=E7=AB=A0=E9=A0=81=E8=B7=B3?= =?UTF-8?q?=E8=BD=89=E5=9B=9E=E4=B8=BB=E9=A0=81=EF=BC=8C=E4=B8=BB=E9=A0=81?= =?UTF-8?q?=E7=B6=B2=E5=9D=80=E7=9A=84hash=E6=B7=BB=E5=8A=A0=E4=B8=8A?= =?UTF-8?q?=E6=96=87=E7=AB=A0=E9=A0=81=E6=9C=80=E5=BE=8C=E4=B8=80=E5=80=8B?= =?UTF-8?q?=E6=A8=99=E9=A1=8C=E7=9A=84=20bug=20improvement:=20=E5=84=AA?= =?UTF-8?q?=E5=8C=96=20button=20tags=20=E6=A8=99=E7=B0=BD=E5=A4=96?= =?UTF-8?q?=E6=8E=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 ++++- README_CN.md | 7 ++++- layout/includes/third-party/pjax.pug | 47 ++++++++++++++++------------ package.json | 2 +- scripts/tag/button.js | 2 +- source/css/_tags/button.styl | 3 ++ source/js/main.js | 13 +++++--- 7 files changed, 52 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index f9d97b5..ab66397 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,8 @@ ![hexo version](https://img.shields.io/badge/hexo-5.0+-0e83c) ![license](https://img.shields.io/github/license/jerryc127/hexo-theme-butterfly?color=FF5531) +![](https://cdn.jsdelivr.net/gh/jerryc127/CDN@m2/img/theme-butterfly-readme.png) + Demo: 👍 [Butterfly](https://butterfly.js.org/) || 🤞 [MYW](https://immyw.com/) Docs: 📖 [Butterfly Docs](https://butterfly.js.org/posts/21cfbf15/) @@ -97,6 +99,9 @@ npm i hexo-theme-butterfly ## Screenshots +![](https://cdn.jsdelivr.net/gh/jerryc127/CDN@m2/img/butterfly-readme-screenshots-1.jpg) +![](https://cdn.jsdelivr.net/gh/jerryc127/CDN@m2/img/butterfly-readme-screenshots-2.jpg) +![](https://cdn.jsdelivr.net/gh/jerryc127/CDN@m2/img/butterfly-readme-screenshots-3.jpg) +![](https://cdn.jsdelivr.net/gh/jerryc127/CDN@m2/img/butterfly-readme-screenshots-4.jpg) ![](https://cdn.jsdelivr.net/gh/jerryc127/CDN/img/theme-butterfly-readme-homepage-1.png) - ![](https://cdn.jsdelivr.net/gh/jerryc127/CDN/img/theme-butterfly-readme-homepage-2.png) \ No newline at end of file diff --git a/README_CN.md b/README_CN.md index 659d1ba..4ff1566 100644 --- a/README_CN.md +++ b/README_CN.md @@ -12,6 +12,8 @@ ![hexo version](https://img.shields.io/badge/hexo-5.0+-0e83c) ![license](https://img.shields.io/github/license/jerryc127/hexo-theme-butterfly?color=FF5531) +![](https://cdn.jsdelivr.net/gh/jerryc127/CDN@m2/img/theme-butterfly-readme.png) + 預覽: 👍 [Butterfly](https://butterfly.js.org/) || 🤞 [MYW](https://immyw.com/) 文檔: 📖 [Butterfly Docs](https://butterfly.js.org/posts/21cfbf15/) @@ -96,6 +98,9 @@ theme: butterfly ## 截圖 +![](https://cdn.jsdelivr.net/gh/jerryc127/CDN@m2/img/butterfly-readme-screenshots-1.jpg) +![](https://cdn.jsdelivr.net/gh/jerryc127/CDN@m2/img/butterfly-readme-screenshots-2.jpg) +![](https://cdn.jsdelivr.net/gh/jerryc127/CDN@m2/img/butterfly-readme-screenshots-3.jpg) +![](https://cdn.jsdelivr.net/gh/jerryc127/CDN@m2/img/butterfly-readme-screenshots-4.jpg) ![](https://cdn.jsdelivr.net/gh/jerryc127/CDN/img/theme-butterfly-readme-homepage-1.png) - ![](https://cdn.jsdelivr.net/gh/jerryc127/CDN/img/theme-butterfly-readme-homepage-2.png) \ No newline at end of file diff --git a/layout/includes/third-party/pjax.pug b/layout/includes/third-party/pjax.pug index 853c627..8989f30 100644 --- a/layout/includes/third-party/pjax.pug +++ b/layout/includes/third-party/pjax.pug @@ -26,6 +26,29 @@ script. scrollRestoration: false }) + document.addEventListener('pjax:send', function () { + + // removeEventListener toc scroll + window.removeEventListener('scroll', window.tocScrollFn) + + typeof preloader === 'object' && preloader.initLoading() + + if (window.aplayers) { + for (let i = 0; i < window.aplayers.length; i++) { + if (!window.aplayers[i].options.fixed) { + window.aplayers[i].destroy() + } + } + } + + typeof typed === 'object' && typed.destroy() + + //reset readmode + const $bodyClassList = document.body.classList + $bodyClassList.contains('read-mode') && $bodyClassList.remove('read-mode') + + }) + document.addEventListener('pjax:complete', function () { window.refreshFn() @@ -61,28 +84,12 @@ script. typeof preloader === 'object' && preloader.endLoading() }) - - document.addEventListener('pjax:send', function () { - typeof preloader === 'object' && preloader.initLoading() - - if (window.aplayers) { - for (let i = 0; i < window.aplayers.length; i++) { - if (!window.aplayers[i].options.fixed) { - window.aplayers[i].destroy() - } - } - } - - typeof typed === 'object' && typed.destroy() - - //reset readmode - const $bodyClassList = document.body.classList - $bodyClassList.contains('read-mode') && $bodyClassList.remove('read-mode') - - }) - document.addEventListener('pjax:error', (e) => { if (e.request.status === 404) { + if (!{theme.anchor}) { + location.hash && e.request.responseURL !== location.href ? pjax.loadUrl(location.href) : pjax.loadUrl('/404.html') + return + } pjax.loadUrl('/404.html') } }) diff --git a/package.json b/package.json index e5c3727..2b5a271 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hexo-theme-butterfly", - "version": "3.7.5-b3", + "version": "3.7.5-b4", "description": "A Simple and Card UI Design theme for Hexo", "main": "package.json", "scripts": { diff --git a/scripts/tag/button.js b/scripts/tag/button.js index bb5a18a..791a8e3 100644 --- a/scripts/tag/button.js +++ b/scripts/tag/button.js @@ -22,7 +22,7 @@ function btn (args) { option = option.trim() return `${icon.length > 0 ? `` : ''}${text}` + title="${text}">${icon.length ? `` : ''}${text.length ? `${text}` : ''}` } hexo.extend.tag.register('btn', btn, { ends: false }) diff --git a/source/css/_tags/button.styl b/source/css/_tags/button.styl index 79cceed..7dcf0a7 100644 --- a/source/css/_tags/button.styl +++ b/source/css/_tags/button.styl @@ -11,6 +11,9 @@ color: $btn-color line-height: 2 + i + span + margin-left: .3rem + &:not(.block) + .btn-beautify:not(.block) margin: 0 .2rem 1rem diff --git a/source/js/main.js b/source/js/main.js index 9658c73..c444428 100644 --- a/source/js/main.js +++ b/source/js/main.js @@ -388,11 +388,14 @@ document.addEventListener('DOMContentLoaded', function () { const $article = document.getElementById('article-container') // main of scroll - window.addEventListener('scroll', btf.throttle(function (e) { - const currentTop = window.scrollY || document.documentElement.scrollTop - scrollPercent(currentTop) - findHeadPosition(currentTop) - }, 100)) + window.tocScrollFn = function () { + return btf.throttle(function () { + const currentTop = window.scrollY || document.documentElement.scrollTop + scrollPercent(currentTop) + findHeadPosition(currentTop) + }, 100)() + } + window.addEventListener('scroll', tocScrollFn) const scrollPercent = function (currentTop) { const docHeight = $article.clientHeight