hexo-theme-solitude 1.8.0 → 1.8.1

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.
@@ -39,7 +39,7 @@ div#console
39
39
  div.console-btn-item#consoleMusic(onclick="sco.musicToggle()")
40
40
  span.music-switch(title=_p('console.switch_music'))
41
41
  i.solitude.st-disc-fill
42
- if theme.comment.enable && theme.comment.commentBarrage
42
+ if theme.comment.use && theme.comment.commentBarrage
43
43
  div.console-btn-item.on#consoleCommentBarrage(onclick="sco.switchCommentBarrage()")
44
44
  span.commentBarrage
45
45
  i.solitude.st-chat-fill
@@ -52,7 +52,7 @@ div#footer-bar
52
52
  a.footer-bar-link(href=url_for("/"))= config.author
53
53
  div.footer-bar-right
54
54
  each item in theme.footer.links
55
- a.footer-bar-link(href=url_for(item.url), title=item.name)= item.name
55
+ a.footer-bar-link(href=url_for(item.url), alt=item.name)!= item.name
56
56
  a.footer-bar-link.cc(href=url_for(theme.footer.license), aria-label = 'copyright')
57
57
  i.solitude.st-copyright-line
58
58
  i.solitude.st-creative-commons-by-line
@@ -65,5 +65,5 @@ if theme.footer.privacy
65
65
  span.cookies-tip= __('cookies.tip')
66
66
  a.cookies-link(href=url_for(theme.footer.privacy), title=_p('cookies.privacy'))
67
67
  i.solitude.st-right-btn-fill
68
- if theme.comment.enable && theme.comment.commentBarrage
68
+ if theme.comment.use && theme.comment.commentBarrage
69
69
  div.comment-barrage.needEndHide
@@ -26,7 +26,7 @@
26
26
 
27
27
  let comment = false
28
28
 
