hexo-theme-stellar 1.26.8 → 1.28.0

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 (154) hide show
  1. package/_config.yml +139 -95
  2. package/_data/icons.yml +8 -1
  3. package/_data/widgets.yml +19 -7
  4. package/languages/en.yml +5 -2
  5. package/languages/zh-CN.yml +4 -1
  6. package/languages/zh-TW.yml +5 -2
  7. package/layout/404.ejs +1 -1
  8. package/layout/_partial/{plugins/comments → comments}/artalk/script.ejs +2 -2
  9. package/layout/_partial/{plugins/comments/utterances → comments/giscus}/layout.ejs +5 -2
  10. package/layout/_partial/{plugins/comments → comments}/giscus/script.ejs +1 -4
  11. package/layout/_partial/{plugins/comments → comments}/layout.ejs +14 -9
  12. package/layout/_partial/{plugins/comments → comments}/twikoo/script.ejs +1 -1
  13. package/layout/_partial/comments/waline/script.ejs +43 -0
  14. package/layout/_partial/head.ejs +2 -2
  15. package/layout/_partial/main/article/article_footer.ejs +1 -1
  16. package/layout/_partial/main/footer.ejs +1 -1
  17. package/layout/_partial/main/navbar/article_banner.ejs +81 -17
  18. package/layout/_partial/main/navbar/ghinfo.ejs +1 -1
  19. package/layout/_partial/main/post_list/post_card.ejs +1 -1
  20. package/layout/_partial/menubtn.ejs +6 -3
  21. package/layout/_partial/scripts/defines.ejs +31 -0
  22. package/layout/_partial/scripts/services.ejs +29 -0
  23. package/layout/_partial/scripts/sidebar.ejs +25 -0
  24. package/layout/_partial/scripts/utils.ejs +158 -0
  25. package/layout/_partial/scripts.ejs +32 -0
  26. package/layout/_partial/sidebar/{index.ejs → index_leftbar.ejs} +22 -20
  27. package/layout/_partial/sidebar/index_rightbar.ejs +84 -0
  28. package/layout/_partial/sidebar/logo.ejs +1 -1
  29. package/layout/_partial/widgets/author.ejs +37 -0
  30. package/layout/_partial/widgets/components/edit.ejs +24 -0
  31. package/layout/_partial/widgets/ghissues.ejs +1 -1
  32. package/layout/_partial/widgets/ghrepo.ejs +2 -2
  33. package/layout/_partial/widgets/ghuser.ejs +2 -2
  34. package/layout/_partial/widgets/markdown.ejs +1 -1
  35. package/layout/_partial/widgets/recent.ejs +1 -5
  36. package/layout/_partial/widgets/related.ejs +1 -1
  37. package/layout/_partial/widgets/timeline.ejs +1 -1
  38. package/layout/_partial/widgets/toc.ejs +38 -85
  39. package/layout/_partial/widgets/tree.ejs +71 -0
  40. package/layout/_plugins/copycode.ejs +13 -0
  41. package/layout/_plugins/fancybox.ejs +32 -0
  42. package/layout/_plugins/heti.ejs +21 -0
  43. package/layout/_plugins/index.ejs +24 -0
  44. package/layout/_plugins/lazyload.ejs +21 -0
  45. package/layout/{_partial/plugins/parser/mathjax/script.ejs → _plugins/mathjax.ejs} +1 -1
  46. package/layout/_plugins/mermaid.ejs +29 -0
  47. package/layout/_plugins/preload.ejs +9 -0
  48. package/layout/_plugins/scrollreveal.ejs +15 -0
  49. package/layout/_plugins/search/algolia_search.ejs +13 -0
  50. package/layout/_plugins/search/local_search.ejs +8 -0
  51. package/layout/_plugins/swiper.ejs +26 -0
  52. package/layout/_plugins/tianli_gpt.ejs +14 -0
  53. package/layout/archive.ejs +9 -2
  54. package/layout/layout.ejs +9 -6
  55. package/layout/page.ejs +2 -10
  56. package/package.json +1 -1
  57. package/scripts/events/lib/doc_tree.js +8 -8
  58. package/scripts/events/lib/topic_tree.js +3 -0
  59. package/scripts/generators/author.js +3 -2
  60. package/scripts/helpers/parse_config.js +6 -5
  61. package/scripts/tags/lib/albums.js +2 -2
  62. package/scripts/tags/lib/button.js +1 -1
  63. package/scripts/tags/lib/emoji.js +1 -1
  64. package/scripts/tags/lib/friends.js +1 -1
  65. package/scripts/tags/lib/icon.js +10 -5
  66. package/scripts/tags/lib/link.js +2 -2
  67. package/scripts/tags/lib/md.js +1 -1
  68. package/scripts/tags/lib/posters.js +2 -2
  69. package/scripts/tags/lib/sites.js +1 -1
  70. package/scripts/tags/lib/timeline.js +2 -2
  71. package/source/css/_common/button.styl +8 -2
  72. package/source/css/_common/device.styl +39 -12
  73. package/source/css/_custom.styl +15 -16
  74. package/source/css/_defines/const.styl +1 -1
  75. package/source/css/_defines/func.styl +14 -4
  76. package/source/css/_defines/theme.styl +38 -27
  77. package/source/css/_layout/layout.styl +62 -27
  78. package/source/css/_layout/list.styl +1 -1
  79. package/source/css/_layout/main.styl +1 -4
  80. package/source/css/_layout/md.styl +16 -2
  81. package/source/css/_layout/pages/archives.styl +4 -0
  82. package/source/css/_layout/partial/article-banner.styl +14 -15
  83. package/source/css/_layout/partial/article-footer.styl +0 -5
  84. package/source/css/_layout/partial/footer.styl +9 -6
  85. package/source/css/_layout/partial/related.styl +4 -0
  86. package/source/css/_layout/sidebar/footer.styl +3 -1
  87. package/source/css/_layout/sidebar/logo.styl +3 -1
  88. package/source/css/_layout/sidebar/menu.styl +1 -1
  89. package/source/css/_layout/sidebar/nav-area.styl +1 -1
  90. package/source/css/_layout/sidebar/sidebar.styl +25 -16
  91. package/source/css/_layout/tag-plugins/banner.styl +1 -8
  92. package/source/css/_layout/tag-plugins/common.styl +10 -5
  93. package/source/css/_layout/tag-plugins/emoji.styl +1 -0
  94. package/source/css/_layout/tag-plugins/icon.styl +6 -0
  95. package/source/css/_layout/tag-plugins/image.styl +1 -1
  96. package/source/css/_layout/tag-plugins/quot.styl +1 -1
  97. package/source/css/_layout/tag-plugins/timeline.styl +26 -27
  98. package/source/css/_layout/widgets/ghrepo.styl +1 -1
  99. package/source/css/_layout/widgets/ghuser.styl +9 -5
  100. package/source/css/_layout/widgets/list.styl +4 -3
  101. package/source/css/_layout/widgets/related.styl +0 -1
  102. package/source/css/_layout/widgets/timeline.styl +27 -21
  103. package/source/css/_layout/widgets/toc.styl +182 -0
  104. package/source/css/_layout/widgets/tree.styl +0 -0
  105. package/source/css/_layout/widgets/widgets.styl +26 -7
  106. package/source/css/_plugins/comments/twikoo.styl +103 -59
  107. package/source/css/_plugins/comments/waline.styl +13 -10
  108. package/source/css/_plugins/index.styl +2 -0
  109. package/source/css/_plugins/katex.styl +5 -0
  110. package/source/css/_plugins/mermaid.styl +49 -59
  111. package/source/css/_plugins/tianli_gpt.styl +208 -151
  112. package/source/js/main.js +52 -251
  113. package/source/js/plugins/copycode.js +28 -41
  114. package/source/js/search/algolia-search.js +75 -0
  115. package/source/js/search/local-search.js +32 -0
  116. package/source/js/services/fcircle.js +36 -0
  117. package/source/js/services/friends.js +27 -0
  118. package/source/js/services/ghinfo.js +33 -0
  119. package/source/js/services/mdrender.js +10 -0
  120. package/source/js/services/memos.js +73 -0
  121. package/source/js/services/siteinfo.js +38 -0
  122. package/source/js/services/sites.js +30 -0
  123. package/source/js/services/timeline.js +106 -0
  124. package/source/js/services/weibo.js +60 -0
  125. package/layout/_partial/main/navbar/article_top_area.ejs +0 -35
  126. package/layout/_partial/main/navbar/author_banner.ejs +0 -29
  127. package/layout/_partial/plugins/ai/tianli_gpt.ejs +0 -9
  128. package/layout/_partial/plugins/comments/waline/script.ejs +0 -39
  129. package/layout/_partial/plugins/parser/head.ejs +0 -3
  130. package/layout/_partial/plugins/parser/katex/head.ejs +0 -3
  131. package/layout/_partial/plugins/parser/katex/script.ejs +0 -4
  132. package/layout/_partial/plugins/parser/mermaid/script.ejs +0 -29
  133. package/layout/_partial/plugins/parser/script.ejs +0 -9
  134. package/layout/_partial/scripts/index.ejs +0 -176
  135. package/source/css/_layout/widgets/toc_blog.styl +0 -3
  136. package/source/css/_layout/widgets/toc_common.styl +0 -92
  137. package/source/css/_layout/widgets/toc_wiki.styl +0 -62
  138. package/source/js/plugins/fcircle.js +0 -92
  139. package/source/js/plugins/friends.js +0 -84
  140. package/source/js/plugins/ghinfo.js +0 -85
  141. package/source/js/plugins/linkcard.js +0 -48
  142. package/source/js/plugins/marked.js +0 -50
  143. package/source/js/plugins/memos.js +0 -132
  144. package/source/js/plugins/sites.js +0 -87
  145. package/source/js/plugins/timeline.js +0 -162
  146. package/source/js/plugins/weibo.js +0 -116
  147. /package/layout/_partial/{plugins/comments → comments}/artalk/layout.ejs +0 -0
  148. /package/layout/_partial/{plugins/comments → comments}/beaudar/layout.ejs +0 -0
  149. /package/layout/_partial/{plugins/comments → comments}/beaudar/script.ejs +0 -0
  150. /package/layout/_partial/{plugins/comments → comments}/script.ejs +0 -0
  151. /package/layout/_partial/{plugins/comments → comments}/twikoo/layout.ejs +0 -0
  152. /package/layout/_partial/{plugins/comments/giscus → comments/utterances}/layout.ejs +0 -0
  153. /package/layout/_partial/{plugins/comments → comments}/utterances/script.ejs +0 -0
  154. /package/layout/_partial/{plugins/comments → comments}/waline/layout.ejs +0 -0
