hexo-theme-stellar 1.26.7 → 1.27.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 (150) hide show
  1. package/_config.yml +134 -94
  2. package/_data/icons.yml +8 -1
  3. package/_data/widgets.yml +19 -7
  4. package/languages/en.yml +4 -2
  5. package/languages/zh-CN.yml +3 -1
  6. package/languages/zh-TW.yml +4 -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 +1 -1
  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 +0 -1
  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 +32 -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/local_search.ejs +8 -0
  50. package/layout/_plugins/swiper.ejs +26 -0
  51. package/layout/_plugins/tianli_gpt.ejs +11 -0
  52. package/layout/archive.ejs +9 -2
  53. package/layout/layout.ejs +9 -6
  54. package/layout/page.ejs +2 -10
  55. package/package.json +1 -1
  56. package/scripts/events/lib/doc_tree.js +8 -8
  57. package/scripts/events/lib/topic_tree.js +3 -0
  58. package/scripts/generators/author.js +1 -1
  59. package/scripts/helpers/parse_config.js +6 -5
  60. package/scripts/tags/lib/albums.js +2 -2
  61. package/scripts/tags/lib/button.js +1 -1
  62. package/scripts/tags/lib/emoji.js +1 -1
  63. package/scripts/tags/lib/friends.js +1 -1
  64. package/scripts/tags/lib/icon.js +10 -5
  65. package/scripts/tags/lib/link.js +2 -2
  66. package/scripts/tags/lib/md.js +1 -1
  67. package/scripts/tags/lib/posters.js +2 -2
  68. package/scripts/tags/lib/sites.js +1 -1
  69. package/scripts/tags/lib/timeline.js +2 -2
  70. package/source/css/_common/button.styl +8 -2
  71. package/source/css/_common/device.styl +39 -12
  72. package/source/css/_custom.styl +15 -16
  73. package/source/css/_defines/const.styl +1 -1
  74. package/source/css/_defines/func.styl +14 -4
  75. package/source/css/_defines/theme.styl +38 -27
  76. package/source/css/_layout/layout.styl +61 -26
  77. package/source/css/_layout/list.styl +1 -1
  78. package/source/css/_layout/main.styl +1 -4
  79. package/source/css/_layout/md.styl +16 -2
  80. package/source/css/_layout/pages/archives.styl +4 -0
  81. package/source/css/_layout/partial/article-banner.styl +14 -15
  82. package/source/css/_layout/partial/article-footer.styl +0 -5
  83. package/source/css/_layout/partial/footer.styl +8 -6
  84. package/source/css/_layout/partial/related.styl +4 -0
  85. package/source/css/_layout/sidebar/footer.styl +3 -1
  86. package/source/css/_layout/sidebar/logo.styl +3 -1
  87. package/source/css/_layout/sidebar/nav-area.styl +1 -1
  88. package/source/css/_layout/sidebar/sidebar.styl +23 -16
  89. package/source/css/_layout/tag-plugins/banner.styl +1 -8
  90. package/source/css/_layout/tag-plugins/common.styl +10 -5
  91. package/source/css/_layout/tag-plugins/icon.styl +6 -0
  92. package/source/css/_layout/tag-plugins/image.styl +1 -1
  93. package/source/css/_layout/tag-plugins/quot.styl +1 -1
  94. package/source/css/_layout/tag-plugins/timeline.styl +26 -27
  95. package/source/css/_layout/widgets/ghrepo.styl +1 -1
  96. package/source/css/_layout/widgets/ghuser.styl +9 -5
  97. package/source/css/_layout/widgets/list.styl +4 -2
  98. package/source/css/_layout/widgets/related.styl +0 -1
  99. package/source/css/_layout/widgets/timeline.styl +27 -21
  100. package/source/css/_layout/widgets/toc.styl +182 -0
  101. package/source/css/_layout/widgets/tree.styl +0 -0
  102. package/source/css/_layout/widgets/widgets.styl +26 -7
  103. package/source/css/_plugins/comments/twikoo.styl +6 -6
  104. package/source/css/_plugins/comments/waline.styl +13 -10
  105. package/source/css/_plugins/index.styl +2 -0
  106. package/source/css/_plugins/katex.styl +5 -0
  107. package/source/css/_plugins/mermaid.styl +49 -59
  108. package/source/css/_plugins/tianli_gpt.styl +208 -151
  109. package/source/js/main.js +48 -251
  110. package/source/js/plugins/copycode.js +24 -28
  111. package/source/js/search/local-search.js +32 -0
  112. package/source/js/services/fcircle.js +36 -0
  113. package/source/js/services/friends.js +27 -0
  114. package/source/js/services/ghinfo.js +33 -0
  115. package/source/js/services/mdrender.js +10 -0
  116. package/source/js/services/memos.js +73 -0
  117. package/source/js/services/siteinfo.js +38 -0
  118. package/source/js/services/sites.js +30 -0
  119. package/source/js/services/timeline.js +106 -0
  120. package/source/js/services/weibo.js +60 -0
  121. package/layout/_partial/main/navbar/article_top_area.ejs +0 -35
  122. package/layout/_partial/main/navbar/author_banner.ejs +0 -29
  123. package/layout/_partial/plugins/ai/tianli_gpt.ejs +0 -9
  124. package/layout/_partial/plugins/comments/waline/script.ejs +0 -39
  125. package/layout/_partial/plugins/parser/head.ejs +0 -3
  126. package/layout/_partial/plugins/parser/katex/head.ejs +0 -3
  127. package/layout/_partial/plugins/parser/katex/script.ejs +0 -4
  128. package/layout/_partial/plugins/parser/mermaid/script.ejs +0 -29
  129. package/layout/_partial/plugins/parser/script.ejs +0 -9
  130. package/layout/_partial/scripts/index.ejs +0 -176
  131. package/source/css/_layout/widgets/toc_blog.styl +0 -3
  132. package/source/css/_layout/widgets/toc_common.styl +0 -92
  133. package/source/css/_layout/widgets/toc_wiki.styl +0 -62
  134. package/source/js/plugins/fcircle.js +0 -92
  135. package/source/js/plugins/friends.js +0 -84
  136. package/source/js/plugins/ghinfo.js +0 -85
  137. package/source/js/plugins/linkcard.js +0 -48
  138. package/source/js/plugins/marked.js +0 -50
  139. package/source/js/plugins/memos.js +0 -132
  140. package/source/js/plugins/sites.js +0 -87
  141. package/source/js/plugins/timeline.js +0 -162
  142. package/source/js/plugins/weibo.js +0 -116
  143. /package/layout/_partial/{plugins/comments → comments}/artalk/layout.ejs +0 -0
  144. /package/layout/_partial/{plugins/comments → comments}/beaudar/layout.ejs +0 -0
  145. /package/layout/_partial/{plugins/comments → comments}/beaudar/script.ejs +0 -0
  146. /package/layout/_partial/{plugins/comments → comments}/script.ejs +0 -0
  147. /package/layout/_partial/{plugins/comments → comments}/twikoo/layout.ejs +0 -0
  148. /package/layout/_partial/{plugins/comments/giscus → comments/utterances}/layout.ejs +0 -0
  149. /package/layout/_partial/{plugins/comments → comments}/utterances/script.ejs +0 -0
  150. /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,10 @@ const util = {
55
50
  el.classList.toggle("display");
56
51
  }