29
- if (theme.comment.enable) {
29
+ if (theme.comment.use) {
30
30
  comment = {
31
31
  avatar: theme.comment.avatar,
32
32
  commentBarrage: theme.comment.commentBarrage,
@@ -85,7 +85,7 @@
85
85
  }
86
86
  }
87
87
 
88
- if (theme.comment.enable && theme.comment.commentBarrage) {
88
+ if (theme.comment.use && theme.comment.commentBarrage) {
89
89
  lang.barrage = {
90
90
  title: _p('commentBarrage.title'),
91
91
  }
@@ -106,7 +106,7 @@
106
106
  stop: _p('right_menu.music.stop'),
107
107
  }
108
108
  }
109
- if (theme.comment.enable && theme.comment.commentBarrage) {
109
+ if (theme.comment.use && theme.comment.commentBarrage) {
110
110
  rightMenu.barrage = {
111
111
  open: _p('right_menu.barrage.open'),
112
112
  close: _p('right_menu.barrage.close')
@@ -28,7 +28,7 @@ if theme.pwa.enable
28
28
 
29
29
  script.
30
30
  console.log(
31
- "%c Program: Hexo %c Theme: Solitude %c Version: v1.8.0",
31
+ "%c Program: Hexo %c Theme: Solitude %c Version: v1.8.1",
32
32
  "border-radius:5px 0 0 5px;padding: 5px 10px;color:white;background:#ff3842;",
33
33
  "padding: 5px 10px;color:white;background:#3e9f50;",
34
34
  "border-radius:0 5px 5px 0;padding: 5px 10px;background:#0084ff;color:white;"
@@ -39,7 +39,4 @@ if theme.extends.head
39
39
  != item
40
40
 
41
41
  script(src=url_for(theme.cdn.utils))
42
- script(src=url_for(theme.cdn.main))
43
-
44
- if theme.comment.use.includes('Valine')
45
- script(src=url_for(theme.cdn.blueimp_md5))
42
+ script(src=url_for(theme.cdn.main))
@@ -17,7 +17,7 @@ div#rightMenu
17
17
  div.rightMenu-item#menu-pastetext
18
18
  i.solitude.st-clipboard-fill
19
19
  span= _p('right_menu.paste')
20
- if theme.comment.enable
20
+ if theme.comment.use
21
21
  div.rightMenu-item#menu-commenttext
22
22
  i.solitude.st-chat-new-fill
23
23
  span= _p('right_menu.comment')
@@ -56,7 +56,7 @@ div#rightMenu
56
56
  i.solitude(class=item.icon)
57
57
  span= item.name
58
58
  div.rightMenu-group.rightMenu-line.rightMenuOther
59
- if theme.right_menu.commentBarrage && theme.comment.enable && theme.comment.commentBarrage
59
+ if theme.right_menu.commentBarrage && theme.comment.use && theme.comment.commentBarrage
60
60
  div.rightMenu-item#menu-commentBarrage(onclick="sco.switchCommentBarrage()")
61
61
  i.solitude.st-chat-fill
62
62
  span.menu-commentBarrage-text= _p('right_menu.barrage.open')
@@ -7,7 +7,7 @@
7
7
  a.banner-button.secondary(onclick="travelling()")
8
8
  i.solitude.st-signal-tower-fill
9
9
  span.banner-button-text=_p('link.banner.random')
10
- if theme.comment.enable
10
+ if theme.comment.use
11
11
  a.banner-button(onclick="sco.scrollToComment()")
12
12
  i.solitude.st-right-btn-fill
13
13
  span.solitude.banner-button-text=_p('link.banner.toComment')
@@ -40,25 +40,26 @@
40
40
  if theme.post.meta.pv
41
41
  a.post-meta-pv(href=url_for(page.path), title=_p('post.pv'))
42
42
  i.post-meta-icon.solitude.st-fire-fill
43
- case theme.comment.use[0]
44
- when "Twikoo"
45
- span#twikoo_visitors
46
- i.solitude.st-loading-line
47
- when "Waline"
48
- span.waline-pageview-count
49
- i.solitude.st-loading-line
50
- when "Valine"
51
- span.leancloud_visitors(id=url_for(page.path))
52
- span.leancloud-visitors-count
43
+ if theme.comment.use
44
+ case theme.comment.use[0]
45
+ when "Twikoo"
46
+ span#twikoo_visitors
47
+ i.solitude.st-loading-line
48
+ when "Waline"
49
+ span.waline-pageview-count
50
+ i.solitude.st-loading-line
51
+ when "Valine"
52
+ span.leancloud_visitors(id=url_for(page.path))
53
+ span.leancloud-visitors-count
54
+ i.solitude.st-loading-line
55
+ when 'Artalk'
56
+ span#ArtalkPV
53
57
  i.solitude.st-loading-line
54
- when 'Artalk'
55
- span#ArtalkPV
58
+ else
59
+ if theme.busuanzi
60
+ span#busuanzi_value_page_pv
56
61
  i.solitude.st-loading-line
57
- default
58
- if theme.busuanzi
59
- span#busuanzi_value_page_pv
60
- i.solitude.st-loading-line
61
- if theme.post.meta.comment && page.comment && theme.comment.count
62
+ if theme.post.meta.comment && page.comment && theme.comment.count && theme.comment.use
62
63
  span.post-meta-commentcount(title=_p('post.comment'), onclick="sco.scrollTo('post-comment')")
63
64
  i.solitude.st-chat-fill
64
65
  a(href=url_for(page.path) + "#post-comment")
@@ -25,7 +25,7 @@ script.
25
25
  utils.lightbox($content.querySelectorAll('img:not([atk-emoticon])'))
26
26
  sco.owoBig({body: '.atk-grp', item: '.atk-item'})
27
27
  })
28
- !{commentBarrage} && getBarrage(array)
28
+ !{commentBarrage} && barrageArtalk(array)
29
29
  })
30
30
  const destroyArtalk = () => artalkItem.destroy()
31
31
  utils.addGlobalFn('pjax', destroyArtalk, 'destroyArtalk')
@@ -54,7 +54,7 @@ script.
54
54
 
55
55
  if commentBarrage
56
56
  script.
57
- async function getBarrage(array) {
57
+ const barrageArtalk = async array => {
58
58
  await utils.getScript('!{url_for(theme.cdn.commentBarrage)}').then(() => {
59
59
  initializeCommentBarrage(array)
60
60
  })
@@ -12,7 +12,7 @@ script.
12
12
  urls: [window.location.pathname],
13
13
  includeReply: false
14
14
  }).then(res => {
15
- ele.forEach(item => item.textContent=res[0].count)
15
+ ele.forEach(item => item.textContent = res[0].count)
16
16
  }).catch(err => {
17
17
  console.error(err)
18
18
  })
@@ -33,7 +33,7 @@ script.
33
33
  item: '.OwO-items li'
34
34
  })
