枋柚梓 4 years ago
parent 1d9ffe580d
commit 923ae1a61b
  1. 8
      _config.yml
  2. 2
      layout/_meta/author.ejs
  3. 15
      layout/_meta/valinecount.ejs
  4. 8
      layout/_partial/article.ejs
  5. 31
      layout/_partial/cover.ejs
  6. 1
      layout/_partial/footer.ejs
  7. 17
      layout/_partial/head.ejs
  8. 4
      layout/_partial/header.ejs
  9. 282
      layout/_partial/scripts.ejs
  10. 101
      layout/_third-party/clipboard.ejs
  11. 2
      layout/_third-party/fancybox.ejs
  12. 78
      layout/_third-party/pjaxdata.ejs
  13. 9
      layout/layout.ejs
  14. 1
      layout/links.ejs
  15. 1
      source/css/_highlight/index.styl
  16. 12
      source/css/_layout/navbar.styl
  17. 2
      source/css/_layout/sidebar.styl
  18. 203
      source/js/app.js
  19. 34
      source/js/search.js

@ -211,6 +211,10 @@ meta:
# 文章浏览计数
counter:
icon: fas fa-eye
# 文章评论数量:只支持 valine
valinecount:
icon: fal fa-comment-lines
desc: '条评论'
# 文章字数和阅读时长
wordcount:
icon_wordcount: fas fa-keyboard
@ -487,7 +491,7 @@ comments:
valine:
appId: dogUA2FSKGTo029M1SEwGROT-MdYXbMMI # your appId
appKey: u0NdtQ8nvHoMdJPSYqm1LRxE # your appKey
js: https://cdn.jsdelivr.net/npm/valine@1.4/dist/Valine.min.js
js:
path: # All pages use the same path (share the same comments data)
meta: nick,mail,link # valine comment header info
requiredFields: ['nick','mail']
@ -574,7 +578,7 @@ comments:
search:
enable: true
service: hexo # hexo, google, algolia, azure, baidu
js: https://cdn.jsdelivr.net/gh/xaoxuu/cdn-volantis@2.6.5/js/search.js
# js: https://cdn.jsdelivr.net/gh/xaoxuu/cdn-volantis@2.6.4/js/search.js
google:
apiKey:
engineId:

@ -5,7 +5,7 @@ if (post.author == undefined) {
%>
<div class='new-meta-item author'>
<a href="<%- post.author.url %>" rel="nofollow">
<img src="<%- post.author.avatar %>">
<img no-lazy src="<%- post.author.avatar %>">
<p><%- post.author.name %></p>
</a>
</div>

@ -0,0 +1,15 @@
<% if (theme.comments.valine && theme.comments.valine.appId){ %>
<div class="new-meta-item comments-count">
<%
var path = post.path || page.path;
if (path.length > 9 && (path.substring(path.length - 10) == 'index.html')) {
path = path.substring(0, path.length - 10);
}
%>
<a href="<%- url_for(path) %>#comments">
<i class="<%- theme.meta.valinecount.icon %> fa-fw"></i>
<span class="valine-comment-count" data-xid="<%- url_for(path) %>">0</span>
<span class="leancloud-comments-count">&nbsp;<%- theme.meta.valinecount.desc %></span>
</a>
</div>
<% } %>

@ -58,11 +58,3 @@
<%- partial('../_third-party/mathjax') %>
<% } %>
<% if (page.layout == 'post' && page.title){ %>
<script>
window.subData = {
title: '<%- post.title %>',
tools: true
}
</script>
<% } %>

@ -1,17 +1,18 @@
<% if (page.cover == true) { %>
<div class="cover-wrapper">
<% if (is_home() && page.prev == 0 && theme.cover.scheme == 'docs') { %>
<cover class='cover <%- page.layout %> full'>
<%- partial('../_cover/index') %>
<div class="scroll-down"><i class="fa fa-chevron-down scroll-down-effects"></i></div>
</cover>
<% } else { %>
<cover class='cover <%- page.layout %> half'>
<%- partial('../_cover/index') %>
</cover>
<% } %>
<%- partial('header', null, {cache: false, path: path}) %>
</div>
<% } else { %>
<%
var enableCover = false; // 封面是否开启
if(theme.cover && theme.cover.scheme) {
enableCover = true;
}
%>
<% if (enableCover) { %>
<div class="cover-wrapper">
<cover class='cover <%- page.layout %>' style="display: none;">
<%- partial('../_cover/index') %>
<div class="scroll-down" style="display: none;"><i class="fa fa-chevron-down scroll-down-effects"></i></div>
</cover>
<%- partial('header', null, {cache: false, path: path}) %>
</div>
<% } else { %>
<%- partial('header', null, {cache: false, path: path}) %>
<% } %>

@ -46,4 +46,3 @@
<% }) %>
</footer>
<% } %>
<script>setLoadingBarProgress(80);</script>