57
52
  },
53
+
54
+ scrollTop: () => {
55
+ window.scrollTo({top: 0, behavior: "smooth"});
56
+ },
58
57
  }
59
58
 
60
59
  const hud = {
@@ -76,73 +75,71 @@ const hud = {
76
75
 
77
76
  const l_body = document.querySelector('.l_body');
78
77
 
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
78
 
88
79
  const init = {
89
80
  toc: () => {
90
- stellar.jQuery(() => {
81
+ utils.jq(() => {
91
82
  const scrollOffset = 32;
92
83
  var segs = [];
93
84
  $("article.md-text :header").each(function (idx, node) {
94
- segs.push(node)
85
+ segs.push(node);
95
86
  });
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) {
87
+ function activeTOC() {
105
88
  var scrollTop = $(this).scrollTop();
106
- var topSeg = null
89
+ var topSeg = null;
107
90
  for (var idx in segs) {
108
- var seg = $(segs[idx])
91
+ var seg = $(segs[idx]);
109
92
  if (seg.offset().top > scrollTop + scrollOffset) {
110
- continue
93
+ continue;
111
94
  }
112
95
  if (!topSeg) {
113
- topSeg = seg
96
+ topSeg = seg;
114
97
  } else if (seg.offset().top >= topSeg.offset().top) {
115
- topSeg = seg
98
+ topSeg = seg;
116
99
  }
117
100
  }
118
101
  if (topSeg) {
119
- $("#data-toc a.toc-link").removeClass("active")
120
- var link = "#" + topSeg.attr("id")
102
+ $("#data-toc a.toc-link").removeClass("active");
103
+ var link = "#" + topSeg.attr("id");
121
104
  if (link != '#undefined') {
122
- const highlightItem = $('#data-toc a.toc-link[href="' + encodeURI(link) + '"]')
105
+ const highlightItem = $('#data-toc a.toc-link[href="' + encodeURI(link) + '"]');
123
106
  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
- }
107
+ highlightItem.addClass("active");
134
108
  }
135
109
  } else {
136
- $('#data-toc a.toc-link:first').addClass("active")
110
+ $('#data-toc a.toc-link:first').addClass("active");
137
111
  }
138
112
  }
139
- })
113
+ }
114
+ function scrollTOC() {
115
+ const e0 = document.querySelector('#data-toc .toc');
116
+ const e1 = document.querySelector('#data-toc .toc a.toc-link.active');
117
+ if (e0 == null || e1 == null) {
118
+ return;
119
+ }
120
+ const offsetBottom = e1.getBoundingClientRect().bottom - e0.getBoundingClientRect().bottom + 100;
121
+ const offsetTop = e1.getBoundingClientRect().top - e0.getBoundingClientRect().top - 64;
122
+ if (offsetTop < 0) {
123
+ e0.scrollBy({top: offsetTop, behavior: "smooth"});
124
+ } else if (offsetBottom > 0) {
125
+ e0.scrollBy({top: offsetBottom, behavior: "smooth"});
126
+ }
127
+ }
128
+
129
+ var timeout = null;
130
+ window.addEventListener('scroll', function() {
131
+ activeTOC();
132
+ if(timeout !== null) clearTimeout(timeout);
133
+ timeout = setTimeout(function() {
134
+ scrollTOC();
135
+ }.bind(this), 50);
136
+ });
140
137
  })
141
138
  },
142
139
  sidebar: () => {
143
- stellar.jQuery(() => {
140
+ utils.jq(() => {
144
141
  $("#data-toc a.toc-link").click(function (e) {
145
- l_body.classList.remove("sidebar");
142
+ sidebar.dismiss();
146
143
  });
147
144
  })
148
145
  },
@@ -193,203 +190,3 @@ init.toc()
193
190
  init.sidebar()
194
191
  init.relativeDate(document.querySelectorAll('#post-meta time'))
195
192
  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,41 @@
1
- const codeElementArr = document.querySelectorAll('.code')
2
- codeElementArr.forEach(code => {
1
+ window.codeElements.forEach(code => {
3
2
  // 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)
9
-
3
+ const codeCopyBtn = document.createElement('div');
4
+ codeCopyBtn.classList.add('copy-btn');
5
+ codeCopyBtn.innerHTML = ctx.copycode.default_text;
6
+ code.appendChild(codeCopyBtn);
10
7
  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)
8
+ const currentCodeElement = code.children[0]?.innerText;
9
+ await copyCode(currentCodeElement);
10
+ codeCopyBtn.innerHTML = ctx.copycode.success_text;
11
+ codeCopyBtn.classList.add('success');
12
+ hud.toast(ctx.copycode.toast, 2500);
17
13
  setTimeout(() => {
18
- codeCopyBtn.innerHTML = stellar.plugins.copycode.default_text
19
- codeCopyBtn.classList.remove('success')
20
- },3000)
14
+ codeCopyBtn.innerHTML = ctx.copycode.default_text;
15
+ codeCopyBtn.classList.remove('success');
16
+ },3000);
21
17
  })
22
18
  })