35
35
 
36
- !{commentBarrage} && getBarrage()
36
+ if (!{commentBarrage}) await barrageTwikoo()
37
37
  }
38
38
 
39
39
  const loadTwikoo = () => {
@@ -51,23 +51,20 @@ script.
51
51
 
52
52
  if commentBarrage
53
53
  script.
54
- async function getBarrage() {
55
- try {
56
- const response = await fetch("!{envId}", {
57
- method: "POST",
58
- headers: {
59
- "Content-Type": "application/json"
60
- },
61
- body: JSON.stringify({
62
- event: "COMMENT_GET",
63
- accessToken: "!{accessToken}",
64
- url: window.location.pathname
65
- })
66
- });
67
- if (!response.ok) {
68
- throw new Error("HTTP error! status: " + response.status);
69
- }
70
- const data = await response.json();
54
+ const barrageTwikoo = async () => {
55
+ await fetch("!{envId}", {
56
+ method: "POST",
57
+ headers: {
58
+ "Content-Type": "application/json"
59
+ },
60
+ body: JSON.stringify({
61
+ event: "COMMENT_GET",
62
+ accessToken: "!{accessToken}",
63
+ url: window.location.pathname
64
+ })
65
+ }).then(async res => {
66
+ if (!res.ok) throw new Error("HTTP error! status: " + res.status)
67
+ const data = await res.json();
71
68
  await utils.getScript('!{url_for(theme.cdn.commentBarrage)}').then(() => {
72
69
  initializeCommentBarrage((data.data).map(item => Object.assign({
73
70
  content: item.comment,
@@ -76,7 +73,5 @@ if commentBarrage
76
73
  id: item.id
77
74
  })))
78
75
  })
79
- } catch (error) {
80
- console.error("An error occurred while fetching comments: ", error);
81
- }
76
+ }).catch(error => console.error("An error occurred while fetching comments: ", error))
82
77
  }
@@ -27,7 +27,7 @@ script.
27
27
  else {
28
28
  await utils.getScript('!{url_for(theme.cdn.valine)}').then(initValine)
29
29
  }
30
- !{commentBarrage} && getBarrage()
30
+ !{commentBarrage} && barrageValine()
31
31
  }
32
32
  if ('!{use[0]}' === 'Valine' || !{lazyload}) {
33
33
  if (!{lazyload}) utils.loadComment(document.getElementById('vcomment'), loadValine)
@@ -39,26 +39,24 @@ script.
39
39
 
40
40
  if commentBarrage
41
41
  script.
42
- async function getBarrage() {
42
+ const barrageValine = async () => {
43
43
  const url = new URL('!{serverURLs}/1.1/classes/Comment')
44
44
  const params = {
45
45
  url: window.location.pathname,
46
46
  order: '-createdAt'
47
47
  }
48
48
  Object.entries(params).forEach(([key, value]) => url.searchParams.append(key, value))
49
- try {
50
- const response = await fetch(url, {
51
- method: "GET",
52
- headers: {
53
- "X-LC-Id": "#{appId}",
54
- "X-LC-Key": "#{appKey}",
55
- "Content-Type": "application/json"
56
- },
57
- })
58
- if (!response.ok) {
59
- throw new Error(`HTTP error! status: ${response.status}`)
60
- }
61
- const data = await response.json()
49
+ await fetch(url, {
50
+ method: "GET",
51
+ headers: {
52
+ "X-LC-Id": "#{appId}",
53
+ "X-LC-Key": "#{appKey}",
54
+ "Content-Type": "application/json"
55
+ },
56
+ }).then(async res => {
57
+ if (!res.ok) throw new Error(`HTTP error! status: ${res.status}`)
58
+ const data = await res.json()
59
+ if(typeof md5 ==="undefined") await utils.getScript('!{url_for(theme.cdn.blueimp_md5)}')
62
60
  await utils.getScript('!{url_for(theme.cdn.commentBarrage)}')
63
61
  initializeCommentBarrage(data.results
64
62
  .filter(item => item.url === window.location.pathname)
@@ -68,7 +66,5 @@ if commentBarrage
68
66
  mailMd5: md5(item.mail),
69
67
  id: item.objectId
70
68
  })))
71
- } catch (error) {
72
- console.error("An error occurred while fetching comments: ", error)
73
- }
69
+ }).catch(error => console.error("An error occurred while fetching comments: ", error))
74
70
  }