@ -62,12 +62,17 @@
}
}
%>
<title><% if (title) { %><%= title %> - <% } %><%= config.title %></title>
<title><% if (title) { %><%= title %> - <% } %><%= config.title %></title>
<% if (keywords){ %>
<meta name="keywords" content="<%- keywords %>">
<% } else { %>
<meta name="keywords" content="<%- config.keywords || '' %>">
<% } %>
<% if (description){ %>
<meta name="description" content="<%- description %>">
<% } else { %>
<meta name="description" content="<%- config.description || '' %>">
<% } %>
<!-- feed -->
@ -85,13 +90,13 @@
<!-- link -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.13/css/all.min.css">
<%- css('https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css') %>
<% if (theme.plugins.nodewaves && theme.plugins.nodewaves.css) { %>
<%- css(theme.plugins.nodewaves.css) %>
<% } %>
<% if (config.favicon) { %>
<link rel="shortcut icon" type='image/x-icon' href="<%- url_for(config.favicon) %>">
<link rel="shortcut icon" type='image/x-icon' href="<%- url_for(config.favicon) %>">
<% } %>
<% if (theme.plugins.aplayer.enable) { %>
@ -119,11 +124,7 @@
<%- css('css/style.css') %>
<% } %>
<script>
function setLoadingBarProgress(num) {
document.getElementById('loading-bar').style.width=num+"%";
}
</script>
<script src="https://cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.min.js"></script>
<% if (config.google_analytics_key) { %>
<!-- Global site tag (gtag.js) - Google Analytics -->

@ -1,5 +1,5 @@
<div id="loading-bar-wrapper">
<div id="loading-bar"></div>
<script>NProgress.configure({parent:"#loading-bar-wrapper"});NProgress.start();</script>
</div>
<header class="l_header<%- page.sidebar == false ? ' no_sidebar' : '' %> <%- theme.style.navbar.effect.join(' ') %>">
<div class='container'>
@ -119,5 +119,3 @@
</div>
</div>
</header>
<script>setLoadingBarProgress(40);</script>

@ -1,4 +1,6 @@
<%- js('https://cdn.jsdelivr.net/npm/jquery@3.4/dist/jquery.min.js') %>
<%- js('https://cdn.jsdelivr.net/npm/pjax@0.2.8/pjax.min.js') %>
<% if (theme.search && theme.search.enable) { %>
<script>
<% if(theme.search.service === 'baidu') { %>
@ -20,38 +22,10 @@
if (!ROOT.endsWith('/')) ROOT += '/';
</script>
<% } %>
<% if (theme.plugins.instant_page) { %>
<script async src="<%- theme.plugins.instant_page %>" type="module" defer integrity="sha384-OeDn4XE77tdHo8pGtE1apMPmAipjoxUQ++eeJa6EtJCfHlvijigWiJpD7VDPWXV1"></script>
<% } %>
<% if (theme.plugins.scrollreveal && theme.plugins.scrollreveal.js) { %>
<script src="<%- theme.plugins.scrollreveal.js %>"></script>
<script type="text/javascript">
$(function() {
ScrollReveal().reveal('.l_main .reveal', {
distance: '<%- theme.plugins.scrollreveal.distance %>',
duration: '<%- theme.plugins.scrollreveal.duration %>',
interval: '<%- theme.plugins.scrollreveal.interval %>',
scale: '<%- theme.plugins.scrollreveal.scale %>'
});
});
</script>
<% } %>
<% if (theme.plugins.nodewaves && theme.plugins.nodewaves.js) { %>
<%- js({src: theme.plugins.nodewaves.js}) %>
<script type="text/javascript">
$(function() {
Waves.attach('.flat-btn', ['waves-button']);
Waves.attach('.float-btn', ['waves-button', 'waves-float']);
Waves.attach('.float-btn-light', ['waves-button', 'waves-float', 'waves-light']);
Waves.attach('.flat-box', ['waves-block']);
Waves.attach('.float-box', ['waves-block', 'waves-float']);
Waves.attach('.waves-image');
Waves.init();
});
</script>
<% } %>
<% if (theme.plugins.busuanzi) { %>
<script defer src="<%- theme.plugins.busuanzi %>"></script>
<script async src="<%- theme.plugins.instant_page %>" type="module" defer
integrity="sha384-OeDn4XE77tdHo8pGtE1apMPmAipjoxUQ++eeJa6EtJCfHlvijigWiJpD7VDPWXV1"></script>
<% } %>
<% if (theme.plugins.backstretch && theme.plugins.backstretch.enable && (theme.plugins.backstretch.images || page.images)) { %>
@ -105,6 +79,7 @@
<% }) %>
<% } %>
<!--PS:只对 valine 做了 Pjax 兼容-->
<%
var enableDisqus = false;
var enableLivere = false;
@ -112,7 +87,7 @@
var enableVssue = false;
var enableValine = false;
var enableMiniValine = false;
if (theme.comments && page && page.comments == true) {
if (theme.comments) {
if (theme.comments.disqus && theme.comments.disqus.shortname) {
enableDisqus = true;
}
@ -132,10 +107,8 @@
enableMiniValine = true;
}
}
if (theme.comments.valine && theme.comments.valine.appId && theme.comments.valine.visitor && (theme.layout.on_list.meta.indexOf('counter') > -1)) {
enableValine = true;
}
%>
<% if (enableDisqus){ %>
<script>
var disqus_shortname = '<%= theme.comments.disqus.shortname %>';
@ -206,7 +179,6 @@
})
</script>
<% } %>
<% if (enableValine){ %>
<% if (theme.comments.valine.js) { %>
<%- js(theme.comments.valine.js) %>
@ -214,59 +186,63 @@
<%- js(['js/valine.js']) %>
<% } %>
<script>
var GUEST_INFO = ['nick','mail','link'];
var meta = '<%= theme.comments.valine.meta %>'.split(',').filter(function(item){
return GUEST_INFO.indexOf(item) > -1
});
var REQUIRED_FIELDS = ['nick','mail','link'];
var requiredFields = '<%= theme.comments.valine.requiredFields %>'.split(',').filter(function(item){
return REQUIRED_FIELDS.indexOf(item) > -1
});
var valine = new Valine();
function emoji(path, idx, ext) {
var GUEST_INFO = ['nick', 'mail', 'link'];
var meta = '<%= theme.comments.valine.meta %>'.split(',').filter(function (item) {
return GUEST_INFO.indexOf(item) > -1
});
var REQUIRED_FIELDS = ['nick', 'mail', 'link'];
var requiredFields = '<%= theme.comments.valine.requiredFields %>'.split(',').filter(function (item) {
return REQUIRED_FIELDS.indexOf(item) > -1
});
function emoji(path, idx, ext) {
return path + "/" + path + "-" + idx + "." + ext;
}
var emojiMaps = {};
for (var i = 1; i <= 54; i++) {
emojiMaps['tieba-' + i] = emoji('tieba', i, 'png');
}
for (var i = 1; i <= 101; i++) {
emojiMaps['qq-' + i] = emoji('qq', i, 'gif');
}
for (var i = 1; i <= 116; i++) {
emojiMaps['aru-' + i] = emoji('aru', i, 'gif');
}
for (var i = 1; i <= 125; i++) {
emojiMaps['twemoji-' + i] = emoji('twemoji', i, 'png');
}
for (var i = 1; i <= 4; i++) {
emojiMaps['weibo-' + i] = emoji('weibo', i, 'png');
}
valine.init({
el: '#valine_container',
meta: meta,
<% if (page.valine && page.valine.path) { %>
path: "<%= page.valine.path %>",
<% } else if (theme.comments.valine.path) { %>
path: "<%= theme.comments.valine.path %>",
<% } %>
appId: "<%= theme.comments.valine.appId %>",
appKey: "<%= theme.comments.valine.appKey %>",
placeholder: "<%= (page.valine && page.valine.placeholder) ? page.valine.placeholder : theme.comments.valine.placeholder %>",
pageSize:'<%= theme.comments.valine.pageSize %>',
avatar:'<%= theme.comments.valine.avatar %>',
lang:'<%= theme.comments.valine.lang %>',
visitor: '<%= theme.comments.valine.visitor %>',
highlight: '<%= theme.comments.valine.highlight %>',
mathJax: '<%= theme.comments.valine.mathJax %>',
enableQQ: '<%= theme.comments.valine.enableQQ %>',
requiredFields: requiredFields,
emojiCDN: 'https://cdn.jsdelivr.net/gh/xaoxuu/cdn-assets/emoji/valine/',
emojiMaps: emojiMaps
})
}
var emojiMaps = {};
for (var i = 1; i <= 101; i++) {
emojiMaps['qq-' + i] = emoji('qq', i, 'gif');
}
for (var i = 1; i <= 4; i++) {
emojiMaps['weibo-' + i] = emoji('weibo', i, 'png');
}
function pjax_valine() {
var valinePath = $.trim($('#valine-path').text()) === "none" ?
window.location.pathname : $.trim($('#valine-path').text());
var valinePlaceholder = $.trim($('#valine-placeholder').text()) === "none" ?
"<%= theme.comments.valine.placeholder %>" : $.trim($('#valine-placeholder').text());
var ALLPATH = '<%= theme.comments.valine.path %>';
if(ALLPATH != '') valinePath = ALLPATH;
var valine = new Valine();
valine.init({
el: '#valine_container',
meta: meta,
placeholder: valinePlaceholder,
path: valinePath,
appId: "<%= theme.comments.valine.appId %>",
appKey: "<%= theme.comments.valine.appKey %>",
pageSize: '<%= theme.comments.valine.pageSize %>',
avatar: '<%= theme.comments.valine.avatar %>',
lang: '<%= theme.comments.valine.lang %>',
visitor: '<%= theme.comments.valine.visitor %>',
highlight: '<%= theme.comments.valine.highlight %>',
mathJax: '<%= theme.comments.valine.mathJax %>',
enableQQ: '<%= theme.comments.valine.enableQQ %>',
requiredFields: requiredFields,
emojiCDN: 'https://cdn.jsdelivr.net/gh/xaoxuu/cdn-assets/emoji/valine/',
emojiMaps: emojiMaps
})
}
$(function () {
pjax_valine();
});
</script>
<% } %>
<% if (enableMiniValine){ %>
<% if (theme.comments.minivaline.js) { %>
<%- js(theme.comments.minivaline.js) %>
@ -308,14 +284,68 @@
</script>
<% } %>
<!-- 复制 -->
<% if (theme.plugins.clipboard && (theme.style.body.highlight.copy_btn == true)) { %>
<%- partial('_third-party/clipboard') %>
<% } %>
<!--scrollreveal -->
<% if (theme.plugins.scrollreveal && theme.plugins.scrollreveal.js) { %>
<script src="<%- theme.plugins.scrollreveal.js %>"></script>
<script type="text/javascript">
function pjax_scrollrebeal() {
ScrollReveal().reveal('.l_main .reveal', {
distance: '<%- theme.plugins.scrollreveal.distance %>',
duration: '<%- theme.plugins.scrollreveal.duration %>',
interval: '<%- theme.plugins.scrollreveal.interval %>',
scale: '<%- theme.plugins.scrollreveal.scale %>'
});
}
$(function () {
pjax_scrollrebeal();
});
</script>
<% } %>
<!-- ******************************** -->
<!-- fancybox -->
<%- partial('_third-party/fancybox') %>
<!-- ******************************** -->
<% if (config.use_cdn && theme.info.cdn && theme.info.cdn.js) { %>
<%- js(theme.info.cdn.js) %>
<% } else { %>
<%- js(['js/app.js']) %>
<% } %>
<% if (theme.search && theme.search.enable && theme.search.js) { %>
<%- js(theme.search.js) %>
<% if (theme.search && theme.search.enable) { %>
<% if (theme.search.js) { %>
<%- js(theme.search.js) %>
<% } else { %>
<%- js(['js/search.js']) %>
<% } %>
<% } %>
<% if (theme.plugins.busuanzi) { %>
<script defer src="<%- theme.plugins.busuanzi %>" data-pjax></script>
<% } %>
<% if (theme.plugins.nodewaves && theme.plugins.nodewaves.js) { %>
<%- js({src: theme.plugins.nodewaves.js}) %>
<script type="text/javascript">
$(function () {
Waves.attach('.flat-btn', ['waves-button']);
Waves.attach('.float-btn', ['waves-button', 'waves-float']);
Waves.attach('.float-btn-light', ['waves-button', 'waves-float', 'waves-light']);
Waves.attach('.flat-box', ['waves-block']);
Waves.attach('.float-box', ['waves-block', 'waves-float']);
Waves.attach('.waves-image');
Waves.init();
});
</script>
<% } %>
<% if (theme.plugins.comment_typing) { %>
<%- js(theme.plugins.comment_typing) %>
<% } %>
@ -327,17 +357,73 @@
<% } %>
<% } %>
<!-- 复制 -->
<% if (theme.plugins.clipboard && (theme.style.body.highlight.copy_btn == true)) { %>
<%- partial('_third-party/clipboard') %>
<% } %>
<!-- fancybox -->
<%- partial('_third-party/fancybox') %>
<% if (config.import && config.import.script){ %>
<% (config.import.script||[]).forEach(function(item){ %>
<%- item %><% }) %>
<% } %>
<%- js(['js/message.js']) %>
<script>
$(document).ready(function () {
NProgress.done();
});
var pjax;
document.addEventListener('DOMContentLoaded', function () {
pjax = new Pjax({
elements: 'a[href]:not([href^="#"]):not([href="javascript:void(0)"]):not([pjax-fancybox])',
selectors: [
"title",
"meta[name=description]",
"meta[name=keywords]",
"#pjax-container"
],
cacheBust: false, // url 地址追加时间戳,用以避免浏览器缓存
timeout: '5000'
});
});
document.addEventListener('pjax:send', function () {
window.stop(); // 相当于点击了浏览器的停止按钮
window.subData = null; // 移除标题(用于一二级导航栏切换处)
$.fancybox.close(); // 关闭弹窗
$('.l_header .switcher .s-search').removeClass('active'); // 关闭移动端激活的搜索框
$('.l_header').removeClass('z_search-open'); // 关闭移动端激活的搜索框
$('.wrapper').removeClass('sub'); // 跳转页面时关闭二级导航
$(window).unbind('resize'); // 解绑
$(window).unbind('scroll'); // 解绑
$(window).unbind('click'); // 解绑
$(document).unbind('scroll'); // 解绑
NProgress.start();
});
document.addEventListener('pjax:complete', function () {
$('script[data-pjax], .pjax-reload script').each(function () {
$(this).parent().append($(this).remove());
});
try{
pjax_fancybox();
<% if (theme.plugins.scrollreveal && theme.plugins.scrollreveal.js) { %>
pjax_scrollrebeal();
<% } %>
<% if (theme.plugins.clipboard && (theme.style.body.highlight.copy_btn == true)) { %>
pjax_initCopyCode();
<% } %>
<% if (enableValine){ %>
pjax_valine();
<% } %>
} catch (e) {
console.log(e);
}
NProgress.done();
});
document.addEventListener('pjax:error', function () {
NProgress.done();
window.location.href = event.triggerElement.href;
});
</script>

