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

refactor: Finish refactor

上级 f674618d
......@@ -492,7 +492,7 @@ algolia_search:
# Local Search
# See: https://github.com/wzpan/hexo-generator-search/
local_search:
enable: false
enable: true
# ---------------------------------------------------------------
# Background config
......
-
var pjax = false;
var dataPjax = {};
if (theme.pjax && theme.pjax.enable) {
pjax = true;
dataPjax = { 'data-pjax': '' };
}
doctype html
html(lang=config.language)
head
......@@ -14,13 +23,13 @@ html(lang=config.language)
div.content-inner(class=`${is_home() ? 'content-home' : ''}`)
block content
if page.comments
include ./_partials/widgets/comments.pug
aside#sidebar.sidebar
div.sidebar-inner
!= partial('./_partials/sidebar/sidebar.pug', null, { cache: theme.cache })
if page.comments
include ./_partials/widgets/comments.pug
div.clearfix
footer#footer.footer
......@@ -42,9 +51,11 @@ html(lang=config.language)
div#pjax-reload
include ./_third-party/math/index.pug
include ./_third-party/quicklink.pug
include ./_third-party/analytics/busuanzi.pug
else
include ./_third-party/math/index.pug
include ./_third-party/quicklink.pug
include ./_third-party/analytics/busuanzi.pug
include ./_third-party/comments/index.pug
include ./_third-party/advertising/index.pug
......
......@@ -40,7 +40,7 @@ if footerPowered || footerTheme
if footer.theme.version
span= " v" + stun_env("version") + "."
if theme.busuanzi.enable
if theme.busuanzi && theme.busuanzi.enable
include ../analytics/busuanzi.pug
if footer.custom.enable
......
......@@ -89,5 +89,5 @@ if theme.reading_progress.enable && is_post()
div.sidebar-reading
div.sidebar-reading-info
span= __("sidebar.read_info") + " "
span.sidebar-reading-info-num
span.sidebar-reading-info-num= "0"
div.sidebar-reading-line
script(src=theme.google_adsense.js_src async data-pjax)
script(data-pjax).
script(src=theme.google_adsense.js_src async='')&attributes(dataPjax)
script&attributes(dataPjax).
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: '!{ theme.google_adsense.client }',
enable_page_level_ads: !{ theme.google_adsense.enable_page_level_ads }
......
......@@ -4,7 +4,9 @@ script.
var hm = document.createElement('script');
hm.src = 'https://hm.baidu.com/hm.js?!{ theme.baidu_analytics }';
hm.async = true;
hm.setAttribute('data-pjax', '');
if (!{ theme.pjax.enable }) { hm.setAttribute('data-pjax', ''); }
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(hm, s);
})();
......@@ -2,4 +2,4 @@ if theme.busuanzi.enable && (theme.busuanzi.site_uv.enable || theme.busuanzi.sit
- 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(src=busuanzi_js async data-pjax)
script(src=busuanzi_js async)
script(src=`https://www.googletagmanager.com/gtag/js?id=${theme.google_analytics}` async data-pjax)
script(data-pjax).
-
var scriptSrc = `https://www.googletagmanager.com/gtag/js?id=${theme.google_analytics}`;
var dataPjax = {};
if (theme.pjax && theme.pjax.enable) {
dataPjax = { 'data-pjax': '' };
}
script(src=scriptSrc async='')&attributes(dataPjax)
script&attributes(dataPjax).
if (window.location.hostname !== 'localhost') {
window.dataLayer = window.dataLayer || [];
function gtag(){ dataLayer.push(arguments); }
......
......@@ -3,7 +3,9 @@ script.
var hm = document.createElement('script');
hm.src = 'https://tajs.qq.com/stats?sId=!{ theme.tencent_analytics }';
hm.async = true;
hm.setAttribute('data-pjax', '');
if (!{ theme.pjax.enable }) { hm.setAttribute('data-pjax', ''); }
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(hm, s);
})();
script(data-pjax).
script&attributes(dataPjax).
function loadDisqus () {
if (!document.getElementById('disqus_thread')) return;
if (window.DISQUS) {
......@@ -19,7 +19,7 @@ script(data-pjax).
sc.src = 'https://!{ theme.disqus.shortname }.disqus.com/count.js';
sc.id = 'dsq-count-scr';
sc.async = true;
sc.setAttribute('data-pjax', '');
if (!{ pjax }) { sc.setAttribute('data-pjax', ''); }
(d.head || d.body).appendChild(sc);
}
......@@ -28,7 +28,7 @@ script(data-pjax).
}
}
if (!{ theme.pjax.enable }) {
if (!{ pjax }) {
loadDisqus();
} else {
window.addEventListener('DOMContentLoaded', loadDisqus, false);
......
......@@ -5,14 +5,14 @@
if (theme.cdn.gitalk_js) gitalk_js = theme.cdn.gitalk_js
if (theme.cdn.gitalk_md5) gitalk_md5 = theme.cdn.gitalk_md5
script(src=gitalk_js data-pjax)
script(src=gitalk_md5 data-pjax)
script(src=gitalk_js)&attributes(dataPjax)
script(src=gitalk_md5)&attributes(dataPjax)
-
var lang = _.get(theme, "gitalk.language")
? theme.gitalk.language : config.language;
script(data-pjax).
script&attributes(dataPjax).
function loadGitalk () {
if (!document.getElementById('gitalk-container')) return;
......@@ -30,7 +30,7 @@ script(data-pjax).
gitalk.render('gitalk-container');
}
if (!{ theme.pjax.enable }) {
if (!{ pjax }) {
loadGitalk();
} else {
window.addEventListener('DOMContentLoaded', loadGitalk, false);
......
script(data-pjax).
script&attributes(dataPjax).
function loadLivere () {
var d = document, s = d.createElement('script');
......@@ -6,11 +6,11 @@ script(data-pjax).
if (typeof LivereTower === 'function') return;
s.src = 'https://cdn-city.livere.com/js/embed.dist.js';
s.setAttribute('data-pjax-rm', '');
if (!{ pjax }) { s.setAttribute('data-pjax-rm', ''); }
(d.head || d.body).appendChild(s);
}
if (!{ theme.pjax.enable }) {
if (!{ pjax }) {
loadLivere();
} else {
window.addEventListener('DOMContentLoaded', loadLivere, false);
......
......@@ -8,7 +8,7 @@
script(src=leancloud_storage_js)
script(src=valine_js)
script(data-pjax).
script&attributes(dataPjax).
function loadValine () {
var GUEST_INFO = ['nick', 'mail', 'link'];
var guest_info = '!{ theme.valine.meta }';
......@@ -33,7 +33,7 @@ script(data-pjax).
});
}
if (!{ theme.pjax.enable }) {
if (!{ pjax }) {
loadValine();
} else {
window.addEventListener('DOMContentLoaded', loadValine, false);
......
......@@ -7,8 +7,8 @@ if theme.math.enable
- isHomeHasMath = true
- })
if theme.pjax.enable || (!is_tag() && !is_category() && !is_archive())
if theme.pjax.enable || isHomeHasMath || (theme.math.per_page || page.math)
if pjax || (!is_tag() && !is_category() && !is_archive())
if pjax || isHomeHasMath || (theme.math.per_page || page.math)
if theme.math.engine === "mathjax"
include ./mathjax.pug
else if theme.math.engine === "katex"
......
......@@ -43,13 +43,9 @@ 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(),
......
......@@ -10,6 +10,9 @@ if theme.quicklink.enable
if is_archive() && theme.quicklink.archive
- loadQuicklink = true
if theme.pjax.enable
- loadQuicklink = true
if loadQuicklink || ((page && page.quicklink) || (post && post.quicklink))
script(src=quicklink_js)
script.
......@@ -21,8 +24,8 @@ if theme.quicklink.enable
});
}
if (!{ theme.quicklink.delay }) {
window.addEventListener('DOMContentLoaded', initQuicklink, false);
} else {
if (!{ pjax } || !{ !theme.quicklink.delay }) {
initQuicklink();
} else {
window.addEventListener('DOMContentLoaded', initQuicklink, false);
}
// $content-width: A calc value.
// $main-width: A calc value.
// -----------------------------------------
@media (min-width: $content-width + $content-aside-gap * 2) {
@media (min-width: $main-width + $content-aside-gap * 2) {
.header-nav-inner {
width: $content-width;
width: $main-width;
}
.main-inner {
width: $content-width;
width: $main-width;
}
}
......
......@@ -36,10 +36,10 @@ $lg-width = 1200px - 0.02px
// Width
$sidebar-width = convert(hexo-config('sidebar.width') || '260px')
$main-width = $md-width
$main-sidebar-gap = 30px
$content-aside-gap = 20px
$content-width = $main-width + $sidebar-width + $main-sidebar-gap
$content-width = $md-width
$main-sidebar-gap = 30px
$main-width = $content-width + $sidebar-width + $main-sidebar-gap
// -------------------------------------------
// Font, line-height
......
$(document).ready(function () {
var tocDepth = CONFIG.sidebar.renderTocDepth;
// Optimize selector by theme config.
var HEADING_SELECTOR = 'h1,h2,h3,h4,h5,h6,'.slice(0, tocDepth * 3).slice(0, -1);
// The heading that reached the top currently.
var currHeading = null;
// The heading that reached the top last time.
var lastHeading = null;
var isRemoveTocClass = false;
var tocDepth = CONFIG.sidebar.renderTocDepth;
// Optimize selector by theme config.
var HEADING_SELECTOR = 'h1,h2,h3,h4,h5,h6,'.slice(0, tocDepth * 3).slice(0, -1);
var $postBody = $('.post-body');
var $allTocItem = $('.sidebar-toc li');
// Automatically expand items in the article directory
// based on the scrolling of heading in the article.
function autoSpreadToc () {
var $postBody = $('.post-body');
var $allTocItem = $('.sidebar-toc li');
var $headings = $postBody.find(HEADING_SELECTOR);
var $firsetChild = $headings.first();
......@@ -33,8 +33,6 @@ $(document).ready(function () {
}
return;
} else {
isRemoveTocClass = false;
}
if (currHeading !== lastHeading) {
......@@ -140,7 +138,7 @@ $(document).ready(function () {
var $navOv = $('.sidebar-nav-ov');
var $tocWrap = $('.sidebar-toc');
var $overview = $('.sidebar-ov');
$navToc.on('click', function () {
if ($(this).hasClass('current')) return;
......
......@@ -235,13 +235,16 @@ Stun.utils = Stun.$u = {
var gConfig = CONFIG.gallery_waterfall;
var colWidth = parseInt(gConfig.col_width);
var colGapX = parseInt(gConfig.gap_x);
$('.gallery').masonry({
itemSelector: '.gallery__img',
columnWidth: colWidth,
percentPosition: true,
gutter: colGapX,
transitionDuration: 0
var GALLERY_IMG_SELECTOR = '.gallery__img';
this.waitAllImageLoad(GALLERY_IMG_SELECTOR, function () {
$('.gallery').masonry({
itemSelector: GALLERY_IMG_SELECTOR,
columnWidth: colWidth,
percentPosition: true,
gutter: colGapX,
transitionDuration: 0
});
});
},
// Lazy load the images of post.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册