@@ -30,7 +30,7 @@ script.
30
30
  initWaline(walineInitFunction)
31
31
  window.walineFn = walineInitFunction
32
32
  }
33
- if (!{commentBarrage}) getBarrage()
33
+ if (!{commentBarrage}) barrageWaline()
34
34
  }
35
35
 
36
36
  if ('!{use[0]}' === 'Valine' || !{lazyload}) {
@@ -41,17 +41,16 @@ script.
41
41
 
42
42
  if commentBarrage
43
43
  script.
44
- async function getBarrage() {
44
+ const barrageWaline = async () => {
45
45
  const url = new URL('!{envId}/api/comment')
46
46
  const params = {path: window.location.pathname, sortBy: 'insertedAt_asc'}
47
47
  Object.entries(params).forEach(([key, value]) => url.searchParams.append(key, value))
48
- try {
49
- const response = await fetch(url, {
50
- method: "GET",
51
- headers: {
52
- "Content-Type": "application/json"
53
- },
54
- })
48
+ const response = await fetch(url, {
49
+ method: "GET",
50
+ headers: {
51
+ "Content-Type": "application/json"
52
+ },
53
+ }).then(async res => {
55
54
  if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`)
56
55
  const data = await response.json();
57
56
  await utils.getScript('!{url_for(theme.cdn.commentBarrage)}')
@@ -61,7 +60,5 @@ if commentBarrage
61
60
  content: item.comment,
62
61
  id: item.objectId
63
62
  })))
64
- } catch (error) {
65
- console.error("An error occurred while fetching comments: ", error)
66
- }
63
+ }).catch(error => console.error("An error occurred while fetching comments: ", error))
67
64
  }
@@ -1,10 +1,10 @@
1
- if theme.console_plus && theme.comment.newest_comment.enable
1
+ if theme.comment.use && theme.console_plus && theme.comment.newest_comment.enable
2
2
  case theme.comment.use[0]
3
3
  when 'Twikoo'
4
- !=partial('includes/widgets/third-party/news-comment/twikoo',{}, {cache: true})
4
+ !=partial('includes/widgets/third-party/news-comment/twikoo', {}, {cache: true})
5
5
  when 'Waline'
6
- !=partial('includes/widgets/third-party/news-comment/waline',{}, {cache: true})
6
+ !=partial('includes/widgets/third-party/news-comment/waline', {}, {cache: true})
7
7
  when 'Valine'
8
- !=partial('includes/widgets/third-party/news-comment/valine',{}, {cache: true})
8
+ !=partial('includes/widgets/third-party/news-comment/valine', {}, {cache: true})
9
9
  when 'Artalk'
10
- !=partial('includes/widgets/third-party/news-comment/artalk',{}, {cache: true})
10
+ !=partial('includes/widgets/third-party/news-comment/artalk', {}, {cache: true})
@@ -5,7 +5,10 @@ script.
5
5
 
6
6
  const replacements = [
7
7
  {regex: /<img.*?src="(.*?)"?[^\>]+>/ig, replacement: '[!{_p("console.newest_comment.image")}]'},
8
- {regex: /<a[^>]+?href=["']?([^"']+)["']?[^>]*>([^<]+)<\/a>/gi, replacement: '[!{_p("console.newest_comment.link")}]'},
8
+ {
9
+ regex: /<a[^>]+?href=["']?([^"']+)["']?[^>]*>([^<]+)<\/a>/gi,
10
+ replacement: '[!{_p("console.newest_comment.link")}]'
11
+ },
9
12
  {regex: /```[\s\S]*?```/g, replacement: '[!{_p("console.newest_comment.code")}]'},
10
13
  {regex: /<[^>]+>/g, replacement: ""}
11
14
  ];
@@ -26,17 +29,16 @@ script.
26
29
  }
27
30
 
28
31
  const getComment = async () => {
29
- try {
30
- const settings = {
31
- "method": "GET",
32
- "headers": {
33
- "X-LC-Id": '!{theme.valine.appId}',
34
- "X-LC-Key": '!{theme.valine.appKey}',
35
- "Content-Type": "application/json"
36
- },
37
- }
38
-
39
- const res = await fetch('!{theme.valine.serverURLs}/1.1/classes/Comment?limit=8&order=-createdAt', settings)
32
+ const settings = {
33
+ "method": "GET",
34
+ "headers": {
35
+ "X-LC-Id": '!{theme.valine.appId}',
36
+ "X-LC-Key": '!{theme.valine.appKey}',
37
+ "Content-Type": "application/json"
38
+ },
39
+ }
40
+ if (typeof md5 === "undefined") await utils.getScript('!{url_for(theme.cdn.blueimp_md5)}')
41
+ await fetch('!{theme.valine.serverURLs}/1.1/classes/Comment?limit=8&order=-createdAt', settings).then(async res => {
40
42
  const result = await res.json()
41
43
  window.res = result
42
44
  const valineArray = result.results.map(e => {
@@ -50,10 +52,10 @@ script.
50
52
  })
51
53
  utils.saveToLocal.set('valine-newest-comment', valineArray, !{theme.comment.newest_comment.storage})
52
54
  generateHtml(valineArray)
53
- } catch (err) {
54
- console.error(err)
55
+ }).catch(error => {
56
+ console.error(error);
55
57
  $asideList.textContent = "!{_p('newest_comment.error')}"
56
- }
58
+ })
57
59
  }
58
60
 
59
61
  const generateHtml = array => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hexo-theme-solitude",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
4
4
  "description": "A beautiful, powerful, and efficient Hexo theme developed by the efu.",
5
5
  "main": "package.json",
6
6
  "scripts": {
@@ -19,7 +19,7 @@ hexo.extend.filter.register('after_post_render', function (data) {
19
19
  data.excerpt = data.title
20
20
  data.toc = !!(config.aside.toc.page && data.toc !== false && data.aside);
21
21
  }
22
- data.comment = !!(config.comment.enable && data.comment !== false);
22
+ data.comment = !!(config.comment.use && data.comment !== false);
23
23
  return data;
24
24
  });
25
25
 
@@ -26,5 +26,5 @@ if hexo-config('search.enable')
26
26
  @import "_tags/*"
27
27
 
28
28
  // comment
29
- if hexo-config('comment.enable')
29
+ if hexo-config('comment.use')
30
30
  @import '_comments/comment.styl'
@@ -1,15 +1,12 @@
1
- /**
2
- * Comment Barrage
3
- * author: @efu
4
- * website: efu.me
5
- * copyright: MIT
6
- * date: 2024-04-12
7
- * update: 2024-04-12
8
- * @param array
9
- */
10
1
  function initializeCommentBarrage(array) {
11
2
  if (array === undefined) return;
12
- new class {
3
+ let existingBarrage = window.currentBarrage;
4
+
5
+ if (existingBarrage) {
6
+ existingBarrage.destroy();
7
+ }
8
+
9
+ let barrage = class {
13
10
  constructor() {
14
11
  this.config = {
15
12
  barrageTimer: [],
@@ -36,7 +33,7 @@ function initializeCommentBarrage(array) {
36
33
  if (!content) return false;
37
34
  const element = document.createElement("div");
38
35
  element.className = "comment-barrage-item";
39
- element.innerHTML = `<div class="barrageHead"><a class="barrageTitle" href="javascript:sco.scrollTo('post-comment')">${GLOBAL_CONFIG.lang.barrage.title}</a><div class="barrageNick">${comment.nick}</div><img class="barrageAvatar" src="${GLOBAL_CONFIG.comment.avatar}/avatar/${comment.mailMd5}"/><a class="comment-barrage-close" href="javascript:sco.switchCommentBarrage();"><i class="solitude st-close-fill"></i></a></div><a class="barrageContent" href="${comment.id ? `javascript:sco.scrollTo(\'${comment.id}\')` : 'javascript:sco.scrollTo(\'post-comment\')' }">${content}</a>`;
36
+ element.innerHTML = `<div class="barrageHead"><a class="barrageTitle" href="javascript:sco.scrollTo('post-comment')">${GLOBAL_CONFIG.lang.barrage.title}</a><div class="barrageNick">${comment.nick}</div><img class="barrageAvatar" src="${GLOBAL_CONFIG.comment.avatar}/avatar/${comment.mailMd5}"/><a class="comment-barrage-close" href="javascript:sco.switchCommentBarrage();"><i class="solitude st-close-fill"></i></a></div><a class="barrageContent" href="${comment.id ? `javascript:sco.scrollTo(\'${comment.id}\')` : 'javascript:sco.scrollTo(\'post-comment\')'}">${content}</a>`;
40
37
  this.config.dom.appendChild(element);
41
38
  this.config.barrageTimer.push(element);
42
39
  return true;
@@ -74,5 +71,14 @@ function initializeCommentBarrage(array) {
74
71
  this.config.dom.addEventListener('mouseover', () => this.hoverOnCommentBarrage = true);
75
72
  this.config.dom.addEventListener('mouseout', () => this.hoverOnCommentBarrage = false);
76
73
  }
77
- }();
74
+
75
+ destroy() {
76
+ clearInterval(this.commentInterval);
77
+ this.config.dom.removeEventListener('mouseover', () => this.hoverOnCommentBarrage = true)
78
+ this.config.dom.removeEventListener('mouseout', () => this.hoverOnCommentBarrage = false)
79
+ this.config.dom.innerHTML = ""
80
+ }
81
+ }
82
+
83
+ window.currentBarrage = new barrage();
78
84
  }
@@ -130,11 +130,11 @@ window.oncontextmenu = (ele) => {
130
130
  if (selectTextNow && window.getSelection()) {
131
131
  display = true;
132
132
  rm.menuItems.copy.style.display = 'block';
133
- rm.menuItems.comment.style.display = 'block';
133
+ GLOBAL_CONFIG.comment && (rm.menuItems.comment.style.display = 'block');
134
134
  rm.menuItems.search.style.display = 'block';
135
135
  } else {
136
136
  rm.menuItems.copy.style.display = 'none';
137
- rm.menuItems.comment.style.display = 'none';
137
+ GLOBAL_CONFIG.comment && (rm.menuItems.comment.style.display = 'none');
138
138
  rm.menuItems.search.style.display = 'none';
139
139
  }
140
140
 
@@ -220,7 +220,7 @@ window.oncontextmenu = (ele) => {
220
220
  })
221
221
 
222
222
  rm.menuItems.paste.addEventListener('click', () => rm.pasteText() && rm.hideRightMenu())
223
- rm.menuItems.comment.addEventListener('click', () => rm.hideRightMenu() || sco.toTalk(selectTextNow))
223
+ GLOBAL_CONFIG.comment && rm.menuItems.comment.addEventListener('click', () => rm.hideRightMenu() || sco.toTalk(selectTextNow))
224
224
  rm.menuItems.new.addEventListener('click', () => window.open(rm.domhref) && rm.hideRightMenu())
225
225
  rm.menuItems.downloadImg.addEventListener('click', () => rm.downloadImage() && rm.hideRightMenu())
226
226
  rm.menuItems.copyImg.addEventListener('click', () => rm.copyImage() && rm.hideRightMenu())