@ -1,54 +1,53 @@
<script src="<%- theme.plugins.clipboard %>"></script>
<script>
function wait(callback, seconds) {
var timelag = null;
timelag = window.setTimeout(callback, seconds);
}
!function (e, t, a) {
var initCopyCode = function(){
var copyHtml = '';
copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
copyHtml += '<i class="fas fa-copy"></i><span>COPY</span>';
copyHtml += '</button>';
$(".highlight .code pre").before(copyHtml);
$(".article pre code").before(copyHtml);
var clipboard = new ClipboardJS('.btn-copy', {
target: function(trigger) {
return trigger.nextElementSibling;
}
});
clipboard.on('success', function(e) {
let $btn = $(e.trigger);
$btn.addClass('copied');
let $icon = $($btn.find('i'));
$icon.removeClass('fa-copy');
$icon.addClass('fa-check-circle');
let $span = $($btn.find('span'));
$span[0].innerText = 'COPIED';
wait(function () { // 等待两秒钟后恢复
$icon.removeClass('fa-check-circle');
$icon.addClass('fa-copy');
$span[0].innerText = 'COPY';
}, 2000);
});
clipboard.on('error', function(e) {
e.clearSelection();
let $btn = $(e.trigger);
$btn.addClass('copy-failed');
let $icon = $($btn.find('i'));
$icon.removeClass('fa-copy');
$icon.addClass('fa-times-circle');
let $span = $($btn.find('span'));
$span[0].innerText = 'COPY FAILED';
wait(function () { // 等待两秒钟后恢复
$icon.removeClass('fa-times-circle');
$icon.addClass('fa-copy');
$span[0].innerText = 'COPY';
}, 2000);
});
function wait(callback, seconds) {
var timelag = null;
timelag = window.setTimeout(callback, seconds)
}
initCopyCode();
}(window, document);
</script>
function pjax_initCopyCode() {
var copyHtml = '';
copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
copyHtml += '<i class="fas fa-copy"></i><span>COPY</span>';
copyHtml += '</button>';
$(".highlight .code pre").before(copyHtml);
$(".article pre code").before(copyHtml);
var clipboard = new ClipboardJS('.btn-copy', {
target: function (trigger) {
return trigger.nextElementSibling
}
});
clipboard.on('success', function (e) {
let $btn = $(e.trigger);
$btn.addClass('copied');
let $icon = $($btn.find('i'));
$icon.removeClass('fa-copy');
$icon.addClass('fa-check-circle');
let $span = $($btn.find('span'));
$span[0].innerText = 'COPIED';
wait(function () {
$icon.removeClass('fa-check-circle');
$icon.addClass('fa-copy');
$span[0].innerText = 'COPY'
}, 2000)
});
clipboard.on('error', function (e) {
e.clearSelection();
let $btn = $(e.trigger);
$btn.addClass('copy-failed');
let $icon = $($btn.find('i'));
$icon.removeClass('fa-copy');
$icon.addClass('fa-times-circle');
let $span = $($btn.find('span'));
$span[0].innerText = 'COPY FAILED';
wait(function () {
$icon.removeClass('fa-times-circle');
$icon.addClass('fa-copy');
$span[0].innerText = 'COPY'
}, 2000)
})
}
$(function () {
pjax_initCopyCode()
});
</script>

@ -10,7 +10,7 @@
}
$(element).attr("data-fancybox", "images");
var caption = ""; // 描述信息
if ($(this).attr('alt')) { // 标准 markdown 描述信息
if ($(this).attr('alt')) { // 判断当前页面是否存在描述信息
$(element).attr('data-caption', $(this).attr('alt'));
caption = $(this).attr('alt');
}

@ -0,0 +1,78 @@
<!--此文件用来存放一些不方便取值的变量-->
<!--思路大概是将值藏到重加载的区域内-->
<%
var changeValinePath = 'none'; // 自定义的 valine 评论路径
var changeValinePlaceholder = 'none'; // 自定义的 valine 评论描述
var ispage = false; // 一二级导航栏切换控制
var postTitle = ''; // 当前文章标题,用于二级导航栏赋值
var enableCover = false; // 封面是否开启
var frontMatterCover = 'none'; // 封面控制
var enableValine = false;
if (theme.comments && page && page.comments == true && theme.comments.valine && theme.comments.valine.appId) {
enableValine = true;
}
if (page && page.comments == true) {
if (enableValine && page.valine && page.valine.path) {
changeValinePath = page.valine.path;
}
if (enableValine && page.valine && page.valine.placeholder) {
changeValinePlaceholder = page.valine.placeholder;
}
}
if(theme.cover && theme.cover.scheme) {
enableCover = true;
}
if (enableCover && page && page.cover) {
frontMatterCover = page.cover;
if (is_home() && page.prev == 0 && theme.cover.scheme == 'docs') {
frontMatterCover = 'docs';
} else {
frontMatterCover = 'blog';
}
}
if (page && page.layout == 'post' && page.title) {
ispage = true;
postTitle = page.title;
}
%>
<div id="pjax-data" style="display: none">
<div id="pjax-ispage"><%=ispage%></div>
<div id="pjax-pageTitle"><%=postTitle%></div>
<div id="pjax-enable-cover"><%=enableCover%></div>
<% if (enableValine){ %>
<div id="valine-path"><%=changeValinePath%></div>
<div id="valine-placeholder"><%=changeValinePlaceholder%></div>
<% } %>
</div>
<% if (enableCover) { %>
<script>
// 处理封面 此时 jquery 还没加载
if("<%=frontMatterCover%>" == "none") { // 移除封面
document.getElementsByClassName('cover')[0].style.display = "none";
document.getElementsByClassName('l_body')[0].classList.add("nocover");
document.getElementsByClassName('l_header','cover-wrapper')[0].classList.add("show");
} else {
if("<%=frontMatterCover%>" == "blog") { // 半屏
document.getElementsByClassName('cover')[0].classList.remove("full");
document.getElementsByClassName('cover')[0].classList.add("half");
document.getElementsByClassName('scroll-down')[0].style.display = "none";
} else if("<%=frontMatterCover%>" == "docs") { // 全屏
document.getElementsByClassName('cover')[0].classList.remove("half");
document.getElementsByClassName('cover')[0].classList.add("full");
document.getElementsByClassName('scroll-down')[0].style.display = "";
}
document.getElementsByClassName('cover')[0].style.display = "";
document.getElementsByClassName('l_body','show')[0].classList.remove("nocover");
document.getElementsByClassName('l_header','cover-wrapper')[0].classList.remove("show");
}
</script>
<% } %>

@ -4,13 +4,14 @@
<body>
<%- partial('_partial/cover') %>
<div class="l_body<%- page.cover ? '' : ' nocover' %>">
<div class='body-wrapper'>
<div class='body-wrapper' id="pjax-container">
<%- partial('_third-party/pjaxdata') %>
<%- body %>
<script>setLoadingBarProgress(60);</script>
</div>
<a class="s-top fas fa-arrow-up fa-fw" href='javascript:void(0)'></a>
</div>
<%- partial('_partial/scripts') %>
<script>setLoadingBarProgress(100);</script>
<div>
<%- partial('_partial/scripts') %>
</div>
</body>
</html>

@ -54,6 +54,7 @@
<br><br>
<%- page.more %>
</section>
<%- partial('_partial/meta',{post:page, position:'footer'}) %>
</article>
<%- partial('_third-party/comments') %>

@ -115,6 +115,7 @@ pre
margin-left: 0
position: sticky
left: 0
z-index: 1
background-color: darken($color-codeblock, 5)
pre
color: $color-meta

@ -1,19 +1,10 @@
#loading-bar-wrapper
position: fixed
width: 100%
top: 0
left: 0
height: 2px
width: 100%
z-index: 99999
#loading-bar
position: fixed
width: 0
height: 2px
trans()
background-color: $color-theme
.l_header
$iconW = 32px
$iconMargin = 4px
@ -260,7 +251,6 @@ ul.list-v
display: block
color: mix($color-text, $color-card, 90)
font-size: $fontsize-meta
font-weight: bold
line-height: 33px
padding: 0 $gap + $border-line + 2px 0 $gap
height: 32px

@ -48,8 +48,8 @@
header
border-top-left-radius: $border-card
border-top-right-radius: $border-card
font-weight: bold
padding: "calc(%s - 2px)" % $gap
font-weight: bold
padding-bottom: 0
&,a
color: $color-theme

@ -3,12 +3,24 @@ var customSearch;
(function ($) {
"use strict";
// 校正页面定位(被导航栏挡住的区域)
var scrollCorrection = 80; // (header height = 64px) + (gap = 16px)
const $headerAnchor = $('.l_header', '.cover-wrapper');
var $headerAnchor = $('.l_header', '.cover-wrapper');
if ($headerAnchor[0]) {
scrollCorrection = $headerAnchor[0].clientHeight + 16;
}
// 尝试: 重设数据值
function restData() {
scrollCorrection = 80;
$headerAnchor = $('.l_header', '.cover-wrapper');
if ($headerAnchor[0]) {
scrollCorrection = $headerAnchor[0].clientHeight + 16;
}
}
// 校正页面定位(被导航栏挡住的区域)
function scrolltoElement(elem, correction = scrollCorrection) {
const $elem = elem.href ? $(elem.getAttribute('href')) : $(elem);
$('html, body').animate({
@ -16,19 +28,20 @@ var customSearch;
}, 500);
}
// 设置滚动锚点
function setScrollAnchor() {
// button
const $postsBtn = $('.menu .active');
const $topBtn = $('.s-top');
const $titleBtn = $('h1.title', '#header-meta');
// anchor
const $bodyAnchor = $('.l_body');
// action
const $postsBtn = $('.menu .active'); // 一级导航上的当前激活的按钮
const $topBtn = $('.s-top'); // 向上
const $titleBtn = $('h1.title', '#header-meta'); // 文章内标题
const $bodyAnchor = $('.l_body'); // 页面主体
if ($postsBtn.length && $bodyAnchor) {
$postsBtn.click(e => {
e.preventDefault();
e.stopPropagation();
scrolltoElement($bodyAnchor);
if($postsBtn.attr("href") != "/") // TODO: fix it
scrolltoElement($bodyAnchor);
e.stopImmediatePropagation();
});
}
if ($titleBtn.length && $bodyAnchor) {
@ -36,6 +49,7 @@ var customSearch;
e.preventDefault();
e.stopPropagation();
scrolltoElement($bodyAnchor);
e.stopImmediatePropagation();
});
}
if ($topBtn.length && $bodyAnchor) {
@ -43,17 +57,32 @@ var customSearch;
e.preventDefault();
e.stopPropagation();
scrolltoElement($bodyAnchor);
e.stopImmediatePropagation();
});
}
//==========================================
const $coverAnchor = $('.cover-wrapper');
var enableCover = $('#pjax-enable-cover').text(); // Pjax 处理
var showHeaderPoint = 0;
if ($coverAnchor[0]) {
showHeaderPoint = $coverAnchor[0].clientHeight - 180;
if(enableCover == "true" && $('.cover.half').css('display') !== 'none') // Pjax 处理
showHeaderPoint = $coverAnchor[0].clientHeight - 180;
}
var pos = document.body.scrollTop;
if(enableCover == "true" && $('.cover.half').css('display') === 'none')
pos += 180; // Pjax 处理
$(document, window).scroll(() => {
const scrollTop = $(window).scrollTop();
let scrollTop = $(window).scrollTop(); // 滚动条距离顶部的距离
if(enableCover == "true" && $('.cover.half').css('display') === 'none')
scrollTop += 180; // Pjax 处理
const del = scrollTop - pos;
pos = scrollTop;
if (scrollTop > 180) {
@ -72,15 +101,27 @@ var customSearch;
$headerAnchor.removeClass('show');
}
});
//==========================================
}
// 设置导航栏
function setHeader() {
var HEXO_ISPAGE = $.trim($('#pjax-ispage').text());
if(HEXO_ISPAGE == 'true')
window.subData = {
title: $.trim($('#pjax-pageTitle').text()),
tools: true
}
if (!window.subData) return;
const $wrapper = $('header .wrapper');
const $comment = $('.s-comment', $wrapper);
const $toc = $('.s-toc', $wrapper);
const $wrapper = $('header .wrapper'); // 整个导航栏
const $comment = $('.s-comment', $wrapper); // 评论按钮 桌面端 移动端
const $toc = $('.s-toc', $wrapper); // 目录按钮 仅移动端
$comment.show(); // 显示 (某些文章可能关闭了评论,故先行显示)
$wrapper.find('.nav-sub .title').text(window.subData.title); // 二级导航文章标题
$wrapper.find('.nav-sub .title').text(window.subData.title);
// 决定一二级导航栏的切换
let pos = document.body.scrollTop;
$(document, window).scroll(() => {
const scrollTop = $(window).scrollTop();
@ -90,21 +131,22 @@ var customSearch;
$wrapper.addClass('sub');
} else if (del <= -50) {
pos = scrollTop;
$wrapper.removeClass('sub');
$wrapper.removeClass('sub'); // <---- 取消二级导航显示
}
});
// bind events to every btn
const $commentTarget = $('.l_body .comments');
let $commentTarget = $('.l_body .comments'); // 评论区域
if ($commentTarget.length) {
$comment.click(e => {
$comment.click(e => { // 评论按钮点击后 跳转到评论区域
e.preventDefault();
e.stopPropagation();
scrolltoElement($commentTarget);
scrolltoElement($('.l_body .comments'));
e.stopImmediatePropagation();
});
} else $comment.remove();
} else $comment.hide(); // 关闭了评论,则隐藏
const $tocTarget = $('.l_body .toc-wrapper');
const $tocTarget = $('.l_body .toc-wrapper'); // 侧边栏的目录列表 PC
if ($tocTarget.length && $tocTarget.children().length) {
$toc.click((e) => {
e.stopPropagation();
@ -112,6 +154,7 @@ var customSearch;
$toc.toggleClass('active');
});
$(document).click(function (e) {
e.stopPropagation();
$tocTarget.removeClass('active');
$toc.removeClass('active');
});
@ -120,11 +163,9 @@ var customSearch;
$toc.removeClass('active');
});
} else $toc.remove();
}
// 设置导航栏菜单选中状态
function setHeaderMenuSelection() {
var $headerMenu = $('body .navigation');
// 先把已经激活的取消激活
@ -159,39 +200,23 @@ var customSearch;
}
}
function setHeaderMenuPhone() {
// var $switcher = $('.l_header .switcher .s-menu');
// var $menu = $('body .menu-phone');
// $switcher.click(function (e) {
// e.stopPropagation();
// $menu.toggleClass('show');
// $switcher.toggleClass('active');
// });
// $(document).click(function (e) {
// // $menu.removeClass('show');
// $switcher.removeClass('active');
// });
// $(document, window).scroll(() => {
// $menu.removeClass('show');
// $switcher.removeClass('active');
// });
}
// 设置导航栏搜索框 fix √
function setHeaderSearch() {
var $switcher = $('.l_header .switcher .s-search');
var $header = $('.l_header');
var $search = $('.l_header .m_search');
var $switcher = $('.l_header .switcher .s-search'); // 搜索按钮 移动端
var $header = $('.l_header'); // 移动端导航栏
var $search = $('.l_header .m_search'); // 搜索框 桌面端
if ($switcher.length === 0) return;
$switcher.click(function (e) {
e.stopPropagation();
$header.toggleClass('z_search-open');
$header.toggleClass('z_search-open'); // 激活移动端搜索框
$switcher.toggleClass('active'); // 搜索按钮
$search.find('input').focus();
$switcher.toggleClass('active');
});
$(document).click(function (e) {
$header.removeClass('z_search-open');
$switcher.removeClass('active');
});
$search.click(function (e) {
e.stopPropagation();
});
@ -224,12 +249,13 @@ var customSearch;
});
}
// 设置导航栏搜索框
function setTocToggle() {
const $toc = $('.toc-wrapper');
const $toc = $('.toc-wrapper'); // 侧边栏 TOC 移动端
if ($toc.length === 0) return;
$toc.click((e) => {
e.stopPropagation();
$toc.addClass('active');
e.stopPropagation();
$toc.addClass('active');
});
$(document).click(() => $toc.removeClass('active'));
@ -248,13 +274,19 @@ var customSearch;
}
});
const liElements = Array.from($toc.find('li a'));
let liElements = Array.from($toc.find('li a'));
//function animate above will convert float to int.
const getAnchor = () => liElements.map(elem => Math.floor($(elem.getAttribute('href')).offset().top - scrollCorrection));
let getAnchor = () => liElements.map(elem => Math.floor($(elem.getAttribute('href')).offset().top - scrollCorrection));
let anchor = getAnchor();
const scrollListener = () => {
const scrollTop = $('html').scrollTop() || $('body').scrollTop();
let domHeigth = $(document).height();
let scrollListener = () => {
let scrollTop = $('html').scrollTop() || $('body').scrollTop();
if ($(document).height() != domHeigth) { // dom 高度发生变化: 普遍来说,是图片懒加载造成的
scrollTop = $('html').scrollTop() || $('body').scrollTop();
domHeigth = $(document).height();
anchor = getAnchor();
}
if (!anchor) return;
//binary search.
let l = 0,
@ -267,18 +299,26 @@ var customSearch;
else r = mid - 1;
}
$(liElements).removeClass('active').eq(l).addClass('active');
}
$(window)
.resize(() => {
};
$(window).scroll(() => {
scrollListener();
});
// 监听窗口改变事件
let resizeTimer = null;
$(window).bind('resize', function (){
if (resizeTimer) clearTimeout(resizeTimer);
resizeTimer = setTimeout(function(){
anchor = getAnchor();
scrollListener();
})
.scroll(() => {
scrollListener()
});
} , 100);
});
scrollListener();
}
// 设置搜索服务
function setSearchService() {
if (SEARCH_SERVICE === 'google') {
customSearch = new GoogleCustomSearch({
@ -312,6 +352,7 @@ var customSearch;
}
}
// 设置 tabs 标签
function setTabs() {
const $tabs = $('.tabs');
if ($tabs.length === 0) return;
@ -336,19 +377,45 @@ var customSearch;
$(function () {
setHeader();
setHeaderMenuSelection();
setHeaderMenuPhone();
setHeaderSearch();
setTocToggle();
setScrollAnchor();
setSearchService();
setTabs();
// $(".article .video-container").fitVids();
// 全屏封面底部箭头
$('.scroll-down').on('click', function () {
scrolltoElement('.l_body');
});
setTimeout(function () {
$('#loading-bar-wrapper').fadeOut(500);
}, 300);
scrolltoElement('.l_body');
});
// addEventListener是先绑定先执行,此处的绑定后执行
document.addEventListener('pjax:complete', function () {
try {
$(function () {
restData();
setHeader();
setHeaderMenuSelection();
setTocToggle();
setScrollAnchor();
setTabs();
});
} catch (error) {
console.log(error);
}
});
});
})(jQuery);
/*Valine Admin*/
if(window.location.hash){
var checkExist = setInterval(function() {
if (typeof jQuery == 'undefined'){return;}
if ($("#"+window.location.hash.split("#")[1]).length) {
$('html, body').animate({scrollTop: $("#"+window.location.hash.split("#")[1]).offset().top-90}, 1000);
clearInterval(checkExist);
}
}, 100);
}

