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
@@ -1,87 +0,0 @@
1
- const sitesjs = {
2
- requestAPI: (url, callback, timeout) => {
3
- let retryTimes = 5;
4
- function request() {
5
- return new Promise((resolve, reject) => {
6
- let status = 0; // 0 等待 1 完成 2 超时
7
- let timer = setTimeout(() => {
8
- if (status === 0) {
9
- status = 2;
10
- timer = null;
11
- reject('请求超时');
12
- if (retryTimes == 0) {
13
- timeout();
14
- }
15
- }
16
- }, 5000);
17
- fetch(url).then(function(response) {
18
- if (status !== 2) {
19
- clearTimeout(timer);
20
- resolve(response);
21
- timer = null;
22
- status = 1;
23
- }
24
- if (response.ok) {
25
- return response.json();
26
- }
27
- throw new Error('Network response was not ok.');
28
- }).then(function(data) {
29
- retryTimes = 0;
30
- callback(data);
31
- }).catch(function(error) {
32
- if (retryTimes > 0) {
33
- retryTimes -= 1;
34
- setTimeout(() => {
35
- request();
36
- }, 5000);
37
- } else {
38
- timeout();
39
- }
40
- });
41
- });
42
- }
43
- request();
44
- },
45
- layout: (cfg) => {
46
- const el = $(cfg.el)[0];
47
- $(el).append('<div class="loading-wrap"><svg xmlns="http://www.w3.org/2000/svg" width="2em" height="2em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-width="2"><path stroke-dasharray="60" stroke-dashoffset="60" stroke-opacity=".3" d="M12 3C16.9706 3 21 7.02944 21 12C21 16.9706 16.9706 21 12 21C7.02944 21 3 16.9706 3 12C3 7.02944 7.02944 3 12 3Z"><animate fill="freeze" attributeName="stroke-dashoffset" dur="1.3s" values="60;0"/></path><path stroke-dasharray="15" stroke-dashoffset="15" d="M12 3C16.9706 3 21 7.02944 21 12"><animate fill="freeze" attributeName="stroke-dashoffset" dur="0.3s" values="15;0"/><animateTransform attributeName="transform" dur="1.5s" repeatCount="indefinite" type="rotate" values="0 12 12;360 12 12"/></path></g></svg></div>');
48
- sitesjs.requestAPI(cfg.api, function(data) {
49
- $(el).find('.loading-wrap').remove();
50
- for (let item of data.content) {
51
- var cell = `<div class="grid-cell site-card">`;
52
- cell += `<a class="card-link" target="_blank" rel="external nofollow noopener noreferrer" href="${item.url}">`;
53
- cell += `<img src="${item.cover || item.screenshot}" onerror="javascript:this.removeAttribute(\'data-src\');this.src=\'${cfg.screenshot}\';"/>`;
54
- cell += `<div class="info">`;
55
- cell += `<img src="${item.icon || item.avatar || cfg.avatar}" onerror="javascript:this.removeAttribute(\'data-src\');this.src=\'${cfg.avatar}\';"/>`;
56
- cell += `<span class="title">${item.title}</span>`;
57
- cell += `<span class="desc">${item.description || item.url}</span>`;
58
- cell += `</div>`;
59
- cell += `</a>`;
60
- cell += `</div>`;
61
- $(el).find('.grid-box').append(cell);
62
- }
63
- }, function() {
64
- $(el).find('.loading-wrap svg').remove();
65
- $(el).find('.loading-wrap').append('<svg xmlns="http://www.w3.org/2000/svg" width="2em" height="2em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path stroke-dasharray="60" stroke-dashoffset="60" d="M12 3L21 20H3L12 3Z"><animate fill="freeze" attributeName="stroke-dashoffset" dur="0.5s" values="60;0"/></path><path stroke-dasharray="6" stroke-dashoffset="6" d="M12 10V14"><animate fill="freeze" attributeName="stroke-dashoffset" begin="0.6s" dur="0.2s" values="6;0"/></path></g><circle cx="12" cy="17" r="1" fill="currentColor" fill-opacity="0"><animate fill="freeze" attributeName="fill-opacity" begin="0.8s" dur="0.4s" values="0;1"/></circle></svg>');
66
- $(el).find('.loading-wrap').addClass('error');
67
- });
68
- },
69
- }
70
-
71
- $(function () {
72
- const els = document.getElementsByClassName('stellar-sites-api');
73
- for (var i = 0; i < els.length; i++) {
74
- const el = els[i];
75
- const api = el.getAttribute('api');
76
- if (api == null) {
77
- continue;
78
- }
79
- var cfg = new Object();
80
- cfg.class = el.getAttribute('class');
81
- cfg.el = el;
82
- cfg.api = api;
83
- cfg.avatar = 'https://gcore.jsdelivr.net/gh/cdn-x/placeholder@1.0.12/link/8f277b4ee0ecd.svg';
84
- cfg.screenshot = 'https://gcore.jsdelivr.net/gh/cdn-x/placeholder@1.0.12/cover/76b86c0226ffd.svg';
85
- sitesjs.layout(cfg);
86
- }
87
- });
@@ -1,162 +0,0 @@
1
- const StellarTimeline = {
2
- reactions: {
3
- '+1': '👍',
4
- '-1': '👎',
5
- 'laugh': '😀',
6
- 'hooray': '🎉',
7
- 'confused': '😕',
8
- 'heart': '❤️',
9
- 'rocket': '🚀',
10
- 'eyes': '👀'
11
- },
12
- requestAPI: (url, callback, timeout) => {
13
- let retryTimes = 5;
14
- function request() {
15
- return new Promise((resolve, reject) => {
16
- let status = 0; // 0 等待 1 完成 2 超时
17
- let timer = setTimeout(() => {
18
- if (status === 0) {
19
- status = 2;
20
- timer = null;
21
- reject('请求超时');
22
- if (retryTimes == 0) {
23
- timeout();
24
- }
25
- }
26
- }, 5000);
27
- fetch(url).then(function(response) {
28
- if (status !== 2) {
29
- clearTimeout(timer);
30
- resolve(response);
31
- timer = null;
32
- status = 1;
33
- }
34
- if (response.ok) {
35
- return response.json();
36
- }
37
- throw new Error('Network response was not ok.');
38
- }).then(function(data) {
39
- retryTimes = 0;
40
- callback(data);
41
- }).catch(function(error) {
42
- if (retryTimes > 0) {
43
- retryTimes -= 1;
44
- setTimeout(() => {
45
- request();
46
- }, 5000);
47
- } else {
48
- timeout();
49
- }
50
- });
51
- });
52
- }
53
- request();
54
- },
55
- layoutDiv: (cfg) => {
56
- const el = $(cfg.el)[0];
57
- $(el).append('<div class="loading-wrap"><svg xmlns="http://www.w3.org/2000/svg" width="2em" height="2em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-width="2"><path stroke-dasharray="60" stroke-dashoffset="60" stroke-opacity=".3" d="M12 3C16.9706 3 21 7.02944 21 12C21 16.9706 16.9706 21 12 21C7.02944 21 3 16.9706 3 12C3 7.02944 7.02944 3 12 3Z"><animate fill="freeze" attributeName="stroke-dashoffset" dur="1.3s" values="60;0"/></path><path stroke-dasharray="15" stroke-dashoffset="15" d="M12 3C16.9706 3 21 7.02944 21 12"><animate fill="freeze" attributeName="stroke-dashoffset" dur="0.3s" values="15;0"/><animateTransform attributeName="transform" dur="1.5s" repeatCount="indefinite" type="rotate" values="0 12 12;360 12 12"/></path></g></svg></div>');
58
- StellarTimeline.requestAPI(cfg.api, function(data) {
59
- $(el).find('.loading-wrap').remove();
60
- const query = new URL(cfg.api).search;
61
- const arr = data.content || data;
62
- var users = [];
63
- const filter = el.getAttribute('user');
64
- if (filter && filter.length > 0) {
65
- users = filter.split(",");
66
- }
67
- var hide = [];
68
- const hideStr = el.getAttribute('hide');
69
- if (hideStr && hideStr.length > 0) {
70
- hide = hideStr.split(",");
71
- }
72
- arr.forEach((item, i) => {
73
- if (item.user && item.user.login && users.length > 0) {
74
- if (!users.includes(item.user.login)) {
75
- return;
76
- }
77
- }
78
- var cell = '<div class="timenode" index="' + i + '">';
79
- cell += '<div class="header">';
80
- if (!users.length && item.user && !hide.includes('user')) {
81
- cell += '<a class="user-info" href="' + item.user.html_url + '" target="_blank" rel="external nofollow noopener noreferrer">';
82
- cell += '<img src="' + item.user.avatar_url + '">';
83
- cell += '<span>' + item.user.login + '</span>';
84
- cell += '</a>';
85
- }
86
- let date = new Date(item.created_at);
87
- cell += '<p>' + date.toLocaleString() + '</p>';
88
- cell += '</div>';
89
- cell += '<div class="body">';
90
- if (!hide.includes('title')) {
91
- cell += '<p class="title">';
92
- cell += '<a href="' + item.html_url + '" target="_blank" rel="external nofollow noopener noreferrer">';
93
- cell += item.title || item.name || item.tag_name;
94
- cell += '</a>';
95
- cell += '</p>';
96
- }
97
-
98
- cell += marked.parse(item.body || '');
99
- if (!hide.includes('footer')) {
100
- cell += '<div class="footer">';
101
- cell += '<div class="flex left">';
102
- if (item.labels) {
103
- item.labels.forEach((label, i) => {
104
- if (!query || !query.includes(encodeURI(label.name))) {
105
- cell += '<div class="item label ' + label.name + '" style="background:#' + label.color + '18;border-color:#' + label.color + '36">';
106
- cell += '<span>' + label.name + '</span>';
107
- cell += '</div>';
108
- }
109
- });
110
- } else if (item.zipball_url) {
111
- cell += '<a class="item download" href="' + item.zipball_url + '" target="_blank" rel="external nofollow noopener noreferrer">';
112
- cell += '<span>📦 ' + item.tag_name + '.zip</span>';
113
- cell += '</a>';
114
- }
115
- cell += '</div>';
116
- cell += '<div class="flex right">';
117
- if (item.reactions && item.reactions.total_count > 0) {
118
- for (let key of Object.keys(StellarTimeline.reactions)) {
119
- let num = item.reactions[key];
120
- if (num > 0) {
121
- cell += '<div class="item reaction ' + key + '">';
122
- cell += '<span>' + StellarTimeline.reactions[key] + ' ' + item.reactions[key] + '</span>';
123
- cell += '</div>';
124
- }
125
- }
126
- }
127
- if (item.comments != null) {
128
- cell += '<a class="item comments last" href="' + item.html_url + '#issuecomment-new" target="_blank" rel="external nofollow noopener noreferrer">';
129
- cell += '<span><svg t="1666270368054" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2528" width="200" height="200"><path d="M952 64H72C32.3 64 0 96.3 0 136v508c0 39.7 32.3 72 72 72h261l128 128c14 14 32.5 21.1 50.9 21.1s36.9-7 50.9-21.1l128-128h261c39.7 0 72-32.3 72-72V136c0.2-39.7-32.1-72-71.8-72zM222 462c-39.8 0-72-32.2-72-72s32.2-72 72-72 72 32.2 72 72-32.2 72-72 72z m290-7.7c-39.8 0-72-32.2-72-72s32.2-72 72-72 72 32.2 72 72c0 39.7-32.2 72-72 72z m290 8c-39.8 0-72-32.2-72-72s32.2-72 72-72 72 32.2 72 72c0 39.7-32.2 72-72 72z" p-id="2529"></path></svg> ' + (item.comments || 0) + '</span>';
130
- cell += '</a>';
131
- }
132
-
133
- cell += '</div>';
134
- cell += '</div>';
135
- }
136
-
137
- cell += '</div>';
138
- cell += '</div>';
139
- $(el).append(cell);
140
- });
141
- }, function() {
142
- $(el).find('.loading-wrap svg').remove();
143
- $(el).find('.loading-wrap').append('<svg xmlns="http://www.w3.org/2000/svg" width="2em" height="2em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path stroke-dasharray="60" stroke-dashoffset="60" d="M12 3L21 20H3L12 3Z"><animate fill="freeze" attributeName="stroke-dashoffset" dur="0.5s" values="60;0"/></path><path stroke-dasharray="6" stroke-dashoffset="6" d="M12 10V14"><animate fill="freeze" attributeName="stroke-dashoffset" begin="0.6s" dur="0.2s" values="6;0"/></path></g><circle cx="12" cy="17" r="1" fill="currentColor" fill-opacity="0"><animate fill="freeze" attributeName="fill-opacity" begin="0.8s" dur="0.4s" values="0;1"/></circle></svg>');
144
- $(el).find('.loading-wrap').addClass('error');
145
- });
146
- },
147
- }
148
-
149
- $(function () {
150
- const els = document.getElementsByClassName('stellar-timeline-api');
151
- for (var i = 0; i < els.length; i++) {
152
- const el = els[i];
153
- const api = el.getAttribute('api');
154
- if (api == null) {
155
- continue;
156
- }
157
- var obj = new Object();
158
- obj.el = el;
159
- obj.api = api;
160
- StellarTimeline.layoutDiv(obj);
161
- }
162
- });
@@ -1,116 +0,0 @@
1
- const weibojs = {
2
- requestAPI: (url, callback, timeout) => {
3
- let retryTimes = 5;
4
- function request() {
5
- return new Promise((resolve, reject) => {
6
- let status = 0; // 0 等待 1 完成 2 超时
7
- let timer = setTimeout(() => {
8
- if (status === 0) {
9
- status = 2;
10
- timer = null;
11
- reject('请求超时');
12
- if (retryTimes == 0) {
13
- timeout();
14
- }
15
- }
16
- }, 5000);
17
- fetch(url).then(function(response) {
18
- if (status !== 2) {
19
- clearTimeout(timer);
20
- resolve(response);
21
- timer = null;
22
- status = 1;
23
- }
24
- if (response.ok) {
25
- return response.json();
26
- }
27
- throw new Error('Network response was not ok.');
28
- }).then(function(data) {
29
- retryTimes = 0;
30
- callback(data);
31
- }).catch(function(error) {
32
- if (retryTimes > 0) {
33
- retryTimes -= 1;
34
- setTimeout(() => {
35
- request();
36
- }, 5000);
37
- } else {
38
- timeout();
39
- }
40
- });
41
- });
42
- }
43
- request();
44
- },
45
- layoutDiv: (cfg) => {
46
- const el = $(cfg.el)[0];
47
- $(el).append('<div class="loading-wrap"><svg xmlns="http://www.w3.org/2000/svg" width="2em" height="2em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-width="2"><path stroke-dasharray="60" stroke-dashoffset="60" stroke-opacity=".3" d="M12 3C16.9706 3 21 7.02944 21 12C21 16.9706 16.9706 21 12 21C7.02944 21 3 16.9706 3 12C3 7.02944 7.02944 3 12 3Z"><animate fill="freeze" attributeName="stroke-dashoffset" dur="1.3s" values="60;0"/></path><path stroke-dasharray="15" stroke-dashoffset="15" d="M12 3C16.9706 3 21 7.02944 21 12"><animate fill="freeze" attributeName="stroke-dashoffset" dur="0.3s" values="15;0"/><animateTransform attributeName="transform" dur="1.5s" repeatCount="indefinite" type="rotate" values="0 12 12;360 12 12"/></path></g></svg></div>');
48
- weibojs.requestAPI(cfg.api, function(data) {
49
- $(el).find('.loading-wrap').remove();
50
- const arr = data.tweets || [];
51
- const limit = el.getAttribute('limit');
52
- arr.forEach((item, i) => {
53
- if (limit && i >= limit) {
54
- return;
55
- }
56
- var cell = '<div class="timenode" index="' + i + '">';
57
- cell += '<div class="header">';
58
- cell += '<div class="user-info">';
59
- cell += '<img src="' + (data.user.avatar_hd || cfg.avatar) + '" onerror="javascript:this.src=\'' + cfg.avatar + '\';">';
60
- cell += '<span>' + data.user.nick_name + '</span>';
61
- cell += '</div>';
62
- cell += '<p>' + item.created_at + '</p>';
63
- cell += '</div>';
64
- cell += '<div class="body">';
65
- cell += '<a class="body" href="' + item.url + '" target="_blank" rel="external nofollow noopener noreferrer">';
66
- cell += item.content;
67
- cell += '</a>';
68
- // cell += '</div>';
69
- // 每条微博的右下角 转发 评论 点赞
70
- cell += '<div class="footer">';
71
- cell += '<div class="flex left">';
72
- cell += '</div>';
73
- cell += '<div class="flex right">';
74
- cell += '<div class="item reaction repost">';
75
- cell += '<a class="item comments last" href="' + item.url + '#issuecomment-new" target="_blank" rel="external nofollow noopener noreferrer">';
76
- cell += '<span>' + '🔗' + ' ' + item.reposts_count + '</span>';
77
- cell += '</a>';
78
- cell += '</div>';
79
- cell += '<a class="item comments last" href="' + item.url + '#issuecomment-new" target="_blank" rel="external nofollow noopener noreferrer">';
80
- cell += '<span><svg t="1666270368054" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2528" width="200" height="200"><path d="M952 64H72C32.3 64 0 96.3 0 136v508c0 39.7 32.3 72 72 72h261l128 128c14 14 32.5 21.1 50.9 21.1s36.9-7 50.9-21.1l128-128h261c39.7 0 72-32.3 72-72V136c0.2-39.7-32.1-72-71.8-72zM222 462c-39.8 0-72-32.2-72-72s32.2-72 72-72 72 32.2 72 72-32.2 72-72 72z m290-7.7c-39.8 0-72-32.2-72-72s32.2-72 72-72 72 32.2 72 72c0 39.7-32.2 72-72 72z m290 8c-39.8 0-72-32.2-72-72s32.2-72 72-72 72 32.2 72 72c0 39.7-32.2 72-72 72z" p-id="2529"></path></svg> '
81
- + (item.comments_count || 0) + '</span>';
82
- cell += '</a>';
83
- cell += '<div class="item reaction attitudes">';
84
- cell += '<a class="item comments last" href="' + item.url + '#issuecomment-new" target="_blank" rel="external nofollow noopener noreferrer">';
85
- cell += '<span>' + '👍' + ' ' + item.attitudes_count + '</span>';
86
- cell += '</a>';
87
- cell += '</div>';
88
-
89
- cell += '</div>';
90
- cell += '</div>';
91
- // 右下角结束
92
- $(el).append(cell);
93
- });
94
- }, function() {
95
- $(el).find('.loading-wrap svg').remove();
96
- $(el).find('.loading-wrap').append('<svg xmlns="http://www.w3.org/2000/svg" width="2em" height="2em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path stroke-dasharray="60" stroke-dashoffset="60" d="M12 3L21 20H3L12 3Z"><animate fill="freeze" attributeName="stroke-dashoffset" dur="0.5s" values="60;0"/></path><path stroke-dasharray="6" stroke-dashoffset="6" d="M12 10V14"><animate fill="freeze" attributeName="stroke-dashoffset" begin="0.6s" dur="0.2s" values="6;0"/></path></g><circle cx="12" cy="17" r="1" fill="currentColor" fill-opacity="0"><animate fill="freeze" attributeName="fill-opacity" begin="0.8s" dur="0.4s" values="0;1"/></circle></svg>');
97
- $(el).find('.loading-wrap').addClass('error');
98
- });
99
- },
100
- }
101
-
102
- $(function () {
103
- const els = document.getElementsByClassName('stellar-weibo-api');
104
- for (var i = 0; i < els.length; i++) {
105
- const el = els[i];
106
- const api = el.getAttribute('api'); // 这个API可以返回微博的json文件
107
- if (api == null) {
108
- continue;
109
- }
110
- var cfg = new Object();
111
- cfg.el = el;
112
- cfg.api = api;
113
- cfg.avatar = 'https://gcore.jsdelivr.net/gh/cdn-x/placeholder@1.0.12/avatar/round/3442075.svg';
114
- weibojs.layoutDiv(cfg);
115
- }
116
- });