23
19
 
24
20
  async function copyCode(currentCode) {
25
21
  if (navigator.clipboard) {
26
22
  try {
27
- await navigator.clipboard.writeText(currentCode)
23
+ await navigator.clipboard.writeText(currentCode);
28
24
  } catch (error) {
29
25
  // 未获得用户许可
30
- codeCopyBtn.innerText = '未获得用户许可'
31
- codeCopyBtn.classList.add('warning')
26
+ codeCopyBtn.innerText = '未获得用户许可';
27
+ codeCopyBtn.classList.add('warning');
32
28
  setTimeout(() => {
33
- codeCopyBtn.innerText = stellar.plugins.copycode.default_text
34
- codeCopyBtn.classList.remove('warning')
35
- },3000)
29
+ codeCopyBtn.innerText = ctx.copycode.default_text;
30
+ codeCopyBtn.classList.remove('warning');
31
+ },3000);
36
32
  }
37
33
  } else {
38
- codeCopyBtn.innerText = '当前浏览器不支持此api'
39
- codeCopyBtn.classList.add('warning')
34
+ codeCopyBtn.innerText = '当前浏览器不支持此api';
35
+ codeCopyBtn.classList.add('warning');
40
36
  setTimeout(() => {
41
- codeCopyBtn.innerText = stellar.plugins.copycode.default_text
42
- codeCopyBtn.classList.remove('warning')
43
- },3000)
37
+ codeCopyBtn.innerText = ctx.copycode.default_text;
38
+ codeCopyBtn.classList.remove('warning');
39
+ },3000);
44
40
  }
