mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2025-09-15 12:58:48 +08:00
fix: 修復開啟anchor後,瀏覽器上一頁/下一頁 跳轉會404的bug (文章頁的url hash 在pjax下變成 undefined)
fix: 修復開啟anchor後,文章頁跳轉回主頁,主頁網址的hash添加上文章頁最後一個標題的 bug improvement: 優化 button tags 標簽外掛
This commit is contained in:
parent
c48ce9af8c
commit
597f0d2019
@ -12,6 +12,8 @@
|
||||

|
||||

|
||||
|
||||

|
||||
|
||||
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
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||

|
||||
@ -12,6 +12,8 @@
|
||||

|
||||

|
||||
|
||||

|
||||
|
||||
預覽: 👍 [Butterfly](https://butterfly.js.org/) || 🤞 [MYW](https://immyw.com/)
|
||||
|
||||
文檔: 📖 [Butterfly Docs](https://butterfly.js.org/posts/21cfbf15/)
|
||||
@ -96,6 +98,9 @@ theme: butterfly
|
||||
|
||||
## 截圖
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||

|
||||
47
layout/includes/third-party/pjax.pug
vendored
47
layout/includes/third-party/pjax.pug
vendored
@ -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')
|
||||
}
|
||||
})
|
||||
|
||||
@ -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": {
|
||||
|
||||
@ -22,7 +22,7 @@ function btn (args) {
|
||||
option = option.trim()
|
||||
|
||||
return `<a class="btn-beautify button--animated ${option}" href="${urlFor(url)}"
|
||||
title="${text}">${icon.length > 0 ? `<i class="${icon} fa-fw"></i>` : ''}<span>${text}</span></a>`
|
||||
title="${text}">${icon.length ? `<i class="${icon}"></i>` : ''}${text.length ? `<span>${text}</span>` : ''}</a>`
|
||||
}
|
||||
|
||||
hexo.extend.tag.register('btn', btn, { ends: false })
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user