Merge pull request #121 from inkss/szyink-material

修改主题的搜索
i18n
Mr. X 4 years ago committed by GitHub
commit e66bf65e4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 38
      _config.yml
  2. 38
      layout/_partial/scripts.ejs
  3. 9
      source/img/algolia.svg
  4. 1
      source/img/azure.svg
  5. 1
      source/img/baidu.svg
  6. 203
      source/js/app.js
  7. 2
      source/js/commentTyping.js
  8. 47
      source/js/search.js
  9. 7
      source/less/_search.less

@ -9,7 +9,7 @@ info:
app: https://cdn.jsdelivr.net/gh/xaoxuu/cdn-material-x@20.2.8/js/app.js
search: https://cdn.jsdelivr.net/gh/xaoxuu/cdn-material-x@20.2.8/js/search.js
volantis: https://cdn.jsdelivr.net/gh/xaoxuu/volantis@1.0.6/js/volantis.min.js
commentTyping: https://cdn.jsdelivr.net/gh/inkss/inkss.github.io/js/commentTyping.js
############################### 主题风格 ###############################
@ -18,9 +18,10 @@ style: pure # pure: 导航栏和标题栏背景是白色
############################### 服务开关 ###############################
scrollreveal: true
nodewaves: true
busuanzi: true
commentTyping: true # 文本框打字机特效
scrollreveal: true # 页面滚动显示动画
nodewaves: true # 按钮点击效果
busuanzi: true # 访问量统计
# fastclick: true
@ -298,20 +299,21 @@ valine:
# 搜索配置
search:
enable: true
service: hexo
# google
google_api_key:
google_engine_id:
# algolia
algolia_app_id:
algolia_api_key:
algolia_index_name:
# azure
azure_service_name:
azure_index_name:
azure_query_key:
# baidu
baidu_api_id:
service: hexo # 类型:google, algolia, azure, baidu 默认 hexo
# 选择你选取的搜索服务后,复制相应的配置到根目录配置文件中
# google:
# apiKey:
# engineId:
# algolia:
# applicationID:
# apiKey:
# indexName:
# azure:
# serviceName:
# indexName:
# queryKey:
# baidu:
# apiId:
# Less渲染
less:

