hexo-theme-volantis 4.3.1 → 5.0.0-alpha.112
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -4
- package/_config.yml +599 -246
- package/languages/en.yml +7 -0
- package/languages/zh-CN.yml +13 -2
- package/languages/zh-TW.yml +7 -0
- package/layout/404.ejs +1 -1
- package/layout/_meta/author.ejs +4 -4
- package/layout/_meta/category.ejs +11 -8
- package/layout/_meta/counter.ejs +29 -7
- package/layout/_meta/date.ejs +1 -1
- package/layout/_meta/music.ejs +1 -1
- package/layout/_meta/share.ejs +1 -1
- package/layout/_meta/tags.ejs +3 -0
- package/layout/_meta/thumbnail.ejs +3 -1
- package/layout/_meta/updated.ejs +1 -1
- package/layout/_meta/walinecount.ejs +2 -1
- package/layout/{_cover → _partial/_cover}/blank.ejs +0 -0
- package/layout/{_cover → _partial/_cover}/dock.ejs +1 -1
- package/layout/{_cover → _partial/_cover}/featured.ejs +1 -1
- package/layout/{_cover → _partial/_cover}/focus.ejs +1 -1
- package/layout/_partial/_cover/layout.ejs +8 -0
- package/layout/{_cover → _partial/_cover}/search.ejs +2 -2
- package/layout/_partial/archive.ejs +2 -2
- package/layout/_partial/article.ejs +21 -16
- package/layout/_partial/categories.ejs +1 -1
- package/layout/_partial/cover.ejs +8 -28
- package/layout/_partial/footer.ejs +19 -11
- package/layout/_partial/head.ejs +70 -116
- package/layout/_partial/header.ejs +17 -11
- package/layout/_partial/meta.ejs +18 -4
- package/layout/_partial/post.ejs +35 -9
- package/layout/_partial/scripts/_ctrl/cdnCtrl.ejs +126 -0
- package/layout/_partial/scripts/{coverCtrl.ejs → _ctrl/coverCtrl.ejs} +17 -25
- package/layout/_partial/scripts/_ctrl.ejs +2 -0
- package/layout/_partial/scripts/content-visibility-scroll-fix.ejs +88 -0
- package/layout/_partial/scripts/global.ejs +422 -109
- package/layout/_partial/scripts/index.ejs +91 -46
- package/layout/_partial/scripts/toc.ejs +98 -68
- package/layout/_partial/side.ejs +4 -1
- package/layout/_plugins/_page_plugins/artitalk/index.ejs +15 -0
- package/layout/_plugins/_page_plugins/bbtalk/index.ejs +10 -0
- package/layout/_plugins/_page_plugins/fcircle/index.ejs +12 -0
- package/layout/_plugins/_page_plugins/gitter/index.ejs +14 -0
- package/layout/_plugins/_page_plugins/indent/index.ejs +16 -0
- package/layout/_plugins/_page_plugins/index.ejs +27 -0
- package/layout/_plugins/_page_plugins/katex/index.ejs +13 -0
- package/layout/{_third-party/math/mathjax/script.ejs → _plugins/_page_plugins/mathjax/index.ejs} +2 -2
- package/layout/_plugins/_page_plugins/snackbar/index.ejs +55 -0
- package/layout/{_partial/scripts/counter.ejs → _plugins/analytics/LCCounter.ejs} +0 -0
- package/layout/{_third-party → _plugins}/analytics/script.ejs +43 -5
- package/layout/{_third-party → _plugins}/aplayer/layout.ejs +0 -0
- package/layout/_plugins/aplayer/script.ejs +74 -0
- package/layout/_plugins/chat/gitter/script.ejs +17 -0
- package/layout/_plugins/chat/index.ejs +1 -0
- package/layout/_plugins/chat/tidio/script.ejs +1 -0
- package/layout/_plugins/comments/artalk/script.ejs +59 -0
- package/layout/_plugins/comments/beaudar/script.ejs +61 -0
- package/layout/_plugins/comments/discuss/script.ejs +30 -0
- package/layout/_plugins/comments/disqus/script.ejs +98 -0
- package/layout/_plugins/comments/disqusjs/script.ejs +35 -0
- package/layout/_plugins/comments/giscus/script.ejs +47 -0
- package/layout/_plugins/comments/gitalk/script.ejs +24 -0
- package/layout/_plugins/comments/hashover/script.ejs +5 -0
- package/layout/{_third-party → _plugins}/comments/index.ejs +10 -3
- package/layout/_plugins/comments/isso/script.ejs +27 -0
- package/layout/_plugins/comments/livere/script.ejs +15 -0
- package/layout/_plugins/comments/twikoo/script.ejs +40 -0
- package/layout/_plugins/comments/utterances/script.ejs +43 -0
- package/layout/_plugins/comments/vssue/script.ejs +37 -0
- package/layout/_plugins/comments/waline/script.ejs +62 -0
- package/layout/_plugins/comments/z-custom/script.ejs +1 -0
- package/layout/_plugins/darkmode/script.ejs +114 -0
- package/layout/{_third-party → _plugins}/end-of-support/script.ejs +25 -8
- package/layout/_plugins/github-api/script.ejs +27 -0
- package/layout/_plugins/highlight/highlightjs/script.ejs +26 -0
- package/layout/_plugins/highlight/prismjs/script.ejs +25 -0
- package/layout/_plugins/highlight/script.ejs +1 -0
- package/layout/{_third-party → _plugins}/lazyload/script.ejs +1 -1
- package/layout/{_third-party → _plugins}/nodewaves/script.ejs +1 -1
- package/layout/_plugins/parallax/script.ejs +74 -0
- package/layout/{_third-party → _plugins}/pjax/animate.ejs +31 -31
- package/layout/_plugins/pjax/index.ejs +73 -0
- package/layout/_plugins/pjax/pdata.ejs +56 -0
- package/layout/{_third-party → _plugins}/preload/script.ejs +3 -3
- package/layout/_plugins/rightmenu/layout.ejs +119 -0
- package/layout/_plugins/rightmenus/layout.ejs +137 -0
- package/layout/_plugins/scrollreveal/script.ejs +25 -0
- package/layout/_plugins/search/script.ejs +50 -0
- package/layout/{_third-party → _plugins}/share/layout.ejs +0 -0
- package/layout/_plugins/swiper/script.ejs +37 -0
- package/layout/_pre.ejs +2 -2
- package/layout/_widget/_pre.ejs +5 -0
- package/layout/_widget/blogger.ejs +1 -1
- package/layout/_widget/category.ejs +2 -2
- package/layout/_widget/copyright.ejs +1 -1
- package/layout/_widget/grid.ejs +3 -3
- package/layout/_widget/lastupdate.ejs +27 -0
- package/layout/_widget/list.ejs +2 -2
- package/layout/_widget/load.ejs +18 -0
- package/layout/_widget/music.ejs +3 -2
- package/layout/_widget/page.ejs +1 -1
- package/layout/_widget/qrcode.ejs +1 -1
- package/layout/_widget/related_posts.ejs +1 -1
- package/layout/_widget/tagcloud.ejs +1 -1
- package/layout/_widget/text.ejs +1 -1
- package/layout/_widget/toc.ejs +6 -2
- package/layout/_widget/webinfo.ejs +13 -76
- package/layout/archive.ejs +4 -4
- package/layout/category.ejs +9 -4
- package/layout/docs.ejs +1 -1
- package/layout/friends.ejs +6 -25
- package/layout/index.ejs +1 -1
- package/layout/layout.ejs +30 -12
- package/layout/list.ejs +1 -1
- package/layout/page.ejs +1 -1
- package/layout/post.ejs +1 -1
- package/layout/tag.ejs +8 -3
- package/package.json +5 -3
- package/scripts/events/index.js +13 -0
- package/scripts/events/lib/check-configuration.js +43 -0
- package/scripts/events/lib/check-environment.js +74 -0
- package/scripts/events/lib/config.js +34 -9
- package/scripts/events/lib/render-stylus.js +78 -0
- package/scripts/events/lib/stellar-tag-utils.js +76 -0
- package/scripts/filters/content-visibility.js +25 -0
- package/scripts/{render → filters}/img.js +0 -0
- package/scripts/filters/replace.js +15 -0
- package/scripts/{z-lazyload/lib/process.js → filters/z-lazyload.js} +6 -3
- package/scripts/helpers/custom-files.js +165 -0
- package/scripts/helpers/first-style.js +19 -0
- package/scripts/helpers/head/autoCanonical.js +15 -0
- package/scripts/helpers/head/generate_preload_fontfamily.js +22 -0
- package/scripts/helpers/head/generate_seo.js +24 -0
- package/scripts/helpers/head/generate_title__keywords__description.js +101 -0
- package/scripts/{related_posts/index.js → helpers/related-posts.js} +1 -1
- package/scripts/helpers/revisioned.js +158 -0
- package/scripts/helpers/structured-data/index.js +2 -0
- package/scripts/helpers/structured-data/lib/blogposting.js +77 -0
- package/scripts/helpers/structured-data/lib/breadcrumblist.js +152 -0
- package/scripts/helpers/structured-data/lib/config.js +31 -0
- package/scripts/helpers/structured-data/lib/index.js +30 -0
- package/scripts/helpers/structured-data/lib/organization.js +15 -0
- package/scripts/helpers/structured-data/lib/person.js +16 -0
- package/scripts/helpers/structured-data/lib/website.js +42 -0
- package/scripts/tags/btn.js +6 -1
- package/scripts/tags/btns.js +7 -2
- package/scripts/tags/checkbox.js +12 -2
- package/scripts/tags/contributors.js +100 -0
- package/scripts/tags/dropmenu.js +18 -3
- package/scripts/tags/fancybox.js +44 -10
- package/scripts/tags/folding.js +6 -1
- package/scripts/tags/frame.js +6 -1
- package/scripts/tags/friends.js +99 -0
- package/scripts/tags/ghcard.js +6 -1
- package/scripts/tags/image.js +14 -2
- package/scripts/tags/link.js +6 -1
- package/scripts/tags/md.js +59 -0
- package/scripts/tags/media.js +25 -1
- package/scripts/tags/note.js +36 -3
- package/scripts/tags/site.js +87 -51
- package/scripts/tags/span.js +12 -2
- package/scripts/tags/swiper.js +38 -0
- package/scripts/tags/tabs.js +33 -3
- package/scripts/tags/timeline.js +6 -1
- package/source/css/Readme.md +28 -0
- package/source/css/_defines/AutoPrefixCSS.styl +347 -0
- package/source/css/_defines/Readme.md +3 -0
- package/source/css/_defines/color.styl +41 -1
- package/source/css/_defines/effect.styl +0 -13
- package/source/css/_defines/fonts.styl +17 -18
- package/source/css/_defines/func.styl +12 -30
- package/source/css/_first/base_first.styl +118 -0
- package/source/css/_first/{cover.styl → cover_first.styl} +113 -87
- package/source/css/_first/dark_first.styl +76 -0
- package/source/css/_first/fontfamily_first.styl +17 -0
- package/source/css/_first/{navbar.styl → navbar_first.styl} +4 -10
- package/source/css/_first/search_first.styl +12 -0
- package/source/css/{_base/index.styl → _style/_base/base.styl} +9 -93
- package/source/css/_style/_base/fontfamily_async.styl +8 -0
- package/source/css/{_layout → _style/_layout}/archive.styl +0 -0
- package/source/css/{_layout → _style/_layout}/article.styl +3 -30
- package/source/css/{_layout → _style/_layout}/footer.styl +0 -0
- package/source/css/_style/_layout/friends-simpleuser.styl +23 -0
- package/source/css/_style/_layout/friends-traditional.styl +81 -0
- package/source/css/{_layout → _style/_layout}/img.styl +0 -0
- package/source/css/_style/_layout/loading.styl +14 -0
- package/source/css/{_layout → _style/_layout}/main.styl +19 -7
- package/source/css/{_layout → _style/_layout}/md.styl +0 -0
- package/source/css/{_layout → _style/_layout}/pagination.styl +1 -1
- package/source/css/{_layout → _style/_layout}/posts.styl +2 -0
- package/source/css/{_first → _style/_layout}/search.styl +0 -103
- package/source/css/{_layout → _style/_layout}/sidebar.styl +23 -3
- package/source/css/{_layout → _style/_layout}/snackbar.styl +0 -0
- package/source/css/{_layout → _style/_layout}/toc.styl +3 -3
- package/source/css/{_layout → _style/_layout}/video.styl +0 -0
- package/source/css/_style/_plugins/_dark/dark_async.styl +41 -0
- package/source/css/_style/_plugins/_dark/dark_plugins.styl +136 -0
- package/source/css/_style/_plugins/_highlight/highlightjs/clipboard.styl +36 -0
- package/source/css/_style/_plugins/_highlight/highlightjs/color.styl +96 -0
- package/source/css/_style/_plugins/_highlight/highlightjs/index.styl +102 -0
- package/source/css/_style/_plugins/_highlight/highlightjs/language.styl +63 -0
- package/source/css/_style/_plugins/_highlight/index.styl +1 -0
- package/source/css/_style/_plugins/_highlight/prismjs/clipboard.styl +33 -0
- package/source/css/_style/_plugins/_highlight/prismjs/index.styl +8 -0
- package/source/css/_style/_plugins/_highlight/prismjs/language.styl +63 -0
- package/source/css/_style/_plugins/_rightmenu/reading.styl +56 -0
- package/source/css/{_plugins → _style/_plugins/_rightmenu}/rightmenu.styl +22 -2
- package/source/css/{_plugins → _style/_plugins}/aplayer.styl +8 -1
- package/source/css/{_plugins → _style/_plugins}/cursor.styl +49 -19
- package/source/css/_style/_plugins/fontcolor.styl +84 -0
- package/source/css/{_plugins → _style/_plugins}/gitalk.styl +0 -0
- package/source/css/_style/_plugins/index.styl +24 -0
- package/source/css/{_plugins → _style/_plugins}/mathjax.styl +0 -0
- package/source/css/_style/_plugins/message.styl +14 -0
- package/source/css/{_plugins → _style/_plugins}/pjaxanimate.styl +0 -0
- package/source/css/_style/_tag-plugins/Readme.md +6 -0
- package/source/css/{_tag-plugins → _style/_tag-plugins}/btns.styl +0 -0
- package/source/css/{_tag-plugins → _style/_tag-plugins}/checkbox.styl +0 -0
- package/source/css/{_tag-plugins → _style/_tag-plugins}/dropmenu.styl +0 -0
- package/source/css/{_plugins → _style/_tag-plugins}/fancybox.styl +8 -9
- package/source/css/{_tag-plugins → _style/_tag-plugins}/folding.styl +0 -0
- package/source/css/{_tag-plugins → _style/_tag-plugins}/frame.styl +0 -0
- package/source/css/_style/_tag-plugins/friends.styl +72 -0
- package/source/css/{_tag-plugins → _style/_tag-plugins}/ghcard.styl +0 -0
- package/source/css/{_tag-plugins → _style/_tag-plugins}/image.styl +0 -0
- package/source/css/{_tag-plugins → _style/_tag-plugins}/link.styl +0 -0
- package/source/css/{_tag-plugins → _style/_tag-plugins}/media.styl +0 -0
- package/source/css/{_tag-plugins → _style/_tag-plugins}/note.styl +0 -0
- package/source/css/_style/_tag-plugins/sites.styl +87 -0
- package/source/css/{_tag-plugins → _style/_tag-plugins}/span.styl +0 -0
- package/source/css/_style/_tag-plugins/swiper.styl +44 -0
- package/source/css/{_tag-plugins → _style/_tag-plugins}/table.styl +0 -0
- package/source/css/{_tag-plugins → _style/_tag-plugins}/tabs.styl +0 -0
- package/source/css/_style/_tag-plugins/tag.json +35 -0
- package/source/css/_style/_tag-plugins/text.styl +31 -0
- package/source/css/{_tag-plugins → _style/_tag-plugins}/timeline.styl +0 -0
- package/source/css/_style/index.styl +8 -0
- package/source/css/first.styl +17 -6
- package/source/css/style.styl +9 -7
- package/source/js/app.js +1051 -278
- package/source/js/plugins/aplayer.js +186 -0
- package/source/js/plugins/parallax.js +191 -0
- package/source/js/plugins/rightMenu.js +577 -0
- package/source/js/plugins/rightMenus.js +616 -0
- package/source/js/plugins/tags/contributors.js +92 -0
- package/source/js/plugins/tags/friends.js +93 -0
- package/source/js/plugins/tags/sites.js +96 -0
- package/source/js/search/hexo.js +180 -373
- package/.eslintrc.json +0 -111
- package/layout/_meta/valinecount.ejs +0 -15
- package/layout/_partial/rightmenu.ejs +0 -199
- package/layout/_partial/scripts/cover.ejs +0 -45
- package/layout/_partial/scripts/darkmode.ejs +0 -85
- package/layout/_partial/scripts/import.ejs +0 -3
- package/layout/_partial/scripts/issues.ejs +0 -18
- package/layout/_partial/scripts/search.ejs +0 -62
- package/layout/_partial/snackbar.ejs +0 -22
- package/layout/_third-party/aplayer/script.ejs +0 -26
- package/layout/_third-party/clipboard/script.ejs +0 -54
- package/layout/_third-party/comments/disqus/layout.ejs +0 -5
- package/layout/_third-party/comments/disqus/script.ejs +0 -90
- package/layout/_third-party/comments/disqusjs/layout.ejs +0 -1
- package/layout/_third-party/comments/disqusjs/script.ejs +0 -34
- package/layout/_third-party/comments/gitalk/layout.ejs +0 -1
- package/layout/_third-party/comments/gitalk/script.ejs +0 -22
- package/layout/_third-party/comments/hashover/layout.ejs +0 -2
- package/layout/_third-party/comments/hashover/script.ejs +0 -1
- package/layout/_third-party/comments/isso/layout.ejs +0 -1
- package/layout/_third-party/comments/isso/script.ejs +0 -1
- package/layout/_third-party/comments/livere/layout.ejs +0 -3
- package/layout/_third-party/comments/livere/script.ejs +0 -10
- package/layout/_third-party/comments/minivaline/layout.ejs +0 -3
- package/layout/_third-party/comments/minivaline/script.ejs +0 -34
- package/layout/_third-party/comments/twikoo/layout.ejs +0 -3
- package/layout/_third-party/comments/twikoo/script.ejs +0 -32
- package/layout/_third-party/comments/valine/layout.ejs +0 -3
- package/layout/_third-party/comments/valine/script.ejs +0 -49
- package/layout/_third-party/comments/vssue/layout.ejs +0 -1
- package/layout/_third-party/comments/vssue/script.ejs +0 -21
- package/layout/_third-party/comments/waline/layout.ejs +0 -3
- package/layout/_third-party/comments/waline/script.ejs +0 -33
- package/layout/_third-party/fancybox/script.ejs +0 -61
- package/layout/_third-party/highlightjs/script.ejs +0 -11
- package/layout/_third-party/pjax/index.ejs +0 -78
- package/layout/_third-party/pjax/pdata.ejs +0 -53
- package/layout/_third-party/scrollreveal/script.ejs +0 -21
- package/layout/_third-party/tidio/script.ejs +0 -3
- package/layout/artitalk.ejs +0 -13
- package/layout/bb.ejs +0 -10
- package/package-lock.json +0 -916
- package/scripts/tags/issues.js +0 -41
- package/scripts/z-lazyload/index.js +0 -4
- package/source/css/_highlight/index.styl +0 -316
- package/source/css/_layout/friends.styl +0 -79
- package/source/css/_plugins/clipboard.styl +0 -37
- package/source/css/_plugins/dark.styl +0 -149
- package/source/css/_plugins/darkmode.styl +0 -9
- package/source/css/_plugins/index.styl +0 -18
- package/source/css/_plugins/twikoo.styl +0 -21
- package/source/css/_plugins/valine.styl +0 -183
- package/source/css/_tag-plugins/simpleuser.styl +0 -21
- package/source/css/_tag-plugins/site-card.styl +0 -70
- package/source/js/aplayer.js +0 -167
- package/source/js/issues.js +0 -186
- package/source/js/search/algolia.js +0 -344
- package/source/js/search/azure.js +0 -355
- package/source/js/search/baidu.js +0 -340
- package/source/js/search/google.js +0 -339
- package/source/js/valine.js +0 -5137
package/source/js/search/hexo.js
CHANGED
|
@@ -1,385 +1,192 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
1
|
+
let SearchService = (() => {
|
|
2
|
+
fn = {};
|
|
3
|
+
fn.queryText = null;
|
|
4
|
+
fn.data = null;
|
|
5
|
+
fn.template = `<div id="u-search">
|
|
6
|
+
<div class="modal">
|
|
7
|
+
<header class="modal-header" class="clearfix">
|
|
8
|
+
<form id="u-search-modal-form" class="u-search-form" name="uSearchModalForm">
|
|
9
|
+
<input type="text" id="u-search-modal-input" class="u-search-input" />
|
|
10
|
+
<button type="submit" id="u-search-modal-btn-submit" class="u-search-btn-submit">
|
|
11
|
+
<span class="fa-solid fa-search"></span>
|
|
12
|
+
</button>
|
|
13
|
+
</form>
|
|
14
|
+
<a id="u-search-btn-close" class="btn-close"> <span class="fa-solid fa-times"></span> </a>
|
|
15
|
+
</header>
|
|
16
|
+
<main class="modal-body">
|
|
17
|
+
<ul class="modal-results"></ul>
|
|
18
|
+
</main>
|
|
19
|
+
</div>
|
|
20
|
+
<div id="modal-overlay" class="modal-overlay"></div>
|
|
21
|
+
</div>
|
|
22
|
+
`;
|
|
23
|
+
fn.init = () => {
|
|
24
|
+
let div = document.createElement("div");
|
|
25
|
+
div.innerHTML += fn.template;
|
|
26
|
+
document.body.append(div);
|
|
27
|
+
document.querySelectorAll(".u-search-form").forEach((e) => {
|
|
28
|
+
e.addEventListener("submit", fn.onSubmit, false);
|
|
29
|
+
});
|
|
30
|
+
let uSearchModalInput = document.querySelector("#u-search-modal-input");
|
|
31
|
+
uSearchModalInput.addEventListener("input", fn.onSubmit);
|
|
32
|
+
document
|
|
33
|
+
.querySelector("#u-search-btn-close")
|
|
34
|
+
.addEventListener("click", fn.close, false);
|
|
35
|
+
document
|
|
36
|
+
.querySelector("#modal-overlay")
|
|
37
|
+
.addEventListener("click", fn.close, false);
|
|
38
|
+
};
|
|
39
|
+
fn.onSubmit = (event) => {
|
|
40
|
+
event.preventDefault();
|
|
41
|
+
let input = event.target.querySelector(".u-search-input");
|
|
42
|
+
if (input) {
|
|
43
|
+
fn.queryText = input.value;
|
|
44
|
+
} else {
|
|
45
|
+
fn.queryText = event.target.value;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (fn.queryText) {
|
|
49
|
+
fn.search();
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
fn.search = async () => {
|
|
53
|
+
document.querySelectorAll(".u-search-input").forEach((e) => {
|
|
54
|
+
e.value = fn.queryText;
|
|
55
|
+
});
|
|
56
|
+
document.querySelector("#u-search").style.display = "block";
|
|
57
|
+
if (!fn.data) {
|
|
58
|
+
fn.data = await fn.fetchData();
|
|
59
|
+
}
|
|
60
|
+
let results = "";
|
|
61
|
+
results += fn.buildResultList(data.pages);
|
|
62
|
+
results += fn.buildResultList(data.posts);
|
|
63
|
+
document.querySelector("#u-search .modal-results").innerHTML = results;
|
|
64
|
+
window.pjax && pjax.refresh(document.querySelector("#u-search"));
|
|
65
|
+
document.addEventListener("keydown", function f(event) {
|
|
66
|
+
if (event.code === "Escape") {
|
|
67
|
+
fn.close();
|
|
68
|
+
document.removeEventListener("keydown", f);
|
|
65
69
|
}
|
|
66
|
-
|
|
67
|
-
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
fn.close = () => {
|
|
73
|
+
document.querySelector("#u-search").style.display = "none";
|
|
74
|
+
};
|
|
75
|
+
fn.fetchData = () => {
|
|
76
|
+
return fetch(SearchServiceDataPath)
|
|
77
|
+
.then((response) => response.text())
|
|
78
|
+
.then((res) => {
|
|
79
|
+
data = JSON.parse(res);
|
|
80
|
+
// console.log(data);
|
|
81
|
+
return data;
|
|
68
82
|
});
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
self.afterQuery = function() {
|
|
76
|
-
self.dom.modal_body.scrollTop(0);
|
|
77
|
-
self.dom.modal_ajax_content.addClass('loaded');
|
|
78
|
-
self.stopLoading();
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Perform a complete serach operation including UI updates and query
|
|
83
|
-
* @param startIndex {int} start index or page number
|
|
84
|
-
*/
|
|
85
|
-
self.search = function(startIndex, callback) {
|
|
86
|
-
self.beforeQuery();
|
|
87
|
-
if (self.search instanceof Function) {
|
|
88
|
-
self.query(self.queryText, startIndex, function() {
|
|
89
|
-
self.afterQuery();
|
|
90
|
-
});
|
|
91
|
-
} else {
|
|
92
|
-
console.log('query() does not exist.');
|
|
93
|
-
self.onQueryError(self.queryText, '');
|
|
94
|
-
self.afterQuery();
|
|
83
|
+
};
|
|
84
|
+
fn.buildResultList = (data) => {
|
|
85
|
+
let html = "";
|
|
86
|
+
data.forEach((post) => {
|
|
87
|
+
if (post.text) {
|
|
88
|
+
post.text = post.text.replace(/12345\d*/g, "") // 简易移除代码行号
|
|
95
89
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Query error handler
|
|
100
|
-
* @param queryText: (string)
|
|
101
|
-
* @param status: (string)
|
|
102
|
-
*/
|
|
103
|
-
self.onQueryError = function(queryText, status) {
|
|
104
|
-
var errMsg = '';
|
|
105
|
-
if (status === 'success') errMsg = 'No result found for "' + queryText + '".';
|
|
106
|
-
else if (status === 'timeout') errMsg = 'Unfortunate timeout.';
|
|
107
|
-
else errMsg = 'Mysterious failure.';
|
|
108
|
-
self.dom.modal_results.html('');
|
|
109
|
-
self.dom.modal_error.html(errMsg);
|
|
110
|
-
self.dom.modal_error.show();
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
self.nextPage = function() {
|
|
114
|
-
if (self.nav.next !== -1) {
|
|
115
|
-
self.search(self.nav.next);
|
|
90
|
+
if (!post.title&&post.text) {
|
|
91
|
+
post.title = post.text.trim().slice(0,15)
|
|
116
92
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
self.prevPage = function() {
|
|
120
|
-
if (self.nav.prev !== -1) {
|
|
121
|
-
self.search(self.nav.prev);
|
|
93
|
+
if (fn.contentSearch(post)) {
|
|
94
|
+
html += fn.buildResult(post.permalink, post.title, post.digest);
|
|
122
95
|
}
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
self.getUrlRelativePath = function(url) {
|
|
126
|
-
var arrUrl = url.split('//');
|
|
127
|
-
var start = arrUrl[1].indexOf('/');
|
|
128
|
-
var relUrl = arrUrl[1].substring(start);
|
|
129
|
-
if (relUrl.indexOf('?') != -1) {
|
|
130
|
-
relUrl = relUrl.split('?')[0];
|
|
131
|
-
}
|
|
132
|
-
return relUrl;
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Generate html for one result
|
|
137
|
-
* @param url : (string) url
|
|
138
|
-
* @param title : (string) title
|
|
139
|
-
* @param digest : (string) digest
|
|
140
|
-
*/
|
|
141
|
-
self.buildResult = function(url, title, digest) {
|
|
142
|
-
var result = self.getUrlRelativePath(url);
|
|
143
|
-
var html = '';
|
|
144
|
-
html = '<li>';
|
|
145
|
-
html += '<a class=\'result\' href=\'' + result + '\'>';
|
|
146
|
-
html += '<span class=\'title\'>' + title + '</span>';
|
|
147
|
-
if (digest !== '') html += '<span class=\'digest\'>' + digest + '</span>';
|
|
148
|
-
html += '</a>';
|
|
149
|
-
html += '</li>';
|
|
150
|
-
return html;
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Close the modal, resume body scrolling
|
|
155
|
-
* no param
|
|
156
|
-
*/
|
|
157
|
-
self.close = function() {
|
|
158
|
-
self.open = false;
|
|
159
|
-
self.dom.container.fadeOut();
|
|
160
|
-
self.dom.body.removeClass('modal-active');
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Searchform submit event handler
|
|
165
|
-
* @param queryText : (string) the query text
|
|
166
|
-
*/
|
|
167
|
-
self.onSubmit = function(event) {
|
|
168
|
-
event.preventDefault();
|
|
169
|
-
self.queryText = $(this).find('.u-search-input').val();
|
|
170
|
-
if (self.queryText) {
|
|
171
|
-
self.search(1);
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Start loading bar animation
|
|
177
|
-
* no param
|
|
178
|
-
*/
|
|
179
|
-
self.startLoading = function() {
|
|
180
|
-
self.dom.modal_loading_bar.show();
|
|
181
|
-
self.loadingTimer = setInterval(function() {
|
|
182
|
-
self.percentLoaded = Math.min(self.percentLoaded + 5, 95);
|
|
183
|
-
self.dom.modal_loading_bar.css('width', self.percentLoaded + '%');
|
|
184
|
-
}, 100);
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Stop loading bar animation
|
|
189
|
-
* no param
|
|
190
|
-
*/
|
|
191
|
-
self.stopLoading = function() {
|
|
192
|
-
clearInterval(self.loadingTimer);
|
|
193
|
-
self.dom.modal_loading_bar.css('width', '100%');
|
|
194
|
-
self.dom.modal_loading_bar.fadeOut();
|
|
195
|
-
setTimeout(function() {
|
|
196
|
-
self.percentLoaded = 0;
|
|
197
|
-
self.dom.modal_loading_bar.css('width', '0%');
|
|
198
|
-
}, 300);
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Add service branding
|
|
203
|
-
* @param service {String} service name
|
|
204
|
-
*/
|
|
205
|
-
self.addLogo = function(service) {
|
|
206
|
-
var html = '';
|
|
207
|
-
if (self.config.brands[service] && self.config.brands[service].logo) {
|
|
208
|
-
html += '<a href=\'' + self.config.brands[service].url + '\' class=\'' + service + '\'>';
|
|
209
|
-
html += '<img src="' + self.config.imagePath + self.config.brands[service].logo + '" />';
|
|
210
|
-
html += '</a>';
|
|
211
|
-
self.dom.modal_logo.html(html);
|
|
212
|
-
}
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
self.destroy = function() {
|
|
216
|
-
self.dom.form.each(function(index, elem) {
|
|
217
|
-
$(elem).off('submit');
|
|
218
|
-
});
|
|
219
|
-
self.dom.modal_overlay.off('click');
|
|
220
|
-
self.dom.btn_close.off('click');
|
|
221
|
-
self.dom.btn_next.off('click');
|
|
222
|
-
self.dom.btn_prev.off('click');
|
|
223
|
-
self.dom.container.remove();
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* Load template and register event handlers
|
|
228
|
-
* no param
|
|
229
|
-
*/
|
|
230
|
-
self.init = function() {
|
|
231
|
-
$('body').append(template);
|
|
232
|
-
self.parseSelectors();
|
|
233
|
-
self.dom.modal_footer.show();
|
|
234
|
-
self.dom.form.each(function(index, elem) {
|
|
235
|
-
$(elem).on('submit', self.onSubmit);
|
|
236
|
-
});
|
|
237
|
-
self.dom.modal_overlay.on('click', self.close);
|
|
238
|
-
self.dom.btn_close.on('click', self.close);
|
|
239
|
-
self.dom.btn_next.on('click', self.nextPage);
|
|
240
|
-
self.dom.btn_prev.on('click', self.prevPage);
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
self.init();
|
|
96
|
+
});
|
|
97
|
+
return html;
|
|
244
98
|
};
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
(
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
* Credit to: http://hahack.com/codes/local-search-engine-for-hexo/
|
|
267
|
-
* @param post : the post object
|
|
268
|
-
* @param queryText : the search query
|
|
269
|
-
*/
|
|
270
|
-
self.contentSearch = function(post, queryText) {
|
|
271
|
-
var post_title = post.title.trim().toLowerCase();
|
|
272
|
-
var post_content = post.text.trim().toLowerCase();
|
|
273
|
-
var keywords = queryText.trim().toLowerCase().split(' ');
|
|
274
|
-
var foundMatch = false;
|
|
275
|
-
var index_title = -1;
|
|
276
|
-
var index_content = -1;
|
|
277
|
-
var first_occur = -1;
|
|
278
|
-
if (post_title !== '' && post_content !== '') {
|
|
279
|
-
$.each(keywords, function(index, word) {
|
|
280
|
-
index_title = post_title.indexOf(word);
|
|
281
|
-
index_content = post_content.indexOf(word);
|
|
282
|
-
if (index_title < 0 && index_content < 0) {
|
|
283
|
-
foundMatch = false;
|
|
284
|
-
} else {
|
|
285
|
-
foundMatch = true;
|
|
286
|
-
if (index_content < 0) {
|
|
287
|
-
index_content = 0;
|
|
288
|
-
}
|
|
289
|
-
if (index === 0) {
|
|
290
|
-
first_occur = index_content;
|
|
291
|
-
}
|
|
99
|
+
fn.contentSearch = (post) => {
|
|
100
|
+
let post_title = post.title.trim().toLowerCase();
|
|
101
|
+
let post_content = post.text.trim().toLowerCase();
|
|
102
|
+
let keywords = fn.queryText
|
|
103
|
+
.trim()
|
|
104
|
+
.toLowerCase()
|
|
105
|
+
.split(/[-\s]+/);
|
|
106
|
+
let foundMatch = false;
|
|
107
|
+
let index_title = -1;
|
|
108
|
+
let index_content = -1;
|
|
109
|
+
let first_occur = -1;
|
|
110
|
+
if (post_title && post_content) {
|
|
111
|
+
keywords.forEach((word, index) => {
|
|
112
|
+
index_title = post_title.indexOf(word);
|
|
113
|
+
index_content = post_content.indexOf(word);
|
|
114
|
+
if (index_title < 0 && index_content < 0) {
|
|
115
|
+
foundMatch = false;
|
|
116
|
+
} else {
|
|
117
|
+
foundMatch = true;
|
|
118
|
+
if (index_content < 0) {
|
|
119
|
+
index_content = 0;
|
|
292
120
|
}
|
|
293
|
-
if (
|
|
294
|
-
|
|
295
|
-
var start = 0; var end = 0;
|
|
296
|
-
if (first_occur >= 0) {
|
|
297
|
-
start = Math.max(first_occur - 40, 0);
|
|
298
|
-
end = start === 0 ? Math.min(200, post_content.length) : Math.min(first_occur + 120, post_content.length);
|
|
299
|
-
var match_content = post_content.substring(start, end);
|
|
300
|
-
keywords.forEach(function(keyword) {
|
|
301
|
-
var regS = new RegExp(keyword, 'gi');
|
|
302
|
-
match_content = match_content.replace(regS, '<b mark>' + keyword + '</b>');
|
|
303
|
-
});
|
|
304
|
-
post.digest = match_content + '......';
|
|
305
|
-
} else {
|
|
306
|
-
end = Math.min(200, post_content.length);
|
|
307
|
-
post.digest = post_content.trim().substring(0, end);
|
|
308
|
-
}
|
|
121
|
+
if (index === 0) {
|
|
122
|
+
first_occur = index_content;
|
|
309
123
|
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
* Generate metadata after a successful query
|
|
331
|
-
* @param data : (object) the raw google custom search response data
|
|
332
|
-
*/
|
|
333
|
-
self.buildMetadata = function(data) {
|
|
334
|
-
self.dom.modal_footer.hide();
|
|
335
|
-
};
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* Send a GET request
|
|
339
|
-
* @param queryText : (string) the query text
|
|
340
|
-
* @param startIndex : (int) the index of first item (start from 1)
|
|
341
|
-
* @param callback : (function)
|
|
342
|
-
*/
|
|
343
|
-
self.query = function(queryText, startIndex, callback) {
|
|
344
|
-
if (!self.cache) {
|
|
345
|
-
$.get(self.config.endpoint, {
|
|
346
|
-
key : self.config.apiKey,
|
|
347
|
-
cx : self.config.engineId,
|
|
348
|
-
q : queryText,
|
|
349
|
-
start: startIndex,
|
|
350
|
-
num : self.config.per_page
|
|
351
|
-
}, function(data, status) {
|
|
352
|
-
if (status !== 'success'
|
|
353
|
-
|| !data
|
|
354
|
-
|| (!data.posts && !data.pages)
|
|
355
|
-
|| (data.posts.length < 1 && data.pages.length < 1)
|
|
356
|
-
) {
|
|
357
|
-
self.onQueryError(queryText, status);
|
|
124
|
+
}
|
|
125
|
+
if (foundMatch) {
|
|
126
|
+
post_content = post.text.trim();
|
|
127
|
+
let start = 0;
|
|
128
|
+
let end = 0;
|
|
129
|
+
if (first_occur >= 0) {
|
|
130
|
+
start = Math.max(first_occur - 40, 0);
|
|
131
|
+
end =
|
|
132
|
+
start === 0
|
|
133
|
+
? Math.min(200, post_content.length)
|
|
134
|
+
: Math.min(first_occur + 120, post_content.length);
|
|
135
|
+
let match_content = post_content.substring(start, end);
|
|
136
|
+
keywords.forEach(function (keyword) {
|
|
137
|
+
let regS = new RegExp(keyword, "gi");
|
|
138
|
+
match_content = match_content.replace(
|
|
139
|
+
regS,
|
|
140
|
+
"<b mark>" + keyword + "</b>"
|
|
141
|
+
);
|
|
142
|
+
});
|
|
143
|
+
post.digest = match_content + "......";
|
|
358
144
|
} else {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
results += self.buildResultList(data.pages, queryText);
|
|
362
|
-
results += self.buildResultList(data.posts, queryText);
|
|
363
|
-
self.dom.modal_results.html(results);
|
|
364
|
-
}
|
|
365
|
-
self.buildMetadata(data);
|
|
366
|
-
if (callback) {
|
|
367
|
-
callback(data);
|
|
145
|
+
end = Math.min(200, post_content.length);
|
|
146
|
+
post.digest = post_content.trim().substring(0, end);
|
|
368
147
|
}
|
|
369
|
-
});
|
|
370
|
-
} else {
|
|
371
|
-
var results = '';
|
|
372
|
-
results += self.buildResultList(self.cache.pages, queryText);
|
|
373
|
-
results += self.buildResultList(self.cache.posts, queryText);
|
|
374
|
-
self.dom.modal_results.html(results);
|
|
375
|
-
self.buildMetadata(self.cache);
|
|
376
|
-
if (callback) {
|
|
377
|
-
callback(self.cache);
|
|
378
148
|
}
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
return self;
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
return foundMatch;
|
|
383
152
|
};
|
|
384
|
-
|
|
385
|
-
|
|
153
|
+
fn.buildResult = (url, title, digest) => {
|
|
154
|
+
let result = fn.getUrlRelativePath(url);
|
|
155
|
+
let html = "";
|
|
156
|
+
html += "<li>";
|
|
157
|
+
html +=
|
|
158
|
+
"<a class='result' href='" + result + "?keyword=" + fn.queryText + "'>";
|
|
159
|
+
html += "<span class='title'>" + title + "</span>";
|
|
160
|
+
if (digest !== "") html += "<span class='digest'>" + digest + "</span>";
|
|
161
|
+
html += "</a>";
|
|
162
|
+
html += "</li>";
|
|
163
|
+
return html;
|
|
164
|
+
};
|
|
165
|
+
fn.getUrlRelativePath = function (url) {
|
|
166
|
+
let arrUrl = url.split("//");
|
|
167
|
+
let start = arrUrl[1].indexOf("/");
|
|
168
|
+
let relUrl = arrUrl[1].substring(start);
|
|
169
|
+
if (relUrl.indexOf("?") != -1) {
|
|
170
|
+
relUrl = relUrl.split("?")[0];
|
|
171
|
+
}
|
|
172
|
+
return relUrl;
|
|
173
|
+
};
|
|
174
|
+
return {
|
|
175
|
+
init: () => {
|
|
176
|
+
fn.init();
|
|
177
|
+
},
|
|
178
|
+
setQueryText: (queryText) => {
|
|
179
|
+
fn.queryText = queryText;
|
|
180
|
+
},
|
|
181
|
+
search: () => {
|
|
182
|
+
fn.search();
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
})();
|
|
186
|
+
Object.freeze(SearchService);
|
|
187
|
+
|
|
188
|
+
SearchService.init();
|
|
189
|
+
document.addEventListener("pjax:success", SearchService.init);
|
|
190
|
+
document.addEventListener("pjax:send", function () {
|
|
191
|
+
document.querySelector("#u-search").style.display = "none";
|
|
192
|
+
});
|