package/source/js/main.js CHANGED
@@ -1,4 +1,3 @@
1
- console.log('\n' + '%c Stellar v' + stellar.version + ' %c\n' + stellar.github + '\n', 'color:#e8fafe;background:#03c7fa;padding:8px;border-radius:4px', 'margin-top:8px');
2
1
  // utils
3
2
  const util = {
4
3
 
@@ -10,27 +9,23 @@ const util = {
10
9
  const minute = 1000 * 60
11
10
  const hour = minute * 60
12
11
  const day = hour * 24
13
- const month = day * 30
14
12
 
15
13
  let result
16
14
  if (more) {
17
- const monthCount = dateDiff / month
18
15
  const dayCount = dateDiff / day
19
16
  const hourCount = dateDiff / hour
20
17
  const minuteCount = dateDiff / minute
21
18
 
22
- if (monthCount > 12) {
19
+ if (dayCount > 14) {
23
20
  result = null
24
- } else if (monthCount >= 1) {
25
- result = parseInt(monthCount) + ' ' + stellar.config.date_suffix.month
26
21
  } else if (dayCount >= 1) {
27
- result = parseInt(dayCount) + ' ' + stellar.config.date_suffix.day
22
+ result = parseInt(dayCount) + ' ' + ctx.date_suffix.day
28
23
  } else if (hourCount >= 1) {
29
- result = parseInt(hourCount) + ' ' + stellar.config.date_suffix.hour
24
+ result = parseInt(hourCount) + ' ' + ctx.date_suffix.hour
30
25
  } else if (minuteCount >= 1) {
31
- result = parseInt(minuteCount) + ' ' + stellar.config.date_suffix.min
26
+ result = parseInt(minuteCount) + ' ' + ctx.date_suffix.min
32
27
  } else {
33
- result = stellar.config.date_suffix.just
28
+ result = ctx.date_suffix.just
34
29
  }
35
30
  } else {
36
31
  result = parseInt(dateDiff / day)
@@ -55,6 +50,14 @@ const util = {
55
50
  el.classList.toggle("display");
56
51
  }
57
52
  },
53
+
54
+ scrollTop: () => {
55
+ window.scrollTo({top: 0, behavior: "smooth"});
56
+ },
57
+
58
+ scrollComment: () => {
59
+ document.getElementById('comments').scrollIntoView({behavior: "smooth"});
60
+ },
58
61
  }
59
62
 
60
63
  const hud = {
@@ -76,73 +79,71 @@ const hud = {
76
79
 
77
80
  const l_body = document.querySelector('.l_body');
78
81
 
79
- const sidebar = {
80
- toggle: () => {
81
- if (l_body) {
82
- l_body.classList.add('mobile');
83
- l_body.classList.toggle("sidebar");
84
- }
85
- }
86
- }
87
82
 
88
83
  const init = {
89
84
  toc: () => {
90
- stellar.jQuery(() => {
85
+ utils.jq(() => {
91
86
  const scrollOffset = 32;
92
87
  var segs = [];
93
88
  $("article.md-text :header").each(function (idx, node) {
94
- segs.push(node)
89
+ segs.push(node);
95
90
  });
96
- // 定位到激活的目录树(不如pjax体验好)
97
- // const widgets = document.querySelector('.widgets')
98
- // const e1 = document.querySelector('.doc-tree-link.active')
99
- // const offsetTop = e1.getBoundingClientRect().top - widgets.getBoundingClientRect().top - 100
100
- // if (offsetTop > 0) {
101
- // widgets.scrollBy({top: offsetTop, behavior: 'smooth'})
102
- // }
103
- // 滚动
104
- $(document, window).scroll(function (e) {
91
+ function activeTOC() {
105
92
  var scrollTop = $(this).scrollTop();
106
- var topSeg = null
93
+ var topSeg = null;
107
94
  for (var idx in segs) {
108
- var seg = $(segs[idx])
95
+ var seg = $(segs[idx]);
109
96
  if (seg.offset().top > scrollTop + scrollOffset) {
110
- continue
97
+ continue;
111
98
  }
112
99
  if (!topSeg) {
113
- topSeg = seg
100
+ topSeg = seg;
114
101
  } else if (seg.offset().top >= topSeg.offset().top) {
115
- topSeg = seg
102
+ topSeg = seg;
116
103
  }
117
104
  }
118
105
  if (topSeg) {
119
- $("#data-toc a.toc-link").removeClass("active")
120
- var link = "#" + topSeg.attr("id")
106
+ $("#data-toc a.toc-link").removeClass("active");
107
+ var link = "#" + topSeg.attr("id");
121
108
  if (link != '#undefined') {
122
- const highlightItem = $('#data-toc a.toc-link[href="' + encodeURI(link) + '"]')
109
+ const highlightItem = $('#data-toc a.toc-link[href="' + encodeURI(link) + '"]');
123
110
  if (highlightItem.length > 0) {
124
- highlightItem.addClass("active")
125
- const e0 = document.querySelector('.widgets')
126
- const e1 = document.querySelector('#data-toc a.toc-link[href="' + encodeURI(link) + '"]')
127
- const offsetBottom = e1.getBoundingClientRect().bottom - e0.getBoundingClientRect().bottom + 200
128
- const offsetTop = e1.getBoundingClientRect().top - e0.getBoundingClientRect().top - 64
129
- if (offsetTop < 0) {
130
- e0.scrollBy(0, offsetTop)
131
- } else if (offsetBottom > 0) {
132
- e0.scrollBy(0, offsetBottom)
133
- }
111
+ highlightItem.addClass("active");
134
112
  }
135
113
  } else {
136
- $('#data-toc a.toc-link:first').addClass("active")
114
+ $('#data-toc a.toc-link:first').addClass("active");
137
115
  }
138
116
  }
139
- })
117
+ }
118
+ function scrollTOC() {
119
+ const e0 = document.querySelector('#data-toc .toc');
120
+ const e1 = document.querySelector('#data-toc .toc a.toc-link.active');
121
+ if (e0 == null || e1 == null) {
122
+ return;
123
+ }
124
+ const offsetBottom = e1.getBoundingClientRect().bottom - e0.getBoundingClientRect().bottom + 100;
125
+ const offsetTop = e1.getBoundingClientRect().top - e0.getBoundingClientRect().top - 64;
126
+ if (offsetTop < 0) {
127
+ e0.scrollBy({top: offsetTop, behavior: "smooth"});
128
+ } else if (offsetBottom > 0) {
129
+ e0.scrollBy({top: offsetBottom, behavior: "smooth"});
130
+ }
131
+ }
132
+
133
+ var timeout = null;
134
+ window.addEventListener('scroll', function() {
135
+ activeTOC();
136
+ if(timeout !== null) clearTimeout(timeout);
137
+ timeout = setTimeout(function() {
138
+ scrollTOC();
139
+ }.bind(this), 50);
140
+ });
140
141
  })
141
142
  },
142
143
  sidebar: () => {
143
- stellar.jQuery(() => {
144
+ utils.jq(() => {
144
145
  $("#data-toc a.toc-link").click(function (e) {
145
- l_body.classList.remove("sidebar");
146
+ sidebar.dismiss();
146
147
  });
147
148
  })
148
149
  },
@@ -193,203 +194,3 @@ init.toc()
193
194
  init.sidebar()
194
195
  init.relativeDate(document.querySelectorAll('#post-meta time'))
195
196
  init.registerTabsTag()
196
-
197
- // scrollreveal
198
- if (stellar.plugins.scrollreveal) {
199
- stellar.loadScript(stellar.plugins.scrollreveal.js).then(function () {
200
- const slideUp = {
201
- distance: stellar.plugins.scrollreveal.distance,
202
- duration: stellar.plugins.scrollreveal.duration,
203
- interval: stellar.plugins.scrollreveal.interval,
204
- scale: stellar.plugins.scrollreveal.scale,
205
- opacity: 0,
206
- easing: "ease-out"
207
- }
208
- ScrollReveal().reveal('.l_left .slide-up', slideUp)
209
- ScrollReveal().reveal('.l_main .slide-up', slideUp)
210
- })
211
- }
212
-
213
- // lazyload
214
- if (stellar.plugins.lazyload) {
215
- stellar.loadScript(stellar.plugins.lazyload.js, { defer: true })
216
- // https://www.npmjs.com/package/vanilla-lazyload
217
- // Set the options globally
218
- // to make LazyLoad self-initialize
219
- window.lazyLoadOptions = {
220
- elements_selector: ".lazy",
221
- };
222
- // Listen to the initialization event
223
- // and get the instance of LazyLoad
224
- window.addEventListener(
225
- "LazyLoad::Initialized",
226
- function (event) {
227
- window.lazyLoadInstance = event.detail.instance;
228
- },
229
- false
230
- );
231
- document.addEventListener('DOMContentLoaded', function () {
232
- window.lazyLoadInstance?.update();
233
- });
234
- }
235
-
236
- // stellar js
237
- if (stellar.plugins.stellar) {
238
- for (let key of Object.keys(stellar.plugins.stellar)) {
239
- let js = stellar.plugins.stellar[key];
240
- if (key == 'linkcard') {
241
- stellar.loadScript(js, { defer: true }).then(function () {
242
- setCardLink(document.querySelectorAll('a.link-card[cardlink]'));
243
- });
244
- } else {
245
- const els = document.getElementsByClassName('stellar-' + key + '-api');
246
- if (els != undefined && els.length > 0) {
247
- stellar.jQuery(() => {
248
- if (key == 'timeline' || 'memos' || 'marked') {
249
- stellar.loadScript(stellar.plugins.marked).then(function () {
250
- stellar.loadScript(js, { defer: true });
251
- });
252
- } else {
253
- stellar.loadScript(js, { defer: true });
254
- }
255
- })
256
- }
257
- }
258
- }
259
- }
260
-
261
- // swiper
262
- if (stellar.plugins.swiper) {
263
- const swiper_api = document.getElementById('swiper-api');
264
- if (swiper_api != undefined) {
265
- stellar.loadCSS(stellar.plugins.swiper.css);
266
- stellar.loadScript(stellar.plugins.swiper.js, { defer: true }).then(function () {
267
- const effect = swiper_api.getAttribute('effect') || '';
268
- var swiper = new Swiper('.swiper#swiper-api', {
269
- slidesPerView: 'auto',
270
- spaceBetween: 8,
271
- centeredSlides: true,
272
- effect: effect,
273
- loop: true,
274
- pagination: {
275
- el: '.swiper-pagination',
276
- clickable: true,
277
- },
278
- navigation: {
279
- nextEl: '.swiper-button-next',
280
- prevEl: '.swiper-button-prev',
281
- },
282
- });
283
- })
284
- }
285
- }
286
-
287
- // preload
288
- if (stellar.plugins.preload) {
289
- if (stellar.plugins.preload.service == 'flying_pages') {
290
- window.FPConfig = {
291
- delay: 0,
292
- ignoreKeywords: [],
293
- maxRPS: 5,
294
- hoverDelay: 25
295
- };
296
- stellar.loadScript(stellar.plugins.preload.flying_pages, { defer: true })
297
- }
298
- }
299
-
300
- // fancybox
301
- if (stellar.plugins.fancybox) {
302
- let selector = '[data-fancybox]:not(.error)';
303
- if (stellar.plugins.fancybox.selector) {
304
- selector += `, ${stellar.plugins.fancybox.selector}`
305
- }
306
- var needFancybox = document.querySelectorAll(selector).length !== 0;
307
- if (!needFancybox) {
308
- const els = document.getElementsByClassName('stellar-memos-api');
309
- if (els != undefined && els.length > 0) {
310
- needFancybox = true;
311
- }
312
- }
313
- if (needFancybox) {
314
- stellar.loadCSS(stellar.plugins.fancybox.css);
315
- stellar.loadScript(stellar.plugins.fancybox.js, { defer: true }).then(function () {
316
- Fancybox.bind(selector, {
317
- hideScrollbar: false,
318
- Thumbs: {
319
- autoStart: false,
320
- },
321
- caption: (fancybox, slide) => {
322
- return slide.triggerEl.alt || null
323
- }
324
- });
325
- })
326
- }
327
- }
328
-
329
-
330
- if (stellar.search.service) {
331
- if (stellar.search.service == 'local_search') {
332
- stellar.jQuery(() => {
333
- stellar.loadScript('/js/search/local-search.js', { defer: true }).then(function () {
334
- var $inputArea = $("input#search-input");
335
- if ($inputArea.length == 0) {
336
- return;
337
- }
338
- var $resultArea = document.querySelector("div#search-result");
339
- $inputArea.focus(function() {
340
- var path = stellar.search[stellar.search.service]?.path || '/search.json';
341
- if (path.startsWith('/')) {
342
- path = path.substring(1);
343
- }
344
- path = stellar.config.root + path;
345
- const filter = $inputArea.attr('data-filter') || '';
346
- searchFunc(path, filter, 'search-wrapper', 'search-input', 'search-result');
347
- });
348
- $inputArea.keydown(function(e) {
349
- if (e.which == 13) {
350
- e.preventDefault();
351
- }
352
- });
353
- var observer = new MutationObserver(function(mutationsList, observer) {
354
- if (mutationsList.length == 1) {
355
- if (mutationsList[0].addedNodes.length) {
356
- $('.search-wrapper').removeClass('noresult');
357
- } else if (mutationsList[0].removedNodes.length) {
358
- $('.search-wrapper').addClass('noresult');
359
- }
360
- }
361
- });
362
- observer.observe($resultArea, { childList: true });
363
- });
364
- })
365
- }
366
- }
367
-
368
-
369
- // heti
370
- if (stellar.plugins.heti) {
371
- stellar.loadCSS(stellar.plugins.heti.css);
372
- stellar.loadScript(stellar.plugins.heti.js, { defer: true }).then(function () {
373
- const heti = new Heti('.heti');
374
-
375
- // Copied from heti.autoSpacing() without DOMContentLoaded.
376
- // https://github.com/sivan/heti/blob/eadee6a3b748b3b7924a9e7d5b395d4bce479c9a/js/heti-addon.js
377
- //
378
- // We managed to minimize the code modification to ensure .autoSpacing()
379
- // is synced with upstream; therefore, we use `.bind()` to emulate the
380
- // behavior of .autoSpacing() so we can even modify almost no code.
381
- void (function () {
382
- const $$rootList = document.querySelectorAll(this.rootSelector)
383
-
384
- for (let $$root of $$rootList) {
385
- this.spacingElement($$root)
386
- }
387
- }).bind(heti)();
388
-
389
- stellar.plugins.heti.enable = false;
390
- });
391
- }
392
-
393
- if (stellar.plugins.copycode) {
394
- stellar.loadScript(stellar.plugins.copycode.js, { defer: true })
395
- }
@@ -1,45 +1,32 @@
1
- const codeElementArr = document.querySelectorAll('.code')
2
- codeElementArr.forEach(code => {
3
- // copy btn
4
- const codeCopyBtn = document.createElement('div')
5
- codeCopyBtn.classList.add('copy-btn')
6
- codeCopyBtn.innerHTML = stellar.plugins.copycode.default_text
7
-
8
- code.appendChild(codeCopyBtn)
1
+ window.codeElements.forEach((codeElement) => {
2
+ // 创建复制按钮
3
+ const codeCopyBtn = document.createElement('div');
4
+ codeCopyBtn.className = 'copy-btn';
5
+ codeCopyBtn.textContent = ctx.copycode.default_text;
6
+ codeElement.appendChild(codeCopyBtn);
9
7
 
8
+ // 添加点击事件监听
10
9
  codeCopyBtn.addEventListener('click', async () => {
11
- const currentCodeElement = code.children[0]?.innerText
12
- await copyCode(currentCodeElement)
13
-
14
- codeCopyBtn.innerHTML = stellar.plugins.copycode.success_text
15
- codeCopyBtn.classList.add('success')
16
- hud.toast(stellar.plugins.copycode.toast, 2500)
17
- setTimeout(() => {
18
- codeCopyBtn.innerHTML = stellar.plugins.copycode.default_text
19
- codeCopyBtn.classList.remove('success')
20
- },3000)
21
- })
22
- })
23
-
24
- async function copyCode(currentCode) {
25
- if (navigator.clipboard) {
26
- try {
27
- await navigator.clipboard.writeText(currentCode)
28
- } catch (error) {
29
- // 未获得用户许可
30
- codeCopyBtn.innerText = '未获得用户许可'
31
- codeCopyBtn.classList.add('warning')
32
- setTimeout(() => {
33
- codeCopyBtn.innerText = stellar.plugins.copycode.default_text
34
- codeCopyBtn.classList.remove('warning')
35
- },3000)
10
+ const codeToCopy = codeElement.querySelector('code')?.textContent || '';
11
+ if (navigator.clipboard) {
12
+ try {
13
+ await navigator.clipboard.writeText(codeToCopy);
14
+ codeCopyBtn.textContent = ctx.copycode.success_text;
15
+ codeCopyBtn.classList.add('success');
16
+ hud.toast(ctx.copycode.toast, 2500);
17
+ } catch (error) {
18
+ codeCopyBtn.textContent = '未获得用户许可';
19
+ codeCopyBtn.classList.add('warning');
20
+ }
21
+ } else {
22
+ codeCopyBtn.textContent = '浏览器不支持/非HTTPS';
23
+ codeCopyBtn.classList.add('warning');
36
24
  }
37
- } else {
38
- codeCopyBtn.innerText = '当前浏览器不支持此api'
39
- codeCopyBtn.classList.add('warning')
25
+
26
+ // 3秒后恢复默认文本
40
27
  setTimeout(() => {
41
- codeCopyBtn.innerText = stellar.plugins.copycode.default_text
42
- codeCopyBtn.classList.remove('warning')
43
- },3000)
44
- }
45
- }
28
+ codeCopyBtn.textContent = ctx.copycode.default_text;
29
+ codeCopyBtn.classList.remove('success', 'warning');
30
+ }, 3000);
31
+ });
32
+ });
@@ -0,0 +1,75 @@
1
+ utils.jq(() => {
2
+ var $inputArea = $("input#search-input");
3
+ if ($inputArea.length === 0) {
4
+ return;
5
+ }
6
+
7
+ var $resultArea = $("#search-result");
8
+ var $searchWrapper = $("#search-wrapper");
9
+ var client = algoliasearch(window.searchConfig.appId, window.searchConfig.apiKey);
10
+ var index = client.initIndex(window.searchConfig.indexName);
11
+
12
+ function filterResults(hits, filterPath) {
13
+ if (!filterPath || filterPath === '/') return hits;
14
+ var regex = new RegExp(filterPath);
15
+ return hits.filter(hit => regex.test(hit.url));
16
+ }
17
+
18
+ function displayResults(hits) {
19
+ var $resultList = $("<ul>").addClass("search-result-list");
20
+ if (hits.length === 0) {
21
+ $searchWrapper.addClass('noresult');
22
+ } else {
23
+ $searchWrapper.removeClass('noresult');
24
+ hits.forEach(function(hit) {
25
+ var contentSnippet = hit._snippetResult.content.value;
26
+ var title = hit.hierarchy.lvl1 || 'Untitled';
27
+ var $item = $("<li>").html(`<a href="${hit.url}"><span class='search-result-title'>${title}</span><p class="search-result-content">${contentSnippet}</p></a>`);
28
+ $resultList.append($item);
29
+ });
30
+ }
31
+ $resultArea.html($resultList);
32
+ }
33
+
34
+ $inputArea.on("input", function() {
35
+ var query = $(this).val().trim();
36
+ var filterPath = $inputArea.data('filter');
37
+
38
+ if (query.length <= 0) {
39
+ $searchWrapper.attr('searching', 'false');
40
+ $resultArea.empty();
41
+ return;
42
+ }
43
+
44
+ $searchWrapper.attr('searching', 'true');
45
+
46
+ index.search(query, {
47
+ hitsPerPage: window.searchConfig.hitsPerPage,
48
+ attributesToHighlight: ['content'],
49
+ attributesToSnippet: ['content:30'],
50
+ highlightPreTag: '<span class="search-keyword">',
51
+ highlightPostTag: '</span>',
52
+ restrictSearchableAttributes: ['content']
53
+ }).then(function(responses) {
54
+ displayResults(filterResults(responses.hits, filterPath));
55
+ });
56
+ });
57
+
58
+ $inputArea.on("keydown", function(e) {
59
+ if (e.which == 13) {
60
+ e.preventDefault();
61
+ }
62
+ });
63
+
64
+ var observer = new MutationObserver(function(mutationsList) {
65
+ if (mutationsList.length === 1) {
66
+ if (mutationsList[0].addedNodes.length) {
67
+ $searchWrapper.removeClass('noresult');
68
+ } else if (mutationsList[0].removedNodes.length) {
69
+ $searchWrapper.addClass('noresult');
70
+ }
71
+ }
72
+ });
73
+
74
+ observer.observe($resultArea[0], { childList: true });
75
+ });
@@ -136,3 +136,35 @@ var searchFunc = function(path, filter, wrapperId, searchId, contentId) {
136
136
  }
137
137
  });
138
138
  };
139
+
140
+ utils.jq(() => {
141
+ var $inputArea = $("input#search-input");
142
+ if ($inputArea.length == 0) {
143
+ return;
144
+ }
145
+ var $resultArea = document.querySelector("div#search-result");
146
+ $inputArea.focus(function() {
147
+ var path = ctx.search.path;
148
+ if (path.startsWith('/')) {
149
+ path = path.substring(1);
150
+ }
151
+ path = ctx.root + path;
152
+ const filter = $inputArea.attr('data-filter') || '';
153
+ searchFunc(path, filter, 'search-wrapper', 'search-input', 'search-result');
154
+ });
155
+ $inputArea.keydown(function(e) {
156
+ if (e.which == 13) {
157
+ e.preventDefault();
158
+ }
159
+ });
160
+ var observer = new MutationObserver(function(mutationsList, observer) {
161
+ if (mutationsList.length == 1) {
162
+ if (mutationsList[0].addedNodes.length) {
163
+ $('.search-wrapper').removeClass('noresult');
164
+ } else if (mutationsList[0].removedNodes.length) {
165
+ $('.search-wrapper').addClass('noresult');
166
+ }
167
+ }
168
+ });
169
+ observer.observe($resultArea, { childList: true });
170
+ });
@@ -0,0 +1,36 @@
1
+ utils.jq(() => {
2
+ $(function () {
3
+ const els = document.getElementsByClassName('ds-fcircle');
4
+ for (var i = 0; i < els.length; i++) {
5
+ const el = els[i];
6
+ const api = el.getAttribute('api');
7
+ if (api == null) {
8
+ continue;
9
+ }
10
+ const default_avatar = def.avatar;
11
+ // layout
12
+ utils.request(el, api, function(data) {
13
+ const arr = data.article_data || [];
14
+ const limit = el.getAttribute('limit');
15
+ arr.forEach((item, i) => {
16
+ if (limit && i >= limit) {
17
+ return;
18
+ }
19
+ var cell = '<div class="timenode" index="' + i + '">';
20
+ cell += '<div class="header">';
21
+ cell += '<div class="user-info">';
22
+ cell += '<img src="' + (item.avatar || default_avatar) + '" onerror="javascript:this.src=\'' + default_avatar + '\';">';
23
+ cell += '<span>' + item.author + '</span>';
24
+ cell += '</div>';
25
+ cell += '<span>' + item.created + '</span>';
26
+ cell += '</div>';
27
+ cell += '<a class="body" href="' + item.link + '" target="_blank" rel="external nofollow noopener noreferrer">';
28
+ cell += item.title;
29
+ cell += '</a>';
30
+ cell += '</div>';
31
+ $(el).append(cell);
32
+ });
33
+ });
34
+ }
35
+ });
36
+ });
@@ -0,0 +1,27 @@
1
+ utils.jq(() => {
2
+ $(function () {
3
+ const els = document.getElementsByClassName('ds-friends');
4
+ for (var i = 0; i < els.length; i++) {
5
+ const el = els[i];
6
+ const api = el.getAttribute('api');
7
+ if (api == null) {
8
+ continue;
9
+ }
10
+ const default_avatar = def.avatar;
11
+ // layout
12
+ utils.request(el, api, function(data) {
13
+ for (let item of (data.content || data)) {
14
+ var cell = `<div class="grid-cell user-card">`;
15
+ cell += `<a class="card-link" target="_blank" rel="external nofollow noopener noreferrer" href="${item.html_url || item.url}">`;;
16
+ cell += `<img src="${item.avatar_url || item.avatar || item.icon || default_avatar}" onerror="javascript:this.removeAttribute(\'data-src\');this.src=\'${default_avatar}\';"/>`;
17
+ cell += `<div class="name image-meta">`;
18
+ cell += `<span class="image-caption">${item.title || item.login}</span>`;
19
+ cell += `</div>`;
20
+ cell += `</a>`;
21
+ cell += `</div>`;
22
+ $(el).find('.grid-box').append(cell);
23
+ }
24
+ });
25
+ }
26
+ });
27
+ });
@@ -0,0 +1,33 @@
1
+ utils.jq(() => {
2
+ $(function () {
3
+ const els = document.getElementsByClassName('ds-ghinfo');
4
+ for (var i = 0; i < els.length; i++) {
5
+ const el = els[i];
6
+ const api = el.getAttribute('api');
7
+ if (api == null) {
8
+ continue;
9
+ }
10
+ // layout
11
+ utils.request(null, api, function(data) {
12
+ function fill(data) {
13
+ for (let key of Object.keys(data)) {
14
+ $(el).find("[type=text]#" + key).text(data[key]);
15
+ $(el).find("[type=link]#" + key).attr("href", data[key]);
16
+ $(el).find("[type=img]#" + key).attr("src", data[key]);
17
+ }
18
+ }
19
+ const idx = el.getAttribute('index');
20
+ if (idx != undefined) {
21
+ const arr = data.content || data;
22
+ if (arr && arr.length > idx) {
23
+ let obj = arr[idx];
24
+ obj['latest-tag-name'] = obj['name'];
25
+ fill(arr[idx]);
26
+ }
27
+ } else {
28
+ fill(data);
29
+ }
30
+ });
31
+ }
32
+ });
33
+ });
@@ -0,0 +1,10 @@
1
+ utils.jq(() => {
2
+ const els = document.getElementsByClassName('ds-mdrender');
3
+ for (var i = 0; i < els.length; i++) {
4
+ const el = els[i];
5
+ const src = `${el.getAttribute('src')}?t=${new Date().getTime()}`;
6
+ utils.request(el, src, function(data) {
7
+ el.innerHTML = marked.parse(resp.data);
8
+ });
9
+ }
10
+ });