mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-10 21:17:07 +08:00
fix: 修復 pjax 下, waline js 會重複加載的 bug
This commit is contained in:
@@ -634,7 +634,8 @@ subtitle:
|
|||||||
# source 調用第三方服務
|
# source 調用第三方服務
|
||||||
# source: false 關閉調用
|
# source: false 關閉調用
|
||||||
# source: 1 調用一言網的一句話(簡體) https://hitokoto.cn/
|
# source: 1 調用一言網的一句話(簡體) https://hitokoto.cn/
|
||||||
# source: 2 調用今日詩詞(簡體) https://www.jinrishici.com/
|
# source: 2 調用一句網(簡體) https://yijuzhan.com/
|
||||||
|
# source: 3 調用今日詩詞(簡體) https://www.jinrishici.com/
|
||||||
# subtitle 會先顯示 source , 再顯示 sub 的內容
|
# subtitle 會先顯示 source , 再顯示 sub 的內容
|
||||||
source: false
|
source: false
|
||||||
# 如果關閉打字效果,subtitle 只會顯示 sub 的第一行文字
|
# 如果關閉打字效果,subtitle 只會顯示 sub 的第一行文字
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ script.
|
|||||||
const waline = Waline.init(initData)
|
const waline = Waline.init(initData)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof Waline === 'function') initWaline()
|
if (typeof Waline === 'object') initWaline()
|
||||||
else getScript('!{url_for(theme.asset.waline_js)}').then(initWaline)
|
else getScript('!{url_for(theme.asset.waline_js)}').then(initWaline)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,6 @@
|
|||||||
- const { server, site, option } = theme.artalk
|
- const { server, site, option } = theme.artalk
|
||||||
|
|
||||||
script.
|
script.
|
||||||
function addArtalkSource () {
|
|
||||||
const ele = document.createElement('link')
|
|
||||||
ele.rel = 'stylesheet'
|
|
||||||
ele.href= '!{theme.asset.artalk_css}'
|
|
||||||
document.getElementsByTagName('head')[0].appendChild(ele)
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadArtalk () {
|
function loadArtalk () {
|
||||||
function initArtalk () {
|
function initArtalk () {
|
||||||
window.artalkItem = new Artalk(Object.assign({
|
window.artalkItem = new Artalk(Object.assign({
|
||||||
@@ -22,7 +15,7 @@ script.
|
|||||||
|
|
||||||
if (typeof window.artalkItem === 'object') setTimeout(()=>{initArtalk()},200)
|
if (typeof window.artalkItem === 'object') setTimeout(()=>{initArtalk()},200)
|
||||||
else {
|
else {
|
||||||
addArtalkSource()
|
getCSS('!{theme.asset.artalk_css}')
|
||||||
typeof Artalk !== 'function' ? getScript('!{theme.asset.artalk_js}').then(initArtalk)
|
typeof Artalk !== 'function' ? getScript('!{theme.asset.artalk_js}').then(initArtalk)
|
||||||
: setTimeout(()=>{initArtalk()},200)
|
: setTimeout(()=>{initArtalk()},200)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,6 @@
|
|||||||
|
|
||||||
script.
|
script.
|
||||||
function loadDisqusjs () {
|
function loadDisqusjs () {
|
||||||
function addDisqusjsCSS () {
|
|
||||||
const ele = document.createElement('link')
|
|
||||||
ele.rel = 'stylesheet'
|
|
||||||
ele.href= '!{url_for(theme.asset.disqusjs_css)}'
|
|
||||||
document.getElementsByTagName('head')[0].appendChild(ele)
|
|
||||||
}
|
|
||||||
|
|
||||||
function initDisqusjs () {
|
function initDisqusjs () {
|
||||||
window.disqusjs = null
|
window.disqusjs = null
|
||||||
disqusjs = new DisqusJS(Object.assign({
|
disqusjs = new DisqusJS(Object.assign({
|
||||||
@@ -34,7 +27,7 @@ script.
|
|||||||
|
|
||||||
if (window.disqusJsLoad) initDisqusjs()
|
if (window.disqusJsLoad) initDisqusjs()
|
||||||
else {
|
else {
|
||||||
addDisqusjsCSS()
|
getCSS('!{url_for(theme.asset.disqusjs_css)}')
|
||||||
getScript('!{url_for(theme.asset.disqusjs)}').then(initDisqusjs)
|
getScript('!{url_for(theme.asset.disqusjs)}').then(initDisqusjs)
|
||||||
window.disqusJsLoad = true
|
window.disqusJsLoad = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,4 @@
|
|||||||
script.
|
script.
|
||||||
function addGitalkSource () {
|
|
||||||
const ele = document.createElement('link')
|
|
||||||
ele.rel = 'stylesheet'
|
|
||||||
ele.href= '!{url_for(theme.asset.gitalk_css)}'
|
|
||||||
document.getElementsByTagName('head')[0].appendChild(ele)
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadGitalk () {
|
function loadGitalk () {
|
||||||
function initGitalk () {
|
function initGitalk () {
|
||||||
var gitalk = new Gitalk(Object.assign({
|
var gitalk = new Gitalk(Object.assign({
|
||||||
@@ -23,7 +16,7 @@ script.
|
|||||||
|
|
||||||
if (typeof Gitalk === 'function') initGitalk()
|
if (typeof Gitalk === 'function') initGitalk()
|
||||||
else {
|
else {
|
||||||
addGitalkSource()
|
getCSS('!{url_for(theme.asset.gitalk_css)}')
|
||||||
getScript('!{url_for(theme.asset.gitalk)}').then(initGitalk)
|
getScript('!{url_for(theme.asset.gitalk)}').then(initGitalk)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
14
layout/includes/third-party/comments/waline.pug
vendored
14
layout/includes/third-party/comments/waline.pug
vendored
@@ -3,13 +3,6 @@
|
|||||||
|
|
||||||
script.
|
script.
|
||||||
function loadWaline () {
|
function loadWaline () {
|
||||||
function insertCSS () {
|
|
||||||
const link = document.createElement("link")
|
|
||||||
link.rel = "stylesheet"
|
|
||||||
link.href = "!{url_for(theme.asset.waline_css)}"
|
|
||||||
document.head.appendChild(link)
|
|
||||||
}
|
|
||||||
|
|
||||||
function initWaline () {
|
function initWaline () {
|
||||||
const waline = Waline.init(Object.assign({
|
const waline = Waline.init(Object.assign({
|
||||||
el: '#waline-wrap',
|
el: '#waline-wrap',
|
||||||
@@ -21,10 +14,11 @@ script.
|
|||||||
}, !{JSON.stringify(option)}))
|
}, !{JSON.stringify(option)}))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof Waline === 'function') initWaline()
|
if (typeof Waline === 'object') initWaline()
|
||||||
else {
|
else {
|
||||||
insertCSS()
|
getCSS('!{url_for(theme.asset.waline_css)}').then(() => {
|
||||||
getScript('!{url_for(theme.asset.waline_js)}').then(initWaline)
|
getScript('!{url_for(theme.asset.waline_js)}').then(initWaline)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ script.
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof Waline === 'function') loadWaline()
|
if (typeof Waline === 'object') loadWaline()
|
||||||
else getScript('!{url_for(theme.asset.waline_js)}').then(loadWaline)
|
else getScript('!{url_for(theme.asset.waline_js)}').then(loadWaline)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
32
layout/includes/third-party/subtitle.pug
vendored
32
layout/includes/third-party/subtitle.pug
vendored
@@ -36,6 +36,38 @@ case source
|
|||||||
}
|
}
|
||||||
|
|
||||||
when 2
|
when 2
|
||||||
|
script.
|
||||||
|
function subtitleType () {
|
||||||
|
getScript('https://yijuzhan.com/api/word.php?m=js').then(() => {
|
||||||
|
const con = str[0]
|
||||||
|
if (!{effect}) {
|
||||||
|
const from = '出自 ' + str[1]
|
||||||
|
const sub = !{JSON.stringify(subContent)}
|
||||||
|
sub.unshift(con, from)
|
||||||
|
window.typed = new Typed('#subtitle', {
|
||||||
|
strings: sub,
|
||||||
|
startDelay: !{startDelay},
|
||||||
|
typeSpeed: !{typeSpeed},
|
||||||
|
loop: !{loop},
|
||||||
|
backSpeed: !{backSpeed},
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
document.getElementById('subtitle').innerHTML = con
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!{effect}) {
|
||||||
|
if (typeof Typed === 'function') {
|
||||||
|
subtitleType()
|
||||||
|
} else {
|
||||||
|
getScript('!{url_for(theme.asset.typed)}').then(subtitleType)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
subtitleType()
|
||||||
|
}
|
||||||
|
|
||||||
|
when 3
|
||||||
script.
|
script.
|
||||||
function subtitleType () {
|
function subtitleType () {
|
||||||
getScript('https://sdk.jinrishici.com/v2/browser/jinrishici.js').then(() => {
|
getScript('https://sdk.jinrishici.com/v2/browser/jinrishici.js').then(() => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hexo-theme-butterfly",
|
"name": "hexo-theme-butterfly",
|
||||||
"version": "4.6.0-b4",
|
"version": "4.6.0",
|
||||||
"description": "A Simple and Card UI Design theme for Hexo",
|
"description": "A Simple and Card UI Design theme for Hexo",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -42,12 +42,12 @@ waline_js:
|
|||||||
name: '@waline/client'
|
name: '@waline/client'
|
||||||
file: dist/waline.js
|
file: dist/waline.js
|
||||||
other_name: waline
|
other_name: waline
|
||||||
version: 2.14.6
|
version: 2.14.7
|
||||||
waline_css:
|
waline_css:
|
||||||
name: '@waline/client'
|
name: '@waline/client'
|
||||||
file: dist/waline.css
|
file: dist/waline.css
|
||||||
other_name: waline
|
other_name: waline
|
||||||
version: 2.14.6
|
version: 2.14.7
|
||||||
sharejs:
|
sharejs:
|
||||||
name: butterfly-extsrc
|
name: butterfly-extsrc
|
||||||
file: sharejs/dist/js/social-share.min.js
|
file: sharejs/dist/js/social-share.min.js
|
||||||
|
|||||||
@@ -60,6 +60,17 @@ hexo.extend.helper.register('inject_head_js', function () {
|
|||||||
})
|
})
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const getCSS = `
|
||||||
|
win.getCSS = url => new Promise((resolve, reject) => {
|
||||||
|
const link = document.createElement('link')
|
||||||
|
link.rel = 'stylesheet'
|
||||||
|
link.href = url
|
||||||
|
link.onload = () => resolve()
|
||||||
|
link.onerror = () => reject()
|
||||||
|
document.head.appendChild(link)
|
||||||
|
})
|
||||||
|
`
|
||||||
|
|
||||||
let darkmodeJs = ''
|
let darkmodeJs = ''
|
||||||
if (darkmode.enable) {
|
if (darkmode.enable) {
|
||||||
darkmodeJs = `
|
darkmodeJs = `
|
||||||
@@ -144,5 +155,5 @@ hexo.extend.helper.register('inject_head_js', function () {
|
|||||||
detectApple()
|
detectApple()
|
||||||
`
|
`
|
||||||
|
|
||||||
return `<script>(win=>{${localStore + getScript + darkmodeJs + asideStatus + detectApple}})(window)</script>`
|
return `<script>(win=>{${localStore + getScript + getCSS + darkmodeJs + asideStatus + detectApple}})(window)</script>`
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -275,10 +275,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const newEle = document.createElement('link')
|
getCSS(`${GLOBAL_CONFIG.source.justifiedGallery.css}`)
|
||||||
newEle.rel = 'stylesheet'
|
|
||||||
newEle.href = GLOBAL_CONFIG.source.justifiedGallery.css
|
|
||||||
document.body.appendChild(newEle)
|
|
||||||
getScript(`${GLOBAL_CONFIG.source.justifiedGallery.js}`).then(() => { btf.initJustifiedGallery(ele) })
|
getScript(`${GLOBAL_CONFIG.source.justifiedGallery.js}`).then(() => { btf.initJustifiedGallery(ele) })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user