mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-10 21:17:07 +08:00
improvement: 首頁社交圖標左右邊距調整 feat: 文章版權增加圖標 improvement: 重構 main.js 代碼 improvement: 優化 pjax 下的性能 fix: 修復子目錄下,pjax 跳轉 404 錯誤 feat: getScript 增加 attribute 配置 improvement: 優化手機端 toc 打開和關閉特效 improvement: 文章進入特效改為 transform, 優化 stylus improvement: 目錄側邊欄出現滾動條時,元素不會被擠壓 feat: 文章左右對齊 improvement: 處理 waline 的 url 後面多 / 導致跨域的問題 fix: 修復夜間模式下,小屏幕的toc 滾動條顏色不明顯的 bug fix: 修復設置字體超過17px時,toc 裏面的邊框異常的 bug improvement: 優化語言文件部分用詞 improvement: disqus 和 disqusjs 的評論數獲取不到時,顯示為 0 improvement: disqusjs 的評論數改為 api 獲取 improvement: 代碼優化 improvement: 更新 plugins.yml
84 lines
2.8 KiB
Plaintext
84 lines
2.8 KiB
Plaintext
- var pjaxExclude = 'a:not([target="_blank"])'
|
|
if theme.pjax.exclude
|
|
each val in theme.pjax.exclude
|
|
- pjaxExclude = pjaxExclude + `:not([href="${val}"])`
|
|
|
|
- let pjaxSelectors = ['head > title','#config-diff','#body-wrap','#rightside-config-hide','#rightside-config-show','.js-pjax']
|
|
|
|
- let choose = theme.comments.use
|
|
if choose
|
|
if theme.Open_Graph_meta.enable && (choose.includes('Livere') || choose.includes('Utterances') || choose.includes('Giscus'))
|
|
- pjaxSelectors.unshift('meta[property="og:image"]', 'meta[property="og:title"]', 'meta[property="og:url"]')
|
|
if choose.includes('Utterances') || choose.includes('Giscus')
|
|
- pjaxSelectors.unshift('link[rel="canonical"]')
|
|
|
|
script(src=url_for(theme.asset.pjax))
|
|
script.
|
|
let pjaxSelectors = !{JSON.stringify(pjaxSelectors)}
|
|
|
|
var pjax = new Pjax({
|
|
elements: '!{pjaxExclude}',
|
|
selectors: pjaxSelectors,
|
|
cacheBust: false,
|
|
analytics: !{theme.google_analytics ? true : false},
|
|
scrollRestoration: false
|
|
})
|
|
|
|
document.addEventListener('pjax:send', function () {
|
|
|
|
// removeEventListener
|
|
btf.removeGlobalFnEvent('pjax')
|
|
btf.removeGlobalFnEvent('themeChange')
|
|
|
|
document.getElementById('rightside').classList.remove('rightside-show')
|
|
|
|
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')
|
|
|
|
typeof disqusjs === 'object' && disqusjs.destroy()
|
|
})
|
|
|
|
document.addEventListener('pjax:complete', function () {
|
|
window.refreshFn()
|
|
|
|
document.querySelectorAll('script[data-pjax]').forEach(item => {
|
|
const newScript = document.createElement('script')
|
|
const content = item.text || item.textContent || item.innerHTML || ""
|
|
Array.from(item.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value))
|
|
newScript.appendChild(document.createTextNode(content))
|
|
item.parentNode.replaceChild(newScript, item)
|
|
})
|
|
|
|
GLOBAL_CONFIG.islazyload && window.lazyLoadInstance.update()
|
|
|
|
typeof panguInit === 'function' && panguInit()
|
|
|
|
// google analytics
|
|
typeof gtag === 'function' && gtag('config', '!{theme.google_analytics}', {'page_path': window.location.pathname});
|
|
|
|
// baidu analytics
|
|
typeof _hmt === 'object' && _hmt.push(['_trackPageview',window.location.pathname]);
|
|
|
|
typeof loadMeting === 'function' && document.getElementsByClassName('aplayer').length && loadMeting()
|
|
|
|
// prismjs
|
|
typeof Prism === 'object' && Prism.highlightAll()
|
|
})
|
|
|
|
document.addEventListener('pjax:error', e => {
|
|
if (e.request.status === 404) {
|
|
pjax.loadUrl('!{url_for("/404.html")}')
|
|
}
|
|
})
|