@ -1,24 +1,29 @@
<script src="https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js"></script>
<% if (theme.search && theme.search.enable) { %>
<script>
var GOOGLE_CUSTOM_SEARCH_API_KEY = "<%- theme.search.google_api_key %>";
var GOOGLE_CUSTOM_SEARCH_ENGINE_ID = "<%- theme.search.google_engine_id %>";
var ALGOLIA_API_KEY = "<%- theme.search.algolia_api_key %>";
var ALGOLIA_APP_ID = "<%- theme.search.algolia_app_id %>";
var ALGOLIA_INDEX_NAME = "<%- theme.search.algolia_index_name %>";
var AZURE_SERVICE_NAME = "<%- theme.search.azure_service_name %>";
var AZURE_INDEX_NAME = "<%- theme.search.azure_index_name %>";
var AZURE_QUERY_KEY = "<%- theme.search.azure_query_key %>";
var BAIDU_API_ID = "<%- theme.search.baidu_api_id %>";
<% if(theme.search.service === 'baidu') { %>
var BAIDU_API_ID = "<%- config.baidu.apiId %>";
<%} else if(theme.search.service === 'algolia') { %>
var ALGOLIA_API_KEY = "<%- config.algolia.apiKey %>";
var ALGOLIA_APP_ID = "<%- config.algolia.applicationID %>";
var ALGOLIA_INDEX_NAME = "<%- config.algolia.indexName %>";
<%} else if(theme.search.service === 'azure') { %>
var AZURE_QUERY_KEY = "<%- config.azure.queryKey %>";
var AZURE_INDEX_NAME = "<%- config.azure.indexName %>";
var AZURE_SERVICE_NAME = "<%- config.azure.serviceName %>";
<%} else if(theme.search.service === 'google') { %>
var GOOGLE_CUSTOM_SEARCH_API_KEY = "<%- config.google.apiKey %>";
var GOOGLE_CUSTOM_SEARCH_ENGINE_ID = "<%- config.google.engineId %>";
<%}%>
var SEARCH_SERVICE = "<%- theme.search.service%>" || "hexo";
var ROOT = "<%- config.root %>"||"/";
if(!ROOT.endsWith('/'))ROOT += '/';
var ROOT = "<%- config.root %>" || "/";
if (!ROOT.endsWith('/')) ROOT += '/';
</script>
<% } %>
<script src="//instant.page/1.2.2" type="module" integrity="sha384-2xV8M5griQmzyiY3CDqh1dn4z3llDVqZDqzjzcY+jCBCk/a5fXJmuZ/40JJAPeoU"></script>
<% if (theme.scrollreveal == true) { %>
<script async src="https://cdn.jsdelivr.net/npm/scrollreveal@4.0.5/dist/scrollreveal.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/scrollreveal@4.0.5/dist/scrollreveal.min.js"></script>
<script type="text/javascript">
$(function() {
const $reveal = $('.reveal');
@ -203,6 +208,15 @@
<% } else { %>
<%- js(['js/search.js']) %>
<% } %>
<% if (config.use_cdn && theme.info && theme.info.cdn && theme.info.cdn.js && theme.info.cdn.js.commentTyping) { %>
<% if (theme.commentTyping == true) { %>
<%- js(theme.info.cdn.js.commentTyping) %>
<%}%>
<% } else { %>
<% if (theme.commentTyping == true) { %>
<%- js(['js/commentTyping.js']) %>
<%}%>
<% } %>
<% if (page.layout == 'links') { %>
<%- js('https://cdn.jsdelivr.net/gh/toddmotto/echo@1.7.3/src/echo.js') %>

@ -0,0 +1,9 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1366 362">
<linearGradient id="a" x1="428.258" x2="434.145" y1="404.15" y2="409.85" gradientUnits="userSpaceOnUse" gradientTransform="matrix(94.045 0 0 -94.072 -40381.527 38479.52)">
<stop offset="0" stop-color="#00aeff"/>
<stop offset="1" stop-color="#3369e7"/>
</linearGradient>
<path fill="url(#a)" d="M61.8 15.4h242.8c23.9 0 43.4 19.4 43.4 43.4v242.9c0 23.9-19.4 43.4-43.4 43.4H61.8c-23.9 0-43.4-19.4-43.4-43.4v-243c0-23.9 19.4-43.3 43.4-43.3z"/>
<path fill="#FFF" d="M187 98.7c-51.4 0-93.1 41.7-93.1 93.2S135.6 285 187 285s93.1-41.7 93.1-93.2-41.6-93.1-93.1-93.1zm0 158.8c-36.2 0-65.6-29.4-65.6-65.6s29.4-65.6 65.6-65.6 65.6 29.4 65.6 65.6-29.3 65.6-65.6 65.6zm0-117.8v48.9c0 1.4 1.5 2.4 2.8 1.7l43.4-22.5c1-.5 1.3-1.7.8-2.7-9-15.8-25.7-26.6-45-27.3-1 0-2 .8-2 1.9zm-60.8-35.9l-5.7-5.7c-5.6-5.6-14.6-5.6-20.2 0l-6.8 6.8c-5.6 5.6-5.6 14.6 0 20.2l5.6 5.6c.9.9 2.2.7 3-.2 3.3-4.5 6.9-8.8 10.9-12.8 4.1-4.1 8.3-7.7 12.9-11 1-.6 1.1-2 .3-2.9zM217.5 89V77.7c0-7.9-6.4-14.3-14.3-14.3h-33.3c-7.9 0-14.3 6.4-14.3 14.3v11.6c0 1.3 1.2 2.2 2.5 1.9 9.3-2.7 19.1-4.1 29-4.1 9.5 0 18.9 1.3 28 3.8 1.2.3 2.4-.6 2.4-1.9z"/>
<path fill="#182359" d="M842.5 267.6c0 26.7-6.8 46.2-20.5 58.6-13.7 12.4-34.6 18.6-62.8 18.6-10.3 0-31.7-2-48.8-5.8l6.3-31c14.3 3 33.2 3.8 43.1 3.8 15.7 0 26.9-3.2 33.6-9.6s10-15.9 10-28.5v-6.4c-3.9 1.9-9 3.8-15.3 5.8-6.3 1.9-13.6 2.9-21.8 2.9-10.8 0-20.6-1.7-29.5-5.1-8.9-3.4-16.6-8.4-22.9-15-6.3-6.6-11.3-14.9-14.8-24.8s-5.3-27.6-5.3-40.6c0-12.2 1.9-27.5 5.6-37.7 3.8-10.2 9.2-19 16.5-26.3 7.2-7.3 16-12.9 26.3-17s22.4-6.7 35.5-6.7c12.7 0 24.4 1.6 35.8 3.5 11.4 1.9 21.1 3.9 29 6.1v155.2zm-108.7-77.2c0 16.4 3.6 34.6 10.8 42.2 7.2 7.6 16.5 11.4 27.9 11.4 6.2 0 12.1-.9 17.6-2.6 5.5-1.7 9.9-3.7 13.4-6.1v-97.1c-2.8-.6-14.5-3-25.8-3.3-14.2-.4-25 5.4-32.6 14.7-7.5 9.3-11.3 25.6-11.3 40.8zm294.3 0c0 13.2-1.9 23.2-5.8 34.1s-9.4 20.2-16.5 27.9c-7.1 7.7-15.6 13.7-25.6 17.9s-25.4 6.6-33.1 6.6c-7.7-.1-23-2.3-32.9-6.6-9.9-4.3-18.4-10.2-25.5-17.9-7.1-7.7-12.6-17-16.6-27.9s-6-20.9-6-34.1c0-13.2 1.8-25.9 5.8-36.7 4-10.8 9.6-20 16.8-27.7s15.8-13.6 25.6-17.8c9.9-4.2 20.8-6.2 32.6-6.2s22.7 2.1 32.7 6.2c10 4.2 18.6 10.1 25.6 17.8 7.1 7.7 12.6 16.9 16.6 27.7 4.2 10.8 6.3 23.5 6.3 36.7zm-40 .1c0-16.9-3.7-31-10.9-40.8-7.2-9.9-17.3-14.8-30.2-14.8-12.9 0-23 4.9-30.2 14.8-7.2 9.9-10.7 23.9-10.7 40.8 0 17.1 3.6 28.6 10.8 38.5 7.2 10 17.3 14.9 30.2 14.9 12.9 0 23-5 30.2-14.9 7.2-10 10.8-21.4 10.8-38.5zm127.1 86.4c-64.1.3-64.1-51.8-64.1-60.1L1051 32l39.1-6.2v183.6c0 4.7 0 34.5 25.1 34.6v32.9zm68.9 0h-39.3V108.1l39.3-6.2v175zm-19.7-193.5c13.1 0 23.8-10.6 23.8-23.7S1177.6 36 1164.4 36s-23.8 10.6-23.8 23.7 10.7 23.7 23.8 23.7zm117.4 18.6c12.9 0 23.8 1.6 32.6 4.8 8.8 3.2 15.9 7.7 21.1 13.4s8.9 13.5 11.1 21.7c2.3 8.2 3.4 17.2 3.4 27.1v100.6c-6 1.3-15.1 2.8-27.3 4.6s-25.9 2.7-41.1 2.7c-10.1 0-19.4-1-27.7-2.9-8.4-1.9-15.5-5-21.5-9.3-5.9-4.3-10.5-9.8-13.9-16.6-3.3-6.8-5-16.4-5-26.4 0-9.6 1.9-15.7 5.6-22.3 3.8-6.6 8.9-12 15.3-16.2 6.5-4.2 13.9-7.2 22.4-9s17.4-2.7 26.6-2.7c4.3 0 8.8.3 13.6.8s9.8 1.4 15.2 2.7v-6.4c0-4.5-.5-8.8-1.6-12.8-1.1-4.1-3-7.6-5.6-10.7-2.7-3.1-6.2-5.5-10.6-7.2s-10-3-16.7-3c-9 0-17.2 1.1-24.7 2.4-7.5 1.3-13.7 2.8-18.4 4.5l-4.7-32.1c4.9-1.7 12.2-3.4 21.6-5.1s19.5-2.6 30.3-2.6zm3.3 141.9c12 0 20.9-.7 27.1-1.9v-39.8c-2.2-.6-5.3-1.3-9.4-1.9-4.1-.6-8.6-1-13.6-1-4.3 0-8.7.3-13.1 1-4.4.6-8.4 1.8-11.9 3.5s-6.4 4.1-8.5 7.2c-2.2 3.1-3.2 4.9-3.2 9.6 0 9.2 3.2 14.5 9 18 5.9 3.6 13.7 5.3 23.6 5.3zM512.9 103c12.9 0 23.8 1.6 32.6 4.8 8.8 3.2 15.9 7.7 21.1 13.4 5.3 5.8 8.9 13.5 11.1 21.7 2.3 8.2 3.4 17.2 3.4 27.1v100.6c-6 1.3-15.1 2.8-27.3 4.6-12.2 1.8-25.9 2.7-41.1 2.7-10.1 0-19.4-1-27.7-2.9-8.4-1.9-15.5-5-21.5-9.3-5.9-4.3-10.5-9.8-13.9-16.6-3.3-6.8-5-16.4-5-26.4 0-9.6 1.9-15.7 5.6-22.3 3.8-6.6 8.9-12 15.3-16.2 6.5-4.2 13.9-7.2 22.4-9s17.4-2.7 26.6-2.7c4.3 0 8.8.3 13.6.8 4.7.5 9.8 1.4 15.2 2.7v-6.4c0-4.5-.5-8.8-1.6-12.8-1.1-4.1-3-7.6-5.6-10.7-2.7-3.1-6.2-5.5-10.6-7.2-4.4-1.7-10-3-16.7-3-9 0-17.2 1.1-24.7 2.4-7.5 1.3-13.7 2.8-18.4 4.5l-4.7-32.1c4.9-1.7 12.2-3.4 21.6-5.1 9.4-1.8 19.5-2.6 30.3-2.6zm3.4 142c12 0 20.9-.7 27.1-1.9v-39.8c-2.2-.6-5.3-1.3-9.4-1.9-4.1-.6-8.6-1-13.6-1-4.3 0-8.7.3-13.1 1-4.4.6-8.4 1.8-11.9 3.5s-6.4 4.1-8.5 7.2c-2.2 3.1-3.2 4.9-3.2 9.6 0 9.2 3.2 14.5 9 18s13.7 5.3 23.6 5.3zm158.5 31.9c-64.1.3-64.1-51.8-64.1-60.1L610.6 32l39.1-6.2v183.6c0 4.7 0 34.5 25.1 34.6v32.9z"/>
</svg>

After

Width:  |  Height:  |  Size: 4.3 KiB

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" width="48px" height="48px"><path fill="#035bda" d="M46 40L29.317 10.852 22.808 23.96 34.267 37.24 13 39.655zM13.092 18.182L2 36.896 11.442 35.947 28.033 5.678z"/></svg>

After

Width:  |  Height:  |  Size: 228 B

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" width="48px" height="48px"><path fill="#1565c0" d="M36.094 31.35c-1.695-1.5-3.754-3.225-6.66-7.35-1.865-2.647-3.512-4-5.934-4-2.664 0-4.117 1.25-5.552 3.279-2.1 2.971-2.925 3.971-5.088 5.675-.786.619-4.861 3.172-4.86 7.671C8.001 41.875 11.753 44 15.155 44c4.469 0 5.439-1 8.345-1 3.633 0 5.57 1 8.476 1C37.789 44 39 39.625 39 36.872 39 34.25 37.789 32.85 36.094 31.35zM11.389 24.885c3.124-.694 3.616-3.739 3.611-5.732-.002-.696-.064-1.263-.096-1.558-.198-1.678-2.027-4.55-4.551-4.594-.12-.002-.242.002-.365.013-3.412.314-3.911 5.412-3.911 5.412-.056.287-.082.613-.078.963.031 2.263 1.356 5.527 4.274 5.61C10.623 25.008 10.994 24.973 11.389 24.885M19.503 16C21.99 16 24 13.315 24 9.998 24 6.681 21.99 4 19.503 4 17.015 4 15 6.681 15 9.998 15 13.315 17.015 16 19.503 16M29.522 16.964c.221.031.436.041.645.033 2.696-.103 4.416-3.276 4.781-5.723.037-.241.054-.486.052-.733-.015-2.441-1.831-5.012-3.799-5.49-2.177-.532-4.893 3.173-5.138 5.59-.037.37-.059.739-.063 1.103C25.975 14.296 26.841 16.599 29.522 16.964M41.984 21.142c0-1.281-1.004-5.142-4.742-5.142C33.496 16 33 19.644 33 22.219c0 2.41.187 5.752 4.578 5.781.087.001.176 0 .267-.002 4.027-.094 4.183-4.203 4.152-6.138C41.993 21.561 41.984 21.315 41.984 21.142"/><path fill="#fff" d="M24 31v7.5c0 0 0 1.875 2.625 2.5H33V31h-2.625v7.5h-2.75c0 0-.875-.125-1-.75V31H24zM20 27v4h-3c-2.125.375-4 2.25-3.999 4.875C13.001 35.917 13 35.958 13 36c0 2.75 1.875 4.625 4 5h5.625V27H20zM20 38.75h-2.375c-.75 0-2-1.125-2-2.75s1.25-2.75 2-2.75H20V38.75z"/></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

@ -12,10 +12,12 @@ var customSearch;
function scrolltoElement(elem, correction) {
correction = correction || scrollCorrection;
const $elem = elem.href ? $(elem.getAttribute('href')) : $(elem);
$('html, body').animate({ 'scrollTop': $elem.offset().top - correction }, 400);
};
$('html, body').animate({
'scrollTop': $elem.offset().top - correction
}, 400);
}
function setScrollAnchor(){
function setScrollAnchor() {
// button
const $postsBtn = $('.menu .active');
const $topBtn = $('.s-top');
@ -24,13 +26,25 @@ var customSearch;
const $bodyAnchor = $('.l_body');
// action
if ($postsBtn.length && $bodyAnchor) {
$postsBtn.click(e => { e.preventDefault(); e.stopPropagation(); scrolltoElement($bodyAnchor); });
$postsBtn.click(e => {
e.preventDefault();
e.stopPropagation();
scrolltoElement($bodyAnchor);
});
}
if ($titleBtn.length && $bodyAnchor) {
$titleBtn.click(e => { e.preventDefault(); e.stopPropagation(); scrolltoElement($bodyAnchor); });
$titleBtn.click(e => {
e.preventDefault();
e.stopPropagation();
scrolltoElement($bodyAnchor);
});
}
if ($topBtn.length && $bodyAnchor) {
$topBtn.click(e => { e.preventDefault(); e.stopPropagation(); scrolltoElement($bodyAnchor); });
$topBtn.click(e => {
e.preventDefault();
e.stopPropagation();
scrolltoElement($bodyAnchor);
});
}
const $coverAnchor = $('.cover-wrapper');
@ -45,11 +59,11 @@ var customSearch;
pos = scrollTop;
if (scrollTop > 150) {
$topBtn.addClass('show');
if (del > 0) {
$topBtn.removeClass('hl');
} else {
$topBtn.addClass('hl');
}
if (del > 0) {
$topBtn.removeClass('hl');
} else {
$topBtn.addClass('hl');
}
} else {
$topBtn.removeClass('show').removeClass('hl');
}
@ -59,7 +73,7 @@ var customSearch;
$headerAnchor.removeClass('show');
}
});
}
}
function setHeader() {
if (!window.subData) return;
@ -84,12 +98,19 @@ var customSearch;
// bind events to every btn
const $commentTarget = $('#comments');
if ($commentTarget.length) {
$comment.click(e => { e.preventDefault(); e.stopPropagation(); scrolltoElement($commentTarget); });
$comment.click(e => {
e.preventDefault();
e.stopPropagation();
scrolltoElement($commentTarget);
});
} else $comment.remove();
const $tocTarget = $('.toc-wrapper');
if ($tocTarget.length && $tocTarget.children().length) {
$toc.click((e) => { e.stopPropagation(); $tocTarget.toggleClass('active'); });
$toc.click((e) => {
e.stopPropagation();
$tocTarget.toggleClass('active');
});
} else $toc.remove();
@ -97,9 +118,9 @@ var customSearch;
}
function setHeaderMenuSelection() {
var $headerMenu = $('body .navgation');
// 先把已经激活的取消激活
$headerMenu.find('li a.active').removeClass('active');
var $headerMenu = $('body .navgation');
// 先把已经激活的取消激活
$headerMenu.find('li a.active').removeClass('active');
// var $underline = $headerMenu.find('.underline');
function setUnderline($item) {
// if (!transition) $underline.addClass('disable-trans');
@ -109,20 +130,20 @@ var customSearch;
}
//set current active nav
var $active_link = null;
var idname = location.pathname.replace(/\/|%/g, "");
if (idname.length == 0) {
idname = "home";
}
var idname = location.pathname.replace(/\/|%/g, "");
if (idname.length == 0) {
idname = "home";
}
var page = idname.match(/page\d{0,}$/g);
if (page) {
page = page[0];
idname = idname.split(page)[0];
}
var index = idname.match(/index.html/);
if (index) {
index = index[0];
idname = idname.split(index)[0];
}
var index = idname.match(/index.html/);
if (index) {
index = index[0];
idname = idname.split(index)[0];
}
if (idname && $headerMenu) {
$active_link = $('#' + idname, $headerMenu);
setUnderline($active_link);
@ -158,53 +179,53 @@ var customSearch;
$search.click(function (e) {
e.stopPropagation();
});
$header.ready(function () {
$header.bind('keydown', function (event) {
if (event.keyCode == 9) {
return false;
} else {
var isie = (document.all) ? true: false;
var key;
var ev;
if (isie) { //IE浏览器
key = window.event.keyCode;
ev = window.event;
} else { //火狐浏览器
key = e.which;
ev = e;
}
if (key == 9) { //IE浏览器
if (isie) {
ev.keyCode = 0;
ev.returnValue = false;
} else { //火狐浏览器
ev.which = 0;
ev.preventDefault();
}
}
}
});
});
$header.ready(function () {
$header.bind('keydown', function (event) {
if (event.keyCode == 9) {
return false;
} else {
var isie = (document.all) ? true : false;
var key;
var ev;
if (isie) { //IE浏览器
key = window.event.keyCode;
ev = window.event;
} else { //火狐浏览器
key = event.which;
ev = event;
}
if (key == 9) { //IE浏览器
if (isie) {
ev.keyCode = 0;
ev.returnValue = false;
} else { //火狐浏览器
ev.which = 0;
ev.preventDefault();
}
}
}
});
});
}
function setTocToggle() {
const $toc = $('.toc-wrapper');
if ($toc.length === 0) return;
// $toc.click((e) => {
// e.stopPropagation();
// $toc.addClass('active');
// });
// e.stopPropagation();
// $toc.addClass('active');
// });
$(document).click(() => $toc.removeClass('active'));
$toc.on('click', 'a', (e) => {
e.preventDefault();
e.stopPropagation();
if (e.target.tagName === 'A') {
scrolltoElement(e.target);
} else if (e.target.tagName === 'SPAN') {
scrolltoElement(e.target.parentElement);
}
$toc.removeClass('active');
scrolltoElement(e.target);
} else if (e.target.tagName === 'SPAN') {
scrolltoElement(e.target.parentElement);
}
$toc.removeClass('active');
});
const liElements = Array.from($toc.find('li a'));
@ -216,7 +237,9 @@ var customSearch;
const scrollTop = $('html').scrollTop() || $('body').scrollTop();
if (!anchor) return;
//binary search.
let l = 0, r = anchor.length - 1, mid;
let l = 0,
r = anchor.length - 1,
mid;
while (l < r) {
mid = (l + r + 1) >> 1;
if (anchor[mid] === scrollTop) l = r = mid;
@ -236,58 +259,52 @@ var customSearch;
scrollListener();
}
$(function () {
//set header
setHeader();
setHeaderMenuSelection();
setHeaderMenuPhone();
setHeaderSearch();
setTocToggle();
setScrollAnchor();
// $(".article .video-container").fitVids();
setTimeout(function () {
$('#loading-bar-wrapper').fadeOut(500);
}, 300);
function setSearchService() {
if (SEARCH_SERVICE === 'google') {
customSearch = new GoogleCustomSearch({
apiKey: GOOGLE_CUSTOM_SEARCH_API_KEY,
engineId: GOOGLE_CUSTOM_SEARCH_ENGINE_ID,
imagePath: "/images/"
imagePath: "/img/"
});
}
else if (SEARCH_SERVICE === 'algolia') {
} else if (SEARCH_SERVICE === 'algolia') {
customSearch = new AlgoliaSearch({
apiKey: ALGOLIA_API_KEY,
appId: ALGOLIA_APP_ID,
indexName: ALGOLIA_INDEX_NAME,
imagePath: "/images/"
imagePath: "/img/"
});
}
else if (SEARCH_SERVICE === 'hexo') {
} else if (SEARCH_SERVICE === 'hexo') {
customSearch = new HexoSearch({
imagePath: "/images/"
imagePath: "/img/"
});
}
else if (SEARCH_SERVICE === 'azure') {
} else if (SEARCH_SERVICE === 'azure') {
customSearch = new AzureSearch({
serviceName: AZURE_SERVICE_NAME,
indexName: AZURE_INDEX_NAME,
queryKey: AZURE_QUERY_KEY,
imagePath: "/images/"
imagePath: "/img/"
});
}
else if (SEARCH_SERVICE === 'baidu') {
} else if (SEARCH_SERVICE === 'baidu') {
customSearch = new BaiduSearch({
apiId: BAIDU_API_ID,
imagePath: "/images/"
imagePath: "/img/"
});
}
}
$(function () {
setHeader();
setHeaderMenuSelection();
setHeaderMenuPhone();
setHeaderSearch();
setTocToggle();
setScrollAnchor();
setSearchService();
// $(".article .video-container").fitVids();
setTimeout(function () {
$('#loading-bar-wrapper').fadeOut(500);
}, 300);
});
})(jQuery);
})(jQuery);

