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.
Files changed (309) hide show
  1. package/README.md +6 -4
  2. package/_config.yml +599 -246
  3. package/languages/en.yml +7 -0
  4. package/languages/zh-CN.yml +13 -2
  5. package/languages/zh-TW.yml +7 -0
  6. package/layout/404.ejs +1 -1
  7. package/layout/_meta/author.ejs +4 -4
  8. package/layout/_meta/category.ejs +11 -8
  9. package/layout/_meta/counter.ejs +29 -7
  10. package/layout/_meta/date.ejs +1 -1
  11. package/layout/_meta/music.ejs +1 -1
  12. package/layout/_meta/share.ejs +1 -1
  13. package/layout/_meta/tags.ejs +3 -0
  14. package/layout/_meta/thumbnail.ejs +3 -1
  15. package/layout/_meta/updated.ejs +1 -1
  16. package/layout/_meta/walinecount.ejs +2 -1
  17. package/layout/{_cover → _partial/_cover}/blank.ejs +0 -0
  18. package/layout/{_cover → _partial/_cover}/dock.ejs +1 -1
  19. package/layout/{_cover → _partial/_cover}/featured.ejs +1 -1
  20. package/layout/{_cover → _partial/_cover}/focus.ejs +1 -1
  21. package/layout/_partial/_cover/layout.ejs +8 -0
  22. package/layout/{_cover → _partial/_cover}/search.ejs +2 -2
  23. package/layout/_partial/archive.ejs +2 -2
  24. package/layout/_partial/article.ejs +21 -16
  25. package/layout/_partial/categories.ejs +1 -1
  26. package/layout/_partial/cover.ejs +8 -28
  27. package/layout/_partial/footer.ejs +19 -11
  28. package/layout/_partial/head.ejs +70 -116
  29. package/layout/_partial/header.ejs +17 -11
  30. package/layout/_partial/meta.ejs +18 -4
  31. package/layout/_partial/post.ejs +35 -9
  32. package/layout/_partial/scripts/_ctrl/cdnCtrl.ejs +126 -0
  33. package/layout/_partial/scripts/{coverCtrl.ejs → _ctrl/coverCtrl.ejs} +17 -25
  34. package/layout/_partial/scripts/_ctrl.ejs +2 -0
  35. package/layout/_partial/scripts/content-visibility-scroll-fix.ejs +88 -0
  36. package/layout/_partial/scripts/global.ejs +422 -109
  37. package/layout/_partial/scripts/index.ejs +91 -46
  38. package/layout/_partial/scripts/toc.ejs +98 -68
  39. package/layout/_partial/side.ejs +4 -1
  40. package/layout/_plugins/_page_plugins/artitalk/index.ejs +15 -0
  41. package/layout/_plugins/_page_plugins/bbtalk/index.ejs +10 -0
  42. package/layout/_plugins/_page_plugins/fcircle/index.ejs +12 -0
  43. package/layout/_plugins/_page_plugins/gitter/index.ejs +14 -0
  44. package/layout/_plugins/_page_plugins/indent/index.ejs +16 -0
  45. package/layout/_plugins/_page_plugins/index.ejs +27 -0
  46. package/layout/_plugins/_page_plugins/katex/index.ejs +13 -0
  47. package/layout/{_third-party/math/mathjax/script.ejs → _plugins/_page_plugins/mathjax/index.ejs} +2 -2
  48. package/layout/_plugins/_page_plugins/snackbar/index.ejs +55 -0
  49. package/layout/{_partial/scripts/counter.ejs → _plugins/analytics/LCCounter.ejs} +0 -0
  50. package/layout/{_third-party → _plugins}/analytics/script.ejs +43 -5
  51. package/layout/{_third-party → _plugins}/aplayer/layout.ejs +0 -0
  52. package/layout/_plugins/aplayer/script.ejs +74 -0
  53. package/layout/_plugins/chat/gitter/script.ejs +17 -0
  54. package/layout/_plugins/chat/index.ejs +1 -0
  55. package/layout/_plugins/chat/tidio/script.ejs +1 -0
  56. package/layout/_plugins/comments/artalk/script.ejs +59 -0
  57. package/layout/_plugins/comments/beaudar/script.ejs +61 -0
  58. package/layout/_plugins/comments/discuss/script.ejs +30 -0
  59. package/layout/_plugins/comments/disqus/script.ejs +98 -0
  60. package/layout/_plugins/comments/disqusjs/script.ejs +35 -0
  61. package/layout/_plugins/comments/giscus/script.ejs +47 -0
  62. package/layout/_plugins/comments/gitalk/script.ejs +24 -0
  63. package/layout/_plugins/comments/hashover/script.ejs +5 -0
  64. package/layout/{_third-party → _plugins}/comments/index.ejs +10 -3
  65. package/layout/_plugins/comments/isso/script.ejs +27 -0
  66. package/layout/_plugins/comments/livere/script.ejs +15 -0
  67. package/layout/_plugins/comments/twikoo/script.ejs +40 -0
  68. package/layout/_plugins/comments/utterances/script.ejs +43 -0
  69. package/layout/_plugins/comments/vssue/script.ejs +37 -0
  70. package/layout/_plugins/comments/waline/script.ejs +62 -0
  71. package/layout/_plugins/comments/z-custom/script.ejs +1 -0
  72. package/layout/_plugins/darkmode/script.ejs +114 -0
  73. package/layout/{_third-party → _plugins}/end-of-support/script.ejs +25 -8
  74. package/layout/_plugins/github-api/script.ejs +27 -0
  75. package/layout/_plugins/highlight/highlightjs/script.ejs +26 -0
  76. package/layout/_plugins/highlight/prismjs/script.ejs +25 -0
  77. package/layout/_plugins/highlight/script.ejs +1 -0
  78. package/layout/{_third-party → _plugins}/lazyload/script.ejs +1 -1
  79. package/layout/{_third-party → _plugins}/nodewaves/script.ejs +1 -1
  80. package/layout/_plugins/parallax/script.ejs +74 -0
  81. package/layout/{_third-party → _plugins}/pjax/animate.ejs +31 -31
  82. package/layout/_plugins/pjax/index.ejs +73 -0
  83. package/layout/_plugins/pjax/pdata.ejs +56 -0
  84. package/layout/{_third-party → _plugins}/preload/script.ejs +3 -3
  85. package/layout/_plugins/rightmenu/layout.ejs +119 -0
  86. package/layout/_plugins/rightmenus/layout.ejs +137 -0
  87. package/layout/_plugins/scrollreveal/script.ejs +25 -0
  88. package/layout/_plugins/search/script.ejs +50 -0
  89. package/layout/{_third-party → _plugins}/share/layout.ejs +0 -0
  90. package/layout/_plugins/swiper/script.ejs +37 -0
  91. package/layout/_pre.ejs +2 -2
  92. package/layout/_widget/_pre.ejs +5 -0
  93. package/layout/_widget/blogger.ejs +1 -1
  94. package/layout/_widget/category.ejs +2 -2
  95. package/layout/_widget/copyright.ejs +1 -1
  96. package/layout/_widget/grid.ejs +3 -3
  97. package/layout/_widget/lastupdate.ejs +27 -0
  98. package/layout/_widget/list.ejs +2 -2
  99. package/layout/_widget/load.ejs +18 -0
  100. package/layout/_widget/music.ejs +3 -2
  101. package/layout/_widget/page.ejs +1 -1
  102. package/layout/_widget/qrcode.ejs +1 -1
  103. package/layout/_widget/related_posts.ejs +1 -1
  104. package/layout/_widget/tagcloud.ejs +1 -1
  105. package/layout/_widget/text.ejs +1 -1
  106. package/layout/_widget/toc.ejs +6 -2
  107. package/layout/_widget/webinfo.ejs +13 -76
  108. package/layout/archive.ejs +4 -4
  109. package/layout/category.ejs +9 -4
  110. package/layout/docs.ejs +1 -1
  111. package/layout/friends.ejs +6 -25
  112. package/layout/index.ejs +1 -1
  113. package/layout/layout.ejs +30 -12
  114. package/layout/list.ejs +1 -1
  115. package/layout/page.ejs +1 -1
  116. package/layout/post.ejs +1 -1
  117. package/layout/tag.ejs +8 -3
  118. package/package.json +5 -3
  119. package/scripts/events/index.js +13 -0
  120. package/scripts/events/lib/check-configuration.js +43 -0
  121. package/scripts/events/lib/check-environment.js +74 -0
  122. package/scripts/events/lib/config.js +34 -9
  123. package/scripts/events/lib/render-stylus.js +78 -0
  124. package/scripts/events/lib/stellar-tag-utils.js +76 -0
  125. package/scripts/filters/content-visibility.js +25 -0
  126. package/scripts/{render → filters}/img.js +0 -0
  127. package/scripts/filters/replace.js +15 -0
  128. package/scripts/{z-lazyload/lib/process.js → filters/z-lazyload.js} +6 -3
  129. package/scripts/helpers/custom-files.js +165 -0
  130. package/scripts/helpers/first-style.js +19 -0
  131. package/scripts/helpers/head/autoCanonical.js +15 -0
  132. package/scripts/helpers/head/generate_preload_fontfamily.js +22 -0
  133. package/scripts/helpers/head/generate_seo.js +24 -0
  134. package/scripts/helpers/head/generate_title__keywords__description.js +101 -0
  135. package/scripts/{related_posts/index.js → helpers/related-posts.js} +1 -1
  136. package/scripts/helpers/revisioned.js +158 -0
  137. package/scripts/helpers/structured-data/index.js +2 -0
  138. package/scripts/helpers/structured-data/lib/blogposting.js +77 -0
  139. package/scripts/helpers/structured-data/lib/breadcrumblist.js +152 -0
  140. package/scripts/helpers/structured-data/lib/config.js +31 -0
  141. package/scripts/helpers/structured-data/lib/index.js +30 -0
  142. package/scripts/helpers/structured-data/lib/organization.js +15 -0
  143. package/scripts/helpers/structured-data/lib/person.js +16 -0
  144. package/scripts/helpers/structured-data/lib/website.js +42 -0
  145. package/scripts/tags/btn.js +6 -1
  146. package/scripts/tags/btns.js +7 -2
  147. package/scripts/tags/checkbox.js +12 -2
  148. package/scripts/tags/contributors.js +100 -0
  149. package/scripts/tags/dropmenu.js +18 -3
  150. package/scripts/tags/fancybox.js +44 -10
  151. package/scripts/tags/folding.js +6 -1
  152. package/scripts/tags/frame.js +6 -1
  153. package/scripts/tags/friends.js +99 -0
  154. package/scripts/tags/ghcard.js +6 -1
  155. package/scripts/tags/image.js +14 -2
  156. package/scripts/tags/link.js +6 -1
  157. package/scripts/tags/md.js +59 -0
  158. package/scripts/tags/media.js +25 -1
  159. package/scripts/tags/note.js +36 -3
  160. package/scripts/tags/site.js +87 -51
  161. package/scripts/tags/span.js +12 -2
  162. package/scripts/tags/swiper.js +38 -0
  163. package/scripts/tags/tabs.js +33 -3
  164. package/scripts/tags/timeline.js +6 -1
  165. package/source/css/Readme.md +28 -0
  166. package/source/css/_defines/AutoPrefixCSS.styl +347 -0
  167. package/source/css/_defines/Readme.md +3 -0
  168. package/source/css/_defines/color.styl +41 -1
  169. package/source/css/_defines/effect.styl +0 -13
  170. package/source/css/_defines/fonts.styl +17 -18
  171. package/source/css/_defines/func.styl +12 -30
  172. package/source/css/_first/base_first.styl +118 -0
  173. package/source/css/_first/{cover.styl → cover_first.styl} +113 -87
  174. package/source/css/_first/dark_first.styl +76 -0
  175. package/source/css/_first/fontfamily_first.styl +17 -0
  176. package/source/css/_first/{navbar.styl → navbar_first.styl} +4 -10
  177. package/source/css/_first/search_first.styl +12 -0
  178. package/source/css/{_base/index.styl → _style/_base/base.styl} +9 -93
  179. package/source/css/_style/_base/fontfamily_async.styl +8 -0
  180. package/source/css/{_layout → _style/_layout}/archive.styl +0 -0
  181. package/source/css/{_layout → _style/_layout}/article.styl +3 -30
  182. package/source/css/{_layout → _style/_layout}/footer.styl +0 -0
  183. package/source/css/_style/_layout/friends-simpleuser.styl +23 -0
  184. package/source/css/_style/_layout/friends-traditional.styl +81 -0
  185. package/source/css/{_layout → _style/_layout}/img.styl +0 -0
  186. package/source/css/_style/_layout/loading.styl +14 -0
  187. package/source/css/{_layout → _style/_layout}/main.styl +19 -7
  188. package/source/css/{_layout → _style/_layout}/md.styl +0 -0
  189. package/source/css/{_layout → _style/_layout}/pagination.styl +1 -1
  190. package/source/css/{_layout → _style/_layout}/posts.styl +2 -0
  191. package/source/css/{_first → _style/_layout}/search.styl +0 -103
  192. package/source/css/{_layout → _style/_layout}/sidebar.styl +23 -3
  193. package/source/css/{_layout → _style/_layout}/snackbar.styl +0 -0
  194. package/source/css/{_layout → _style/_layout}/toc.styl +3 -3
  195. package/source/css/{_layout → _style/_layout}/video.styl +0 -0
  196. package/source/css/_style/_plugins/_dark/dark_async.styl +41 -0
  197. package/source/css/_style/_plugins/_dark/dark_plugins.styl +136 -0
  198. package/source/css/_style/_plugins/_highlight/highlightjs/clipboard.styl +36 -0
  199. package/source/css/_style/_plugins/_highlight/highlightjs/color.styl +96 -0
  200. package/source/css/_style/_plugins/_highlight/highlightjs/index.styl +102 -0
  201. package/source/css/_style/_plugins/_highlight/highlightjs/language.styl +63 -0
  202. package/source/css/_style/_plugins/_highlight/index.styl +1 -0
  203. package/source/css/_style/_plugins/_highlight/prismjs/clipboard.styl +33 -0
  204. package/source/css/_style/_plugins/_highlight/prismjs/index.styl +8 -0
  205. package/source/css/_style/_plugins/_highlight/prismjs/language.styl +63 -0
  206. package/source/css/_style/_plugins/_rightmenu/reading.styl +56 -0
  207. package/source/css/{_plugins → _style/_plugins/_rightmenu}/rightmenu.styl +22 -2
  208. package/source/css/{_plugins → _style/_plugins}/aplayer.styl +8 -1
  209. package/source/css/{_plugins → _style/_plugins}/cursor.styl +49 -19
  210. package/source/css/_style/_plugins/fontcolor.styl +84 -0
  211. package/source/css/{_plugins → _style/_plugins}/gitalk.styl +0 -0
  212. package/source/css/_style/_plugins/index.styl +24 -0
  213. package/source/css/{_plugins → _style/_plugins}/mathjax.styl +0 -0
  214. package/source/css/_style/_plugins/message.styl +14 -0
  215. package/source/css/{_plugins → _style/_plugins}/pjaxanimate.styl +0 -0
  216. package/source/css/_style/_tag-plugins/Readme.md +6 -0
  217. package/source/css/{_tag-plugins → _style/_tag-plugins}/btns.styl +0 -0
  218. package/source/css/{_tag-plugins → _style/_tag-plugins}/checkbox.styl +0 -0
  219. package/source/css/{_tag-plugins → _style/_tag-plugins}/dropmenu.styl +0 -0
  220. package/source/css/{_plugins → _style/_tag-plugins}/fancybox.styl +8 -9
  221. package/source/css/{_tag-plugins → _style/_tag-plugins}/folding.styl +0 -0
  222. package/source/css/{_tag-plugins → _style/_tag-plugins}/frame.styl +0 -0
  223. package/source/css/_style/_tag-plugins/friends.styl +72 -0
  224. package/source/css/{_tag-plugins → _style/_tag-plugins}/ghcard.styl +0 -0
  225. package/source/css/{_tag-plugins → _style/_tag-plugins}/image.styl +0 -0
  226. package/source/css/{_tag-plugins → _style/_tag-plugins}/link.styl +0 -0
  227. package/source/css/{_tag-plugins → _style/_tag-plugins}/media.styl +0 -0
  228. package/source/css/{_tag-plugins → _style/_tag-plugins}/note.styl +0 -0
  229. package/source/css/_style/_tag-plugins/sites.styl +87 -0
  230. package/source/css/{_tag-plugins → _style/_tag-plugins}/span.styl +0 -0
  231. package/source/css/_style/_tag-plugins/swiper.styl +44 -0
  232. package/source/css/{_tag-plugins → _style/_tag-plugins}/table.styl +0 -0
  233. package/source/css/{_tag-plugins → _style/_tag-plugins}/tabs.styl +0 -0
  234. package/source/css/_style/_tag-plugins/tag.json +35 -0
  235. package/source/css/_style/_tag-plugins/text.styl +31 -0
  236. package/source/css/{_tag-plugins → _style/_tag-plugins}/timeline.styl +0 -0
  237. package/source/css/_style/index.styl +8 -0
  238. package/source/css/first.styl +17 -6
  239. package/source/css/style.styl +9 -7
  240. package/source/js/app.js +1051 -278
  241. package/source/js/plugins/aplayer.js +186 -0
  242. package/source/js/plugins/parallax.js +191 -0
  243. package/source/js/plugins/rightMenu.js +577 -0
  244. package/source/js/plugins/rightMenus.js +616 -0
  245. package/source/js/plugins/tags/contributors.js +92 -0
  246. package/source/js/plugins/tags/friends.js +93 -0
  247. package/source/js/plugins/tags/sites.js +96 -0
  248. package/source/js/search/hexo.js +180 -373
  249. package/.eslintrc.json +0 -111
  250. package/layout/_meta/valinecount.ejs +0 -15
  251. package/layout/_partial/rightmenu.ejs +0 -199
  252. package/layout/_partial/scripts/cover.ejs +0 -45
  253. package/layout/_partial/scripts/darkmode.ejs +0 -85
  254. package/layout/_partial/scripts/import.ejs +0 -3
  255. package/layout/_partial/scripts/issues.ejs +0 -18
  256. package/layout/_partial/scripts/search.ejs +0 -62
  257. package/layout/_partial/snackbar.ejs +0 -22
  258. package/layout/_third-party/aplayer/script.ejs +0 -26
  259. package/layout/_third-party/clipboard/script.ejs +0 -54
  260. package/layout/_third-party/comments/disqus/layout.ejs +0 -5
  261. package/layout/_third-party/comments/disqus/script.ejs +0 -90
  262. package/layout/_third-party/comments/disqusjs/layout.ejs +0 -1
  263. package/layout/_third-party/comments/disqusjs/script.ejs +0 -34
  264. package/layout/_third-party/comments/gitalk/layout.ejs +0 -1
  265. package/layout/_third-party/comments/gitalk/script.ejs +0 -22
  266. package/layout/_third-party/comments/hashover/layout.ejs +0 -2
  267. package/layout/_third-party/comments/hashover/script.ejs +0 -1
  268. package/layout/_third-party/comments/isso/layout.ejs +0 -1
  269. package/layout/_third-party/comments/isso/script.ejs +0 -1
  270. package/layout/_third-party/comments/livere/layout.ejs +0 -3
  271. package/layout/_third-party/comments/livere/script.ejs +0 -10
  272. package/layout/_third-party/comments/minivaline/layout.ejs +0 -3
  273. package/layout/_third-party/comments/minivaline/script.ejs +0 -34
  274. package/layout/_third-party/comments/twikoo/layout.ejs +0 -3
  275. package/layout/_third-party/comments/twikoo/script.ejs +0 -32
  276. package/layout/_third-party/comments/valine/layout.ejs +0 -3
  277. package/layout/_third-party/comments/valine/script.ejs +0 -49
  278. package/layout/_third-party/comments/vssue/layout.ejs +0 -1
  279. package/layout/_third-party/comments/vssue/script.ejs +0 -21
  280. package/layout/_third-party/comments/waline/layout.ejs +0 -3
  281. package/layout/_third-party/comments/waline/script.ejs +0 -33
  282. package/layout/_third-party/fancybox/script.ejs +0 -61
  283. package/layout/_third-party/highlightjs/script.ejs +0 -11
  284. package/layout/_third-party/pjax/index.ejs +0 -78
  285. package/layout/_third-party/pjax/pdata.ejs +0 -53
  286. package/layout/_third-party/scrollreveal/script.ejs +0 -21
  287. package/layout/_third-party/tidio/script.ejs +0 -3
  288. package/layout/artitalk.ejs +0 -13
  289. package/layout/bb.ejs +0 -10
  290. package/package-lock.json +0 -916
  291. package/scripts/tags/issues.js +0 -41
  292. package/scripts/z-lazyload/index.js +0 -4
  293. package/source/css/_highlight/index.styl +0 -316
  294. package/source/css/_layout/friends.styl +0 -79
  295. package/source/css/_plugins/clipboard.styl +0 -37
  296. package/source/css/_plugins/dark.styl +0 -149
  297. package/source/css/_plugins/darkmode.styl +0 -9
  298. package/source/css/_plugins/index.styl +0 -18
  299. package/source/css/_plugins/twikoo.styl +0 -21
  300. package/source/css/_plugins/valine.styl +0 -183
  301. package/source/css/_tag-plugins/simpleuser.styl +0 -21
  302. package/source/css/_tag-plugins/site-card.styl +0 -70
  303. package/source/js/aplayer.js +0 -167
  304. package/source/js/issues.js +0 -186
  305. package/source/js/search/algolia.js +0 -344
  306. package/source/js/search/azure.js +0 -355
  307. package/source/js/search/baidu.js +0 -340
  308. package/source/js/search/google.js +0 -339
  309. package/source/js/valine.js +0 -5137
