提交 037bbc76 编写于 作者: EvanOne(文一)'s avatar EvanOne(文一)

fix: Fix busuanzi & math & comments invalid when enable pjax

上级 b64610a7
......@@ -524,6 +524,7 @@ math:
# If true, it will load mathjax / katex srcipt EVERY PAGE.
per_page: false
# value: mathjax / katex (suggest: katex)
engine: katex
# See: https://github.com/mathjax/MathJax/
......@@ -601,31 +602,28 @@ lazyload:
# See: https://github.com/GoogleChromeLabs/quicklink/
quicklink:
enable: false
# Quicklink (quicklink.umd.js script) is loaded on demand.
# Add `quicklink: true` in Front-matter of the page or post you need.
# Home page and archive page can be controlled through home and archive options below.
home: true
archive: true
# Initialize quicklink after the load event fires.
delay: true
# Custom a time in milliseconds by which the browser must execute prefetching.
timeout: 10000
# Enable fetch() or falls back to XHR.
priority: true
# For more flexibility you can add some patterns (RegExp, Function, or Array) to ignores.
# See: https://github.com/GoogleChromeLabs/quicklink#custom-ignore-patterns
# ! ---------------------------------------------------------------
# ! Leave "ignores" as empty if you don't understand what it means.
# ! ---------------------------------------------------------------
# Example:
# ignores:
# - /\/api\/?/
# - uri => uri.includes('.zip')
# - (uri, el) => el.hasAttribute('nofollow')
ignores:
- /\/api\/?/
- uri => uri.includes('.xml')
- uri => uri.includes('.zip')
- (uri, el) => el.hasAttribute('nofollow')
- (uri, el) => el.hasAttribute('noprefetch')
# Pjax
# See: https://github.com/MoOx/pjax/
......
......@@ -96,5 +96,5 @@ if theme.tencent_analytics
link(rel="dns-prefetch" href="https://tajs.qq.com")
include ../_third-party/math/katex_css.pug
include ../_third-party/analytics/analytics-widget.pug
include ../_third-party/analytics/index.pug
include ./config.pug
......@@ -15,13 +15,13 @@ html(lang=config.language)
include ../_scripts/vendors.pug
include ../_third-party/quicklink.pug
include ../_third-party/advertising/index.pug
include ../_third-party/analytics/index.pug
include ../_third-party/comments/index.pug
include ../_third-party/math/index.pug
include ../_third-party/search/index.pug
include ../_third-party/comments/index.pug
if theme.pjax && theme.pjax.enable
include ../_third-party/pjax.pug
include ../_third-party/analytics/busuanzi.pug
include ../_third-party/advertising/index.pug
include ../_third-party/math/index.pug
include ../_scripts/stun.pug
//- Reset `window.Promise` when it was not a function.
//- IE refers the element whose id is `Promise` as `window.Promise`, this causes Velocity throwing an exception
script.
if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
window.Promise = null;
}
- var jquery_js = "https://cdn.jsdelivr.net/npm/jquery@v3.4.1/dist/jquery.min.js"
- var velocity_js = "https://cdn.jsdelivr.net/npm/velocity-animate@1.5.2/velocity.min.js"
- var velocity_ui_js = "https://cdn.jsdelivr.net/npm/velocity-animate@1.5.2/velocity.ui.min.js"
......
if theme.google_analytics
include ./google-analytics.pug
if theme.baidu_analytics
include ./baidu-analytics.pug
if theme.tencent_analytics
include ./tencent-analytics.pug
-
var busuanzi_js = "https://cdn.jsdelivr.net/gh/sukkaw/busuanzi@latest/bsz.pure.mini.js"
if (theme.cdn.busuanzi) busuanzi_js = theme.cdn.busuanzi
if theme.busuanzi.enable
- var busuanzi_js = "https://cdn.jsdelivr.net/gh/sukkaw/busuanzi@latest/bsz.pure.mini.js"
- if (theme.cdn.busuanzi) busuanzi_js = theme.cdn.busuanzi
script(async src=busuanzi_js)
script.
window.addEventListener('load', function () {
Stun.utils.pjaxReloadBusuanzi = function () {
(function(d, s) {
// Remove old script of busuanzi
var old = d.getElementById('busuazi_statistics');
if (old) {
var parent = d.querySelector('head');
parent.removeChild(old);
}
var d = document, s = d.createElement('script');
s.id = 'busuazi_statistics'
s.src = '!{ busuanzi_js }';
s.setAttribute('async', '');
(d.head || d.body).appendChild(s);
})(document, 'script');
};
// Initialization
Stun.utils.pjaxReloadBusuanzi();
}, false);
if theme.busuanzi.enable
include ./busuanzi.pug
if theme.google_analytics
include ./google-analytics.pug
if theme.baidu_analytics
include ./baidu-analytics.pug
if theme.tencent_analytics
include ./tencent-analytics.pug
......@@ -5,13 +5,19 @@ script.
this.page.title = '!{ page.title }';
};
(function() {
var d = document, s = d.createElement('script');
s.src = 'https://!{ theme.disqus.shortname }.disqus.com/embed.js';
s.setAttribute('data-timestamp', '' + +new Date());
(d.head || d.body).appendChild(s);
})();
window.addEventListener('load', function () {
Stun.utils.pjaxReloadDisqus = function () {
(function(d, s) {
var d = document, s = d.createElement('script');
s.src = 'https://!{ theme.disqus.shortname }.disqus.com/embed.js';
s.setAttribute('data-timestamp', '' + +new Date());
(d.head || d.body).appendChild(s);
})(document, 'script');
};
// Initialization
Stun.utils.pjaxReloadDisqus();
}, false);
if theme.disqus.count
script#dsq-count-scr(
src='https://' + theme.disqus.shortname + '.disqus.com/count.js' async)
script(async src='https://' + theme.disqus.shortname + '.disqus.com/count.js')#dsq-count-scr
......@@ -14,15 +14,20 @@ script(src=gitalk_md5)
script.
window.addEventListener('load', function () {
var gitalk = new Gitalk({
id: md5('!{ page.path }'),
clientID: '!{ theme.gitalk.client_id }',
clientSecret: '!{ theme.gitalk.client_secret }',
repo: '!{ theme.gitalk.repo }',
owner: '!{ theme.gitalk.owner }',
admin: ['!{ theme.gitalk.admin }'],
distractionFreeMode: '!{ theme.gitalk.distraction_free_mode }',
language: '!{ lang }'
});
gitalk.render('gitalk-container');
Stun.utils.pjaxReloadGitalk = function () {
var gitalk = new Gitalk({
id: md5('!{ page.path }'),
clientID: '!{ theme.gitalk.client_id }',
clientSecret: '!{ theme.gitalk.client_secret }',
repo: '!{ theme.gitalk.repo }',
owner: '!{ theme.gitalk.owner }',
admin: ['!{ theme.gitalk.admin }'],
distractionFreeMode: '!{ theme.gitalk.distraction_free_mode }',
language: '!{ lang }'
});
gitalk.render('gitalk-container');
};
// Initialization
Stun.utils.pjaxReloadGitalk();
}, false);
script.
window.addEventListener('load', function () {
(function(d, s) {
var j, e = d.getElementsByTagName(s)[0];
if (typeof LivereTower === 'function') { return; }
Stun.utils.pjaxReloadLivere = function () {
(function(d, s) {
var j, e = d.getElementsByTagName(s)[0];
if (typeof LivereTower === 'function') { return; }
j = d.createElement(s);
j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
j.async = true;
e.parentNode.insertBefore(j, e);
})(document, 'script');
j = d.createElement(s);
j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
j.async = true;
e.parentNode.insertBefore(j, e);
})(document, 'script');
};
// Initialization
Stun.utils.pjaxReloadLivere();
}, false);
......@@ -10,25 +10,30 @@ script(src=valine_js)
script.
window.addEventListener('load', function () {
var GUEST_INFO = ['nick', 'mail', 'link'];
var guest_info = '!{ theme.valine.meta }';
Stun.utils.pjaxReloadValine = function () {
var GUEST_INFO = ['nick', 'mail', 'link'];
var guest_info = '!{ theme.valine.meta }';
guest_info = guest_info.split(',').filter(function(item) {
return GUEST_INFO.indexOf(item) > -1;
});
guest_info = guest_info.split(',').filter(function(item) {
return GUEST_INFO.indexOf(item) > -1;
});
new Valine({
el: '#comments',
appId: '!{ theme.valine.appid }',
appKey: '!{ theme.valine.appkey }',
notify: !{ theme.valine.notify },
verify: !{ theme.valine.verify },
placeholder: '!{ theme.valine.placeholder }',
avatar: '!{ theme.valine.avatar }',
meta: guest_info,
pageSize: '!{ theme.valine.pageSize }' || 10,
visitor: !{ theme.valine.visitor },
recordIP: !{ theme.valine.recordIP },
lang: '!{ theme.valine.language }' || 'zh-cn'
});
new Valine({
el: '#comments',
appId: '!{ theme.valine.appid }',
appKey: '!{ theme.valine.appkey }',
notify: !{ theme.valine.notify },
verify: !{ theme.valine.verify },
placeholder: '!{ theme.valine.placeholder }',
avatar: '!{ theme.valine.avatar }',
meta: guest_info,
pageSize: '!{ theme.valine.pageSize }' || 10,
visitor: !{ theme.valine.visitor },
recordIP: !{ theme.valine.recordIP },
lang: '!{ theme.valine.language }' || 'zh-cn'
});
};
// Initialization
Stun.utils.pjaxReloadValine();
}, false);
......@@ -8,7 +8,7 @@ if theme.math.enable
- })
if !is_tag() && !is_category() && !is_archive()
if isHomeHasMath || (theme.math.per_page || page.math)
if theme.pjax.enable || isHomeHasMath || (theme.math.per_page || page.math)
if theme.math.engine === "mathjax"
include ./mathjax.pug
else if theme.math.engine === "katex"
......
if theme.math.katex.copy_tex.enable
if theme.math.katex.copy_tex.copy_tex_js
script(async src=theme.math.katex.copy_tex.copy_tex_js)
script.
window.addEventListener('load', function () {
Stun.utils.pjaxReloadCopyKatex = function () {
(function(d, s) {
var d = document, s = d.createElement('script');
s.src = '!{ theme.math.katex.copy_tex.copy_tex_js }';
s.setAttribute('async', '');
(d.head || d.body).appendChild(s);
})(document, 'script');
};
// Initialization
Stun.utils.pjaxReloadCopyKatex();
}, false);
......@@ -8,7 +8,7 @@ if theme.math.enable
- })
if !is_tag() && !is_category() && !is_archive()
if isHomeHasMath || (theme.math.per_page || page.math)
if theme.pjax.enable || isHomeHasMath || (theme.math.per_page || page.math)
if theme.math.engine === "katex"
link(href=theme.math.katex.cdn rel="stylesheet" type="text/css")
......
script(type="text/x-mathjax-config").
var mathjaxMhchem = '';
if (!!'!{theme.math.mathjax.mhchem}') {
mathjaxMhchem = '!{theme.math.mathjax.mhchem}'
if (!{ theme.math.mathjax.mhchem.enable }) {
mathjaxMhchem = '!{ theme.math.mathjax.mhchem.mhchem_js }';
MathJax.Ajax.config.path['mhchem'] = mathjaxMhchem;
}
......@@ -24,13 +24,12 @@ script(type="text/x-mathjax-config").
MathJax.InputJax.TeX.prefilterHooks.Add(function(data) {
if (data.display) {
var next = data.script.nextSibling;
while (next && next.nodeName.toLowerCase() === '#text') { next = next.nextSibling }
if (next && next.nodeName.toLowerCase() === 'br') { next.parentNode.removeChild(next) }
while (next && next.nodeName.toLowerCase() === '#text') { next = next.nextSibling; }
if (next && next.nodeName.toLowerCase() === 'br') { next.parentNode.removeChild(next); }
}
});
});
script(type="text/x-mathjax-config").
MathJax.Hub.Queue(function() {
var all = MathJax.Hub.getAllJax(), i;
for (i = 0; i < all.length; i++) {
......@@ -38,4 +37,4 @@ script(type="text/x-mathjax-config").
}
});
script(src=theme.math.mathjax.cdn async)
script(async src=theme.math.mathjax.cdn)
......@@ -32,6 +32,28 @@
pjaxArgs = JSON.stringify(pjaxArgs)
var enabledCommentName = '';
var isEnableComment = false;
if (page.comments) {
if (theme.gitment && theme.gitment.enable) {
isEnableComment = true;
enabledCommentName = 'Gitment';
} else if (theme.gitalk && theme.gitalk.enable) {
isEnableComment = true;
enabledCommentName = 'Gitalk';
} else if (theme.livere && theme.livere.enable) {
isEnableComment = true;
enabledCommentName = 'Livere';
} else if (theme.disqus && theme.disqus.enable) {
isEnableComment = true;
enabledCommentName = 'Disqus';
} else if (theme.valine && theme.valine.enable) {
isEnableComment = true;
enabledCommentName = 'Valine';
}
}
if theme.pjax && theme.pjax.enable
- var pjax_js = "https://cdn.jsdelivr.net/npm/pjax@latest/pjax.min.js"
- if (theme.cdn.pjax) pjax_js = theme.cdn.pjax
......@@ -44,9 +66,13 @@ script.
var pjax = new Pjax(!{ pjaxArgs });
// 加载进度条的计时器
var loadingTimer = null;
// 是否第一次加载 pjax
var isFirstLoad = true;
// 重置页面 Y 方向上的滚动偏移量
document.addEventListener('pjax:send', function () {
isFirstLoad = false;
$('html').velocity('scroll', {
duration: 500,
offset: $('#header').height(),
......@@ -84,5 +110,21 @@ script.
Stun.utils.pjaxReloadBoot();
Stun.utils.pjaxReloadScroll();
Stun.utils.pjaxReloadSidebar();
// 重载评论
if (!{ isEnableComment }) {
var reloadFnName = 'pjaxReload' + '!{ enabledCommentName }';
var comment = Stun.utils[reloadFnName];
comment && comment();
}
// 重载 KaTex(只有当第一次加载 pjax 才重载)
if (isFirstLoad) {
Stun.utils.pjaxReloadCopyKatex();
}
// 重载 busuanzi
Stun.utils.pjaxReloadBusuanzi();
}, false);
}, false);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册