@ -0,0 +1,2 @@
(function webpackUniversalModuleDefinition(a,b){if(typeof exports==="object"&&typeof module==="object"){module.exports=b()}else{if(typeof define==="function"&&define.amd){define([],b)}else{if(typeof exports==="object"){exports["POWERMODE"]=b()}else{a["POWERMODE"]=b()}}}})(this,function(){return(function(a){var b={};function c(e){if(b[e]){return b[e].exports}var d=b[e]={exports:{},id:e,loaded:false};a[e].call(d.exports,d,d.exports,c);d.loaded=true;return d.exports}c.m=a;c.c=b;c.p="";return c(0)})([function(c,g,b){var d=document.createElement("canvas");d.width=window.innerWidth;d.height=window.innerHeight;d.style.cssText="position:fixed;top:0;left:0;pointer-events:none;z-index:999999";window.addEventListener("resize",function(){d.width=window.innerWidth;d.height=window.innerHeight});document.body.appendChild(d);var a=d.getContext("2d");var n=[];var j=0;var k=120;var f=k;var p=false;o.shake=true;function l(r,q){return Math.random()*(q-r)+r}function m(r){if(o.colorful){var q=l(0,360);return"hsla("+l(q-10,q+10)+", 100%, "+l(50,80)+"%, "+1+")"}else{return window.getComputedStyle(r).color}}function e(){var t=document.activeElement;var v;if(t.tagName==="TEXTAREA"||(t.tagName==="INPUT"&&t.getAttribute("type")==="text")){var u=b(1)(t,t.selectionStart);v=t.getBoundingClientRect();return{x:u.left+v.left,y:u.top+v.top,color:m(t)}}var s=window.getSelection();if(s.rangeCount){var q=s.getRangeAt(0);var r=q.startContainer;if(r.nodeType===document.TEXT_NODE){r=r.parentNode}v=q.getBoundingClientRect();return{x:v.left,y:v.top,color:m(r)}}return{x:0,y:0,color:"transparent"}}function h(q,s,r){return{x:q,y:s,alpha:1,color:r,velocity:{x:-1+Math.random()*2,y:-3.5+Math.random()*2}}}function o(){var t=e();var s=5+Math.round(Math.random()*10);while(s--){n[j]=h(t.x,t.y,t.color);j=(j+1)%500}f=k;if(!p){requestAnimationFrame(i)}if(o.shake){var r=1+2*Math.random();var q=r*(Math.random()>0.5?-1:1);var u=r*(Math.random()>0.5?-1:1);document.body.style.marginLeft=q+"px";document.body.style.marginTop=u+"px";setTimeout(function(){document.body.style.marginLeft="";document.body.style.marginTop=""},75)}}o.colorful=false;function i(){if(f>0){requestAnimationFrame(i);f--;p=true}else{p=false}a.clearRect(0,0,d.width,d.height);for(var q=0;q<n.length;++q){var r=n[q];if(r.alpha<=0.1){continue}r.velocity.y+=0.075;r.x+=r.velocity.x;r.y+=r.velocity.y;r.alpha*=0.96;a.globalAlpha=r.alpha;a.fillStyle=r.color;a.fillRect(Math.round(r.x-1.5),Math.round(r.y-1.5),3,3)}}requestAnimationFrame(i);c.exports=o},function(b,a){(function(){var d=["direction","boxSizing","width","height","overflowX","overflowY","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","borderStyle","paddingTop","paddingRight","paddingBottom","paddingLeft","fontStyle","fontVariant","fontWeight","fontStretch","fontSize","fontSizeAdjust","lineHeight","fontFamily","textAlign","textTransform","textIndent","textDecoration","letterSpacing","wordSpacing","tabSize","MozTabSize"];var e=window.mozInnerScreenX!=null;function c(k,l,o){var h=o&&o.debug||false;if(h){var i=document.querySelector("#input-textarea-caret-position-mirror-div");if(i){i.parentNode.removeChild(i)}}var f=document.createElement("div");f.id="input-textarea-caret-position-mirror-div";document.body.appendChild(f);var g=f.style;var j=window.getComputedStyle?getComputedStyle(k):k.currentStyle;g.whiteSpace="pre-wrap";if(k.nodeName!=="INPUT"){g.wordWrap="break-word"}g.position="absolute";if(!h){g.visibility="hidden"}d.forEach(function(p){g[p]=j[p]});if(e){if(k.scrollHeight>parseInt(j.height)){g.overflowY="scroll"}}else{g.overflow="hidden"}f.textContent=k.value.substring(0,l);if(k.nodeName==="INPUT"){f.textContent=f.textContent.replace(/\s/g,"\u00a0")}var n=document.createElement("span");n.textContent=k.value.substring(l)||".";f.appendChild(n);var m={top:n.offsetTop+parseInt(j["borderTopWidth"]),left:n.offsetLeft+parseInt(j["borderLeftWidth"])};if(h){n.style.backgroundColor="#aaa"}else{document.body.removeChild(f)}return m}if(typeof b!="undefined"&&typeof b.exports!="undefined"){b.exports=c}else{window.getCaretCoordinates=c}}())}])});
POWERMODE.colorful=true;POWERMODE.shake=false;document.body.addEventListener("input",POWERMODE);