45
41
  }
@@ -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
+ });
@@ -0,0 +1,73 @@
1
+ utils.jq(() => {
2
+ $(function () {
3
+ const els = document.getElementsByClassName('ds-memos');
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 = el.getAttribute('avatar') || def.avatar;
11
+ const limit = el.getAttribute('limit');
12
+ const host = api.replace(/https:\/\/(.*?)\/(.*)/i, '$1');
13
+ // layout
14
+ utils.request(el, api, function(data) {
15
+ var users = [];
16
+ const filter = el.getAttribute('user');
17
+ if (filter && filter.length > 0) {
18
+ users = filter.split(",");
19
+ }
20
+ var hide = [];
21
+ const hideStr = el.getAttribute('hide');
22
+ if (hideStr && hideStr.length > 0) {
23
+ hide = hideStr.split(",");
24
+ }
25
+ data.forEach((item, i) => {
26
+ if (limit && i >= limit) {
27
+ return;
28
+ }
29
+ if (item.user && item.user.login && users.length > 0) {
30
+ if (!users.includes(item.user.login)) {
31
+ return;
32
+ }
33
+ }
34
+ let date = new Date(item.createdTs * 1000)
35
+ var cell = '<div class="timenode" index="' + i + '">';
36
+ cell += '<div class="header">';
37
+ if (!users.length && !hide.includes('user')) {
38
+ cell += '<div class="user-info">';
39
+ if (default_avatar.length > 0) {
40
+ cell += `<img src="${default_avatar}">`;
41
+ }
42
+ cell += '<span>' + item.creatorName + '</span>';
43
+ cell += '</div>';
44
+ }
45
+ cell += '<span>' + date.toLocaleString() + '</span>';
46
+ cell += '</div>';
47
+ cell += '<div class="body">';
48
+ cell += marked.parse(item.content || '');
49
+ var imgs = [];
50
+ for (let res of item.resourceList) {
51
+ if (res.type?.includes('image/')) {
52
+ imgs.push(res);
53
+ }
54
+ }
55
+ if (imgs.length > 0) {
56
+ cell += '<div class="tag-plugin image">';
57
+ for (let img of imgs) {
58
+ if (img.externalLink?.length > 0) {
59
+ cell += `<div class="image-bg"><img src="${img.externalLink}" data-fancybox="memos"></div>`;
60
+ } else {
61
+ cell += `<div class="image-bg"><img src="https://${host}/o/r/${img.id}" data-fancybox="memos"></div>`;
62
+ }
63
+ }
64
+ cell += '</div>';
65
+ }
66
+ cell += '</div>';
67
+ cell += '</div>';
68
+ $(el).append(cell);
69
+ });
70
+ });
71
+ }
72
+ });
73
+ });