@ -122,19 +122,29 @@ var SearchService = "";
}
};
self.getUrlRelativePath = function (url) {
var arrUrl = url.split("//");
var start = arrUrl[1].indexOf("/");
var relUrl = arrUrl[1].substring(start);
if (relUrl.indexOf("?") != -1) {
relUrl = relUrl.split("?")[0];
}
return relUrl;
}
/**
* Generate html for one result
* @param url : (string) url
* @param title : (string) title
* @param digest : (string) digest
* @param index : 标号
*/
self.buildResult = function(url, title, digest, index) {
self.buildResult = function (url, title, digest) {
var result = self.getUrlRelativePath(url);
var html = "";
html = "<li>";
html += "<a class='result' href='" +url+ "'>";
html += "<span class='title'>" +title+ "</span>";
if (digest !== "") html += "<span class='digest'>" +digest+ "</span>";
html += "<a class='result search-result-fix' value='" + result + "'>";
html += "<span class='title'>" + title + "</span>";
if (digest !== "") html += "<span class='digest'>" + digest + "</span>";
html += "</a>";
html += "</li>";
return html;
@ -233,7 +243,7 @@ var SearchService = "";
self.init();
};
var template = '<div id="u-search"><div class="modal"> <header class="modal-header" class="clearfix"><form id="u-search-modal-form" class="u-search-form" name="uSearchModalForm"> <input type="text" id="u-search-modal-input" class="u-search-input" /> <button type="submit" id="u-search-modal-btn-submit" class="u-search-btn-submit"> <span class="fas fa-search"></span> </button></form> <a class="btn-close"> <span class="fas fa-times"></span> </a><div class="modal-loading"><div class="modal-loading-bar"></div></div> </header> <main class="modal-body"><ul class="modal-results modal-ajax-content"></ul> </main> <footer class="modal-footer clearfix"><div class="modal-metadata modal-ajax-content"> <strong class="range"></strong> of <strong class="total"></strong></div><div class="modal-error"></div> <div class="logo"></div> <a class="nav btn-next modal-ajax-content"> <span class="text">NEXT</span> <span class="fas fa-chevron-right"></span> </a> <a class="nav btn-prev modal-ajax-content"> <span class="fas fa-chevron-left"></span> <span class="text">PREV</span> </a> </footer></div><div class="modal-overlay"></div></div>';
var template = '<div id="u-search"><div class="modal"> <header class="modal-header" class="clearfix"><form id="u-search-modal-form" class="u-search-form" name="uSearchModalForm"> <input type="text" id="u-search-modal-input" class="u-search-input" /> <button type="submit" id="u-search-modal-btn-submit" class="u-search-btn-submit"> <span class="fal fa-search"></span> </button></form> <a class="btn-close"> <span class="fal fa-times"></span> </a><div class="modal-loading"><div class="modal-loading-bar"></div></div> </header> <main class="modal-body"><ul class="modal-results modal-ajax-content"></ul> </main> <footer class="modal-footer clearfix"><div class="modal-metadata modal-ajax-content"> <strong class="range"></strong> of <strong class="total"></strong></div><div class="modal-error"></div> <div class="logo"></div> <a class="nav btn-next modal-ajax-content"> <span class="text">NEXT</span> <span class="fal fa-chevron-right"></span> </a> <a class="nav btn-prev modal-ajax-content"> <span class="fal fa-chevron-left"></span> <span class="text">PREV</span> </a> </footer></div><div class="modal-overlay"></div></div>';
})(jQuery);
var AlgoliaSearch;
@ -265,6 +275,7 @@ var AlgoliaSearch;
var digest = "";
html += self.buildResult(url, title, digest, index+1);
});
html += "<script>$('.result.search-result-fix').click(function(event){var url = this.getAttribute('value');try{pjax.loadUrl(url)}catch(e){$(location).attr('href', url)}setTimeout(function(){$('#u-search').fadeOut(500);$('body').removeClass('modal-active');}, 300);});</script>";
return html;
};
@ -366,6 +377,7 @@ var AzureSearch;
var digest = row.excerpt || "";
html += self.buildResult(url, title, digest);
});
html += "<script>$('.result.search-result-fix').click(function(event){var url = this.getAttribute('value');try{pjax.loadUrl(url)}catch(e){$(location).attr('href', url)}setTimeout(function(){$('#u-search').fadeOut(500);$('body').removeClass('modal-active');}, 300);});</script>";
return html;
};
@ -473,6 +485,7 @@ var BaiduSearch;
if (self.contentSearch(post, queryText))
html += self.buildResult(post.linkUrl, post.title, post.abstract);
});
html += "<script>$('.result.search-result-fix').click(function(event){var url = this.getAttribute('value');try{pjax.loadUrl(url)}catch(e){$(location).attr('href', url)}setTimeout(function(){$('#u-search').fadeOut(500);$('body').removeClass('modal-active');}, 300);});</script>";
return html;
};
@ -567,6 +580,7 @@ var GoogleCustomSearch = "";
var digest = (row.htmlSnippet || "").replace('<br>','');
html += self.buildResult(url, title, digest);
});
html += "<script>$('.result.search-result-fix').click(function(event){var url = this.getAttribute('value');try{pjax.loadUrl(url)}catch(e){$(location).attr('href', url)}setTimeout(function(){$('#u-search').fadeOut(500);$('body').removeClass('modal-active');}, 300);});</script>";
return html;
};
@ -710,12 +724,12 @@ var HexoSearch;
*/
self.buildResultList = function(data, queryText) {
var results = [],
html = "";
var i = 1;
$.each(data, function(index, post) {
html = "";
$.each(data, function (index, post) {
if (self.contentSearch(post, queryText))
html += self.buildResult(post.permalink, post.title, post.digest, i++);
html += self.buildResult(post.permalink, post.title, post.digest);
});
html += "<script>$('.result.search-result-fix').click(function(event){var url = this.getAttribute('value');try{pjax.loadUrl(url)}catch(e){$(location).attr('href', url)}setTimeout(function(){$('#u-search').fadeOut(500);$('body').removeClass('modal-active');}, 300);});</script>";
return html;
};

Loading…
Cancel
Save