@@ -1,385 +1,192 @@
1
- var SearchService = '';
2
-
3
- (function($) {
4
-
5
- /**
6
- * A super class of common logics for all search services
7
- * @param options : (object)
8
- */
9
- SearchService = function(options) {
10
- var self = this;
11
-
12
- self.config = $.extend({
13
- per_page : 10,
14
- selectors: {
15
- body : 'body',
16
- form : '.u-search-form',
17
- input : '.u-search-input',
18
- container : '#u-search',
19
- modal : '#u-search .modal',
20
- modal_body : '#u-search .modal-body',
21
- modal_footer : '#u-search .modal-footer',
22
- modal_overlay : '#u-search .modal-overlay',
23
- modal_results : '#u-search .modal-results',
24
- modal_metadata : '#u-search .modal-metadata',
25
- modal_error : '#u-search .modal-error',
26
- modal_loading_bar : '#u-search .modal-loading-bar',
27
- modal_ajax_content: '#u-search .modal-ajax-content',
28
- modal_logo : '#u-search .modal-footer .logo',
29
- btn_close : '#u-search .btn-close',
30
- btn_next : '#u-search .btn-next',
31
- btn_prev : '#u-search .btn-prev'
32
- },
33
- brands: {
34
- 'hexo' : {logo: '', url: ''},
35
- 'google' : {logo: 'google.svg', url: 'https://cse.google.com'},
36
- 'algolia': {logo: 'algolia.svg', url: 'https://www.algolia.com'},
37
- 'baidu' : {logo: 'baidu.svg', url: 'http://zn.baidu.com/cse/home/index'},
38
- 'azure' : {logo: 'azure.svg', url: 'https://azure.microsoft.com/en-us/services/search/'}
39
- },
40
- imagePath: 'https://cdn.jsdelivr.net/gh/volantis-x/cdn-volantis@master/img/logo/'
41
- }, options);
42
-
43
- self.dom = {};
44
- self.percentLoaded = 0;
45
- self.open = false;
46
- self.queryText = '';
47
- self.nav = {
48
- next : -1,
49
- prev : -1,
50
- total : 0,
51
- current: 1
52
- };
53
-
54
- self.parseSelectors = function() {
55
- for (var key in self.config.selectors) {
56
- self.dom[key] = $(self.config.selectors[key]);
57
- }
58
- };
59
-
60
- self.beforeQuery = function() {
61
- if (!self.open) {
62
- self.dom.container.fadeIn();
63
- // self.dom.body.addClass('modal-active');
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
- self.dom.input.each(function(index, elem) {
67
- $(elem).val(self.queryText);
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
- document.activeElement.blur();
70
- self.dom.modal_error.hide();
71
- self.dom.modal_ajax_content.removeClass('loaded');
72
- self.startLoading();
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
- 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="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>';
247
- })(jQuery);
248
-
249
- var HexoSearch;
250
- (function($) {
251
- 'use strict';
252
-
253
- /**
254
- * Search by Hexo generator json content
255
- * @param options : (object)
256
- */
257
- HexoSearch = function(options) {
258
- SearchService.apply(this, arguments);
259
- var self = this;
260
- self.config.endpoint = ROOT + ((options || {}).endpoint || 'content.json');
261
- self.config.endpoint = self.config.endpoint.replace('//', '/'); //make sure the url is correct
262
- self.cache = '';
263
-
264
- /**
265
- * Search queryText in title and content of a post
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 (foundMatch) {
294
- post_content = post.text.trim();
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
- return foundMatch;
313
- };
314
-
315
- /**
316
- * Generate result list html
317
- * @param data : (array) result items
318
- */
319
- self.buildResultList = function(data, queryText) {
320
- var results = [];
321
- var html = '';
322
- $.each(data, function(index, post) {
323
- if (self.contentSearch(post, queryText)) { html += self.buildResult(post.permalink, post.title, post.digest); }
324
- });
325
- html += '<script>try{pjax.refresh(document.querySelector(\'#u-search\'));document.addEventListener(\'pjax:send\',function(){$(\'#u-search\').fadeOut(500);$(\'body\').removeClass(\'modal-active\')});}catch(e){$(\'#u-search\').fadeOut(500);}</script>';
326
- return html;
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
- self.cache = data;
360
- var results = '';
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
- })(jQuery);
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
+ });