@ -31,11 +31,11 @@ var SearchService = "";
btn_prev: "#u-search .btn-prev"
},
brands: {
'hexo': {logo: '', url: ''},
'google': {logo: 'google.svg', url: 'https://cse.google.com'},
'algolia': {logo: 'algolia.svg', url: 'https://www.algolia.com'},
'hexo': {logo: '', url: ''},
'azure': {logo: 'azure.svg', url: 'https://azure.microsoft.com/en-us/services/search/'},
'baidu': {logo: 'baidu.svg', url: 'http://zn.baidu.com/cse/home/index'}
'baidu': {logo: 'baidu.svg', url: 'http://zn.baidu.com/cse/home/index'},
'azure': {logo: 'azure.svg', url: 'https://azure.microsoft.com/en-us/services/search/'}
},
imagePath: ROOT + "img/"
}, options);
@ -127,13 +127,18 @@ var SearchService = "";
* @param url : (string) url
* @param title : (string) title
* @param digest : (string) digest
* @param index : 标号
*/
self.buildResult = function(url, title, digest) {
self.buildResult = function(url, title, digest, index) {
var html = "";
html = "<li>";
html += "<a class='result' href='" +url+ "'>";
html += "<span class='title'>" +title+ "</span>";
html += "<span class='digest'>" +digest+ "</span>";
if(index === undefined)
html += "<span class='title'>" +title+ "</span>";
else
html += "<span class='title'>" +index + ". " + title+ "</span>";
if(digest !== "")
html += "<span class='digest'>" +digest+ "</span>";
html += "<span class='fas fa-chevron-thin-right'></span>";
html += "</a>";
html += "</li>";
@ -237,7 +242,6 @@ var SearchService = "";
})(jQuery);
var AlgoliaSearch;
(function($) {
'use strict';
@ -248,7 +252,7 @@ var AlgoliaSearch;
AlgoliaSearch = function(options) {
SearchService.apply(this, arguments);
var self = this;
var endpoint = "https://" +self.config.app_id+ "-dsn.algolia.net/1/indexes/" +self.config.indexName;
var endpoint = "https://" +self.config.appId+ "-dsn.algolia.net/1/indexes/" + self.config.indexName;
self.addLogo('algolia');
/**
@ -263,8 +267,8 @@ var AlgoliaSearch;
url = ROOT + url;
}
var title = row.title;
var digest = row._highlightResult.excerptStrip.value || "";
html += self.buildResult(url, title, digest);
var digest = "";
html += self.buildResult(url, title, digest, index+1);
});
return html;
};
@ -315,7 +319,7 @@ var AlgoliaSearch;
query: queryText,
page: page-1,
hitsPerPage: self.config.per_page,
"x-algolia-application-id": self.config.app_id,
"x-algolia-application-id": self.config.appId,
"x-algolia-api-key": self.config.apiKey
}, function(data, status) {
if (status === 'success' && data.hits && data.hits.length > 0) {
@ -336,8 +340,8 @@ var AlgoliaSearch;
};
})(jQuery);
var AzureSearch;
var AzureSearch;
(function($) {
'use strict';
@ -447,8 +451,8 @@ var AzureSearch;
};
})(jQuery);
var BaiduSearch;
var BaiduSearch;
(function($) {
'use strict';
@ -541,8 +545,8 @@ var BaiduSearch;
};
})(jQuery);
var GoogleCustomSearch = "";
var GoogleCustomSearch = "";
(function($) {
'use strict';
@ -636,8 +640,8 @@ var GoogleCustomSearch = "";
return self;
};
})(jQuery);
var HexoSearch;
var HexoSearch;
(function($) {
'use strict';
@ -686,14 +690,14 @@ var HexoSearch;
post_content = post.text.trim();
var start = 0, end = 0;
if (first_occur >= 0) {
start = Math.max(first_occur-30, 0);
end = (start === 0) ? Math.min(200, post_content.length) : Math.min(first_occur+170, post_content.length);
start = Math.max(first_occur-40, 0);
end = (start === 0) ? Math.min(200, post_content.length) : Math.min(first_occur + 120, post_content.length);
var match_content = post_content.substring(start, end);
keywords.forEach(function(keyword) {
var regS = new RegExp(keyword, "gi");
match_content = match_content.replace(regS, "<b>"+keyword+"</b>");
match_content = match_content.replace(regS, "<b style='color: #c00'>"+keyword+"</b>");
});
post.digest = match_content;
post.digest = match_content + "......";
}
else {
end = Math.min(200, post_content.length);
@ -712,9 +716,10 @@ var HexoSearch;
self.buildResultList = function(data, queryText) {
var results = [],
html = "";
var i = 1;
$.each(data, function(index, post) {
if (self.contentSearch(post, queryText))
html += self.buildResult(post.permalink, post.title, post.digest);
if (self.contentSearch(post, queryText))
html += self.buildResult(post.permalink, post.title, post.digest, i++);
});
return html;
};

@ -249,7 +249,7 @@
.result {
position: relative;
display: block;
padding: 15px 30px 15px 0px;
padding-top: 20px;
text-decoration: none;
&:hover {
@ -275,8 +275,9 @@
}
.digest {
display: block;
white-space: pre-wrap;
overflow: scroll;
white-space: inherit;
overflow: hidden;
word-break: break-all;
text-overflow: ellipsis;
font-size: @fontsize_small;
line-height: @lineheight_base;

Loading…
Cancel
Save