hexo-theme-solitude 1.7.14 → 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.
Files changed (41) hide show
  1. package/README.md +25 -25
  2. package/{README_zh-cn.md → README_en.md} +25 -25
  3. package/README_zh-tw.md +3 -3
  4. package/_config.yml +41 -34
  5. package/layout/includes/body/mode.pug +6 -3
  6. package/layout/includes/console.pug +1 -1
  7. package/layout/includes/footer.pug +2 -2
  8. package/layout/includes/head/config.pug +3 -36
  9. package/layout/includes/head/page_config.pug +9 -0
  10. package/layout/includes/head.pug +4 -1
  11. package/layout/includes/inject/body.pug +1 -26
  12. package/layout/includes/inject/head.pug +8 -60
  13. package/layout/includes/rightmenu.pug +2 -2
  14. package/layout/includes/widgets/page/links/banner.pug +1 -1
  15. package/layout/includes/widgets/post/postMeta.pug +18 -17
  16. package/layout/includes/widgets/third-party/comments/artalk.pug +29 -18
  17. package/layout/includes/widgets/third-party/comments/comment.pug +48 -12
  18. package/layout/includes/widgets/third-party/comments/twikoo.pug +72 -55
  19. package/layout/includes/widgets/third-party/comments/valine.pug +43 -49
  20. package/layout/includes/widgets/third-party/comments/waline.pug +44 -52
  21. package/layout/includes/widgets/third-party/news-comment/artalk.pug +57 -67
  22. package/layout/includes/widgets/third-party/news-comment/newest-comment.pug +10 -10
  23. package/layout/includes/widgets/third-party/news-comment/twikoo.pug +41 -48
  24. package/layout/includes/widgets/third-party/news-comment/valine.pug +19 -17
  25. package/layout/includes/widgets/third-party/news-comment/waline.pug +3 -3
  26. package/layout/includes/widgets/third-party/pjax.pug +1 -0
  27. package/package.json +1 -1
  28. package/plugins.yml +2 -2
  29. package/scripts/event/merge_config.js +280 -255
  30. package/scripts/filter/comment.js +13 -0
  31. package/scripts/filter/default.js +1 -1
  32. package/source/css/_comments/comment.styl +73 -12
  33. package/source/css/_comments/valine.styl +1 -1
  34. package/source/css/_highlight/index.styl +1 -0
  35. package/source/css/_tags/link.styl +7 -2
  36. package/source/css/index.styl +1 -1
  37. package/source/js/barrage_comment.js +18 -12
  38. package/source/js/main.js +42 -18
  39. package/source/js/right_menu.js +3 -3
  40. package/source/js/tw_cn.js +3 -3
  41. package/source/js/utils.js +62 -0
@@ -50,10 +50,6 @@
50
50
  &::before
51
51
  transform translateX(20px)
52
52
 
53
- .comment-wrap
54
- > div:nth-child(2)
55
- display none
56
-
57
53
  .post-comment
58
54
  background var(--efu-card-bg)
59
55
 
@@ -81,26 +77,91 @@ div#post-comment
81
77
  color var(--efu-secondtext)
82
78
  border-radius 8px
83
79
 
80
+ if hexo-config('comment.use')[1]
81
+ &.move
82
+ if hexo-config('comment.count')
83
+ .comment-head
84
+ .count span:first-child
85
+ display none
86
+
87
+ .count span:last-child
88
+ display inline-block
89
+
90
+ #switch-btn::before
91
+ transform translateX(20px)
92
+
93
+ .comment-wrap
94
+ > div:first-child
95
+ display none
96
+
97
+ > div:last-child
98
+ display block
99
+ animation 0.5s ease 0s 1 normal none running tabshow
100
+
84
101
  .comment-head
85
- font-size .8em !important
102
+ font-size .8em
86
103
  margin-bottom .5rem
87
- display flex
88
- align-items center
89
- flex-wrap wrap
90
104
  position relative
91
105
 
106
+ if hexo-config('comment.use')[1]
107
+ .count span:last-child
108
+ display none
109
+
110
+ .comment-switch
111
+ display inline-block
112
+ float right
113
+ margin 2px auto 0
114
+ padding 4px 16px
115
+ width max-content
116
+ user-select none
117
+
118
+ #switch-btn
119
+ position relative
120
+ display inline-block
121
+ margin 0 8px 0
122
+ width 42px
123
+ height 22px
124
+ border-radius 34px
125
+ background-color var(--efu-main)
126
+ vertical-align middle
127
+ cursor pointer
128
+ transition .4s
129
+ border var(--style-border-always)
130
+
131
+ &::before
132
+ position absolute
133
+ bottom 3px
134
+ left 4px
135
+ width 14px
136
+ height 14px
137
+ border-radius 50%
138
+ background-color #fff
139
+ content ''
140
+ transition .4s
141
+
142
+ if hexo-config('comment.use')[1]
143
+ .comment-wrap
144
+ > div:last-child
145
+ display none
146
+
147
+ > div:first-child
148
+ animation 0.5s ease 0s 1 normal none running tabshow
149
+
92
150
  #owo-big
93
151
  position fixed
94
152
  align-items center
95
- background-color var(--heo-card-bg)
153
+ background-color var(--efu-card-bg)
96
154
  border var(--style-border-always)
97
155
  border-radius 10px
98
156
  z-index 9999
99
157
  display none
100
158
  transform translate(0, -105%)
101
159
  overflow hidden
102
- animation owoIn .3s cubic-bezier(.42,0,.3,1.11)
160
+ animation owoIn .3s cubic-bezier(.42, 0, .3, 1.11)
103
161
  padding 1rem
104
162
 
105
- @import 'twikoo.styl' when hexo-config('comment.type') == 'twikoo'
106
- @import 'valine.styl' when hexo-config('comment.type') == 'valine'
163
+ if hexo-config('twikoo.style') && 'Twikoo' in hexo-config('comment.use')
164
+ @import 'twikoo.styl'
165
+
166
+ if hexo-config('valine.style') && 'Valine' in hexo-config('comment.use')
167
+ @import 'valine.styl'
@@ -1,4 +1,4 @@
1
- #comment
1
+ #vcomment
2
2
  .vcount
3
3
  display none !important
4
4
 
@@ -42,6 +42,7 @@ figure
42
42
  align-items center
43
43
  overflow hidden
44
44
  min-height 1.2rem
45
+ border-radius 8px 8px 0 0
45
46
  height 2.15em
46
47
  font-size 16px
47
48
  background var(--efu-hltools-bg)
@@ -1,5 +1,5 @@
1
1
  #article-container
2
- .tag-link
2
+ a.tag-link
3
3
  background var(--efu-secondbg)
4
4
  border-radius 8px !important
5
5
  display flex
@@ -14,10 +14,15 @@
14
14
  border var(--style-border-hover) !important
15
15
 
16
16
  .tag-link-tips
17
- color var(--efu-card-bg)
17
+ color var(--efu-white)
18
+
19
+ i
20
+ opacity 1
18
21
 
19
22
  i
23
+ transition .3s
20
24
  margin-left auto
25
+ opacity .6
21
26
 
22
27
  .tag-link-bottom
23
28
  display flex
@@ -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
  }
package/source/js/main.js CHANGED
@@ -71,7 +71,7 @@ const percent = () => {
71
71
  let viewportBottom = window.scrollY + document.documentElement.clientHeight
72
72
  let remainingScroll = totalHeight - scrollTop
73
73
 
74
- if ((document.getElementById("post-comment") || document.getElementById("footer")).offsetTop < viewportBottom || scrollPercent > 90) {
74
+ if ((document.getElementById("post-comment") || document.getElementById("footer"))?.offsetTop < viewportBottom || scrollPercent > 90) {
75
75
  document.querySelector("#nav-totop").classList.add("long")
76
76
  percentElement.innerHTML = GLOBAL_CONFIG.lang.backtop
77
77
  } else {
@@ -281,7 +281,7 @@ let sco = {
281
281
  },
282
282
  switchHideAside: function () {
283
283
  const htmlClassList = document.documentElement.classList;
284
- htmlClassList.contains("hide-aside") ? saveToLocal.set("aside-status", "show", 1) : saveToLocal.set("aside-status", "hide", 1)
284
+ htmlClassList.contains("hide-aside") ? utils.saveToLocal.set("aside-status", "show", 1) : saveToLocal.set("aside-status", "hide", 1)
285
285
  htmlClassList.toggle("hide-aside");
286
286
  htmlClassList.contains("hide-aside") ? document.querySelector("#consoleHideAside").classList.add("on") : document.querySelector("#consoleHideAside").classList.remove("on");
287
287
  },
@@ -317,12 +317,12 @@ let sco = {
317
317
  'light'
318
318
  if (nowMode === 'light') {
319
319
  document.documentElement.setAttribute('data-theme', 'dark')
320
- saveToLocal.set('theme', 'dark', 0.02);
320
+ utils.saveToLocal.set('theme', 'dark', 0.02);
321
321
  utils.snackbarShow(GLOBAL_CONFIG.lang.theme.dark, false, 2000)
322
322
  right_menu && rm.mode(true)
323
323
  } else {
324
324
  document.documentElement.setAttribute('data-theme', 'light')
325
- saveToLocal.set('theme', 'light', 0.02);
325
+ utils.saveToLocal.set('theme', 'light', 0.02);
326
326
  utils.snackbarShow(GLOBAL_CONFIG.lang.theme.light, false, 2000)
327
327
  right_menu && rm.mode(false)
328
328
  }
@@ -351,7 +351,7 @@ let sco = {
351
351
  el && GLOBAL_CONFIG.runtime && (el.innerText = utils.timeDiff(new Date(GLOBAL_CONFIG.runtime), new Date()) + GLOBAL_CONFIG.lang.time.day)
352
352
  },
353
353
  toTalk: function (txt) {
354
- const inputs = ["#wl-edit", ".el-textarea__inner", "#veditor"]
354
+ const inputs = ["#wl-edit", ".el-textarea__inner", "#veditor",".atk-textarea"]
355
355
  for (let i = 0; i < inputs.length; i++) {
356
356
  let el = document.querySelector(inputs[i])
357
357
  if (el != null) {
@@ -617,8 +617,7 @@ let sco = {
617
617
  document.getElementById("toPageButton").href = targetPageUrl;
618
618
  }
619
619
  },
620
- owoBig() {
621
- const owoSelectors = GLOBAL_CONFIG.comment.owo
620
+ owoBig(owoSelector) {
622
621
 
623
622
  let owoBig = document.getElementById('owo-big');
624
623
  if (!owoBig) {
@@ -641,8 +640,8 @@ let sco = {
641
640
 
642
641
  const showOwoBig = (event) => {
643
642
  const target = event.target;
644
- const owoItem = target.closest(owoSelectors.item);
645
- if (owoItem && target.closest(owoSelectors.body)) {
643
+ const owoItem = target.closest(owoSelector.item);
644
+ if (owoItem && target.closest(owoSelector.body)) {
646
645
  const imgSrc = owoItem.querySelector('img')?.src;
647
646
  if (imgSrc) {
648
647
  owoBig.innerHTML = `<img src="${imgSrc}" style="max-width: 100%; height: auto;">`;
@@ -653,7 +652,7 @@ let sco = {
653
652
  };
654
653
 
655
654
  const hideOwoBig = (event) => {
656
- if (event.target.closest(owoSelectors.item) && event.target.closest(owoSelectors.body)) {
655
+ if (event.target.closest(owoSelector.item) && event.target.closest(owoSelector.body)) {
657
656
  owoBig.style.display = 'none';
658
657
  }
659
658
  };
@@ -674,6 +673,20 @@ let sco = {
674
673
  item.style.display = 'inline'
675
674
  })
676
675
  },
676
+ switchComments() {
677
+ const switchBtn = document.getElementById('switch-btn')
678
+ if (!switchBtn) return
679
+ let switchDone = false
680
+ const commentContainer = document.getElementById('post-comment')
681
+ const handleSwitchBtn = () => {
682
+ commentContainer.classList.toggle('move')
683
+ if (!switchDone && typeof loadTwoComment === 'function') {
684
+ switchDone = true
685
+ loadTwoComment()
686
+ }
687
+ }
688
+ utils.addEventListenerPjax(switchBtn, 'click', handleSwitchBtn)
689
+ }
677
690
  }
678
691
 
679
692
  const addHighlight = () => {
@@ -798,6 +811,17 @@ const addCopyright = () => {
798
811
  document.body.addEventListener('copy', handleCopy)
799
812
  }
800
813
 
814
+ const asideStatus = () =>{
815
+ const asideStatus = utils.saveToLocal.get('aside-status')
816
+ if (asideStatus !== undefined) {
817
+ if (asideStatus === 'hide') {
818
+ document.documentElement.classList.add('hide-aside')
819
+ } else {
820
+ document.documentElement.classList.remove('hide-aside')
821
+ }
822
+ }
823
+ }
824
+
801
825
  class tabs {
802
826
  static init() {
803
827
  this.clickFnOfTabs()
@@ -835,12 +859,6 @@ class tabs {
835
859
  }
836
860
  }
837
861
 
838
- sco.initAdjust()
839
- percent()
840
- initObserver()
841
- addCopyright()
842
- sco.initConsoleState()
843
-
844
862
  window.refreshFn = () => {
845
863
  document.body.setAttribute('data-type', PAGE_CONFIG.page)
846
864
  if (PAGE_CONFIG.is_home || PAGE_CONFIG.is_page) {
@@ -862,17 +880,23 @@ window.refreshFn = () => {
862
880
  GLOBAL_CONFIG.lazyload.enable && utils.lazyloadImg()
863
881
  GLOBAL_CONFIG.lightbox && utils.lightbox(document.querySelectorAll("#article-container img:not(.flink-avatar,.gallery-group img)"))
864
882
  GLOBAL_CONFIG.randomlink && randomLinksList()
865
- PAGE_CONFIG.comment && initComment()
866
883
  PAGE_CONFIG.toc && toc.init();
867
884
  (PAGE_CONFIG.is_post || PAGE_CONFIG.is_page) && ((addHighlight()) || tabs.init())
868
885
  PAGE_CONFIG.is_home && showTodayCard()
869
886
  GLOBAL_CONFIG.covercolor.enable && coverColor()
870
887
  PAGE_CONFIG.page === "music" && scoMusic.init()
871
- GLOBAL_CONFIG.post_ai && PAGE_CONFIG.page === "post" && efu_ai.init()
888
+ GLOBAL_CONFIG.post_ai && PAGE_CONFIG.is_post && efu_ai.init()
889
+ sco.switchComments()
872
890
  }
873
891
 
874
892
  document.addEventListener('DOMContentLoaded', function () {
893
+ sco.initAdjust()
894
+ percent()
895
+ initObserver()
896
+ addCopyright()
897
+ sco.initConsoleState()
875
898
  window.refreshFn()
899
+ asideStatus()
876
900
  })
877
901
 
878
902
  window.onkeydown = function (e) {
@@ -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())
@@ -5,9 +5,9 @@ document.addEventListener('DOMContentLoaded', function () {
5
5
  const msgToTraditionalChinese = '轉為繁體';
6
6
  const msgToSimplifiedChinese = '转为简体';
7
7
  let targetEncoding =
8
- saveToLocal.get(targetEncodingCookie) === undefined
8
+ utils.saveToLocal.get(targetEncodingCookie) === undefined
9
9
  ? defaultEncoding
10
- : Number(saveToLocal.get('translate-chn-cht'))
10
+ : Number(utils.saveToLocal.get('translate-chn-cht'))
11
11
  let translateButtonObject
12
12
 
13
13
  function setLang() {
@@ -68,7 +68,7 @@ document.addEventListener('DOMContentLoaded', function () {
68
68
  translateButtonObject.firstChild.className = 'solitude st-jianben-line'
69
69
  utils.snackbarShow('你已切換為繁體')
70
70
  }
71
- saveToLocal.set(targetEncodingCookie, targetEncoding, 2)
71
+ utils.saveToLocal.set(targetEncodingCookie, targetEncoding, 2)
72
72
  setLang()
73
73
  translateBody()
74
74
  rm.hideRightMenu()
@@ -1,4 +1,33 @@
1
1
  const utils = {
2
+ saveToLocal: {
3
+ set: function setWithExpiry(key, value, ttl) {
4
+ if (ttl === 0)
5
+ return
6
+ const now = new Date()
7
+ const expiryDay = ttl * 86400000
8
+ const item = {
9
+ value: value,
10
+ expiry: now.getTime() + expiryDay
11
+ }
12
+ localStorage.setItem(key, JSON.stringify(item))
13
+ },
14
+
15
+ get: function getWithExpiry(key) {
16
+ const itemStr = localStorage.getItem(key)
17
+
18
+ if (!itemStr) {
19
+ return undefined
20
+ }
21
+ const item = JSON.parse(itemStr)
22
+ const now = new Date()
23
+
24
+ if (now.getTime() > item.expiry) {
25
+ localStorage.removeItem(key)
26
+ return undefined
27
+ }
28
+ return item.value
29
+ }
30
+ },
2
31
  debounce: function (func, wait, immediate) {
3
32
  let timeout
4
33
  return function () {
@@ -278,4 +307,37 @@ const utils = {
278
307
  callback()
279
308
  }
280
309
  },
310
+ getCSS: (url, id = false) => new Promise((resolve, reject) => {
311
+ const link = document.createElement('link')
312
+ link.rel = 'stylesheet'
313
+ link.href = url
314
+ if (id) link.id = id
315
+ link.onerror = reject
316
+ link.onload = link.onreadystatechange = function () {
317
+ const loadState = this.readyState
318
+ if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
319
+ link.onload = link.onreadystatechange = null
320
+ resolve()
321
+ }
322
+ document.head.appendChild(link)
323
+ }),
324
+
325
+ getScript: (url, attr = {}) => new Promise((resolve, reject) => {
326
+ const script = document.createElement('script')
327
+ script.src = url
328
+ script.async = true
329
+ script.onerror = reject
330
+ script.onload = script.onreadystatechange = function () {
331
+ const loadState = this.readyState
332
+ if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
333
+ script.onload = script.onreadystatechange = null
334
+ resolve()
335
+ }
336
+
337
+ Object.keys(attr).forEach(key => {
338
+ script.setAttribute(key, attr[key])
339
+ })
340
+ document.head.appendChild(script)
341
+ })
342
+
281
343
  }