hexo-theme-solitude 1.2.3 → 1.2.6

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.
package/_config.yml CHANGED
@@ -407,12 +407,18 @@ thirdparty:
407
407
  # 评论
408
408
  comment:
409
409
  enable: false # 是否开启评论
410
- type: 'twikoo' # valine, twikoo
410
+ type: # valine, twikoo
411
+ lazyload: false # 是否开启懒加载
412
+ count: false # 是否显示评论数
411
413
  # 评论系统
412
414
  twikoo:
413
415
  envId: # url: https://twikoo.sondy.top/
414
416
  lang: 'zh-CN' # 语言
415
417
  accessToken: # accessToken
418
+ waline:
419
+ envId: # url: https://waline.js.org/
420
+ pageview: false # 是否开启页面访问量统计
421
+ option: # waline配置项
416
422
 
417
423
  # 插入代码到头部 </head> 之前 和 底部 </body> 之前
418
424
  # 插入额外代码 如:统计,广告等
@@ -502,6 +508,8 @@ cdn:
502
508
  pacejs: https://cdn.bootcdn.net/ajax/libs/pace/1.2.4/pace.min.js
503
509
  echartsjs: https://cdn.bootcdn.net/ajax/libs/echarts/5.4.2/echarts.min.js
504
510
  lunrjs: https://cdn.bootcdn.net/ajax/libs/lunr.js/2.3.9/lunr.min.js
511
+ walinecss: https://cdn.bootcdn.net/ajax/libs/waline/2.15.7/waline.min.css
512
+ walinejs: https://cdn.bootcdn.net/ajax/libs/waline/2.15.7/waline.min.js
505
513
  body:
506
514
  viewimagejs: /lib/view-image.min.js
507
515
  waterfalljs: /lib/waterfall.min.js
@@ -3,7 +3,7 @@ extends includes/layout.pug
3
3
  block content
4
4
  main.layout#content-inner
5
5
  div#archive
6
- div.article-sort-title #{__('page.archives')}<sup>#{page.posts.length}</sup>
6
+ div.article-sort-title #{__('page.archives')}<sup>#{page.posts.find({ parent: { $exists: false } }).length}</sup>
7
7
  div.article-sort
8
8
  include includes/mixins/articleSort
9
9
  include includes/mixins/pagination
@@ -1,16 +1,13 @@
1
1
  extends includes/layout.pug
2
2
 
3
3
  block content
4
- main.layout#content-inner
5
- div#category
6
- div#category-bar
7
- div.category-bar-items#category-bar-items
8
- include includes/widgets/home/categoryBar
9
- div.recent-posts#recent-posts
10
- - const currentCategory = page.category
11
- each post in site.posts.data
12
- each category in post.categories.data
13
- if category.name === currentCategory
14
- include includes/widgets/home/postList
15
- include includes/mixins/pagination
16
- include includes/widgets/aside/aside
4
+ main.layout#content-inner
5
+ div#category
6
+ div#category-bar
7
+ div.category-bar-items#category-bar-items
8
+ include includes/widgets/home/categoryBar
9
+ div.recent-posts#recent-posts
10
+ each post in page.posts.find({ parent: { $exists: false } }).data
11
+ include includes/widgets/home/postList
12
+ include includes/mixins/pagination
13
+ include includes/widgets/aside/aside
@@ -16,7 +16,7 @@ div#console(style="zoom: 1")
16
16
  div.author-content-item-tips= "标签"
17
17
  div.author-content-item-title= "寻找感兴趣的领域"
18
18
  div.card-tag-cloud
19
- each tag in site.tags.data
19
+ each tag in site.tags.find({ parent: { $exists: false } }).data
20
20
  a(href=url_for(tag.path), style="font-size: 0.8rem; color: #d3d3d3")= tag.name
21
21
  sup= tag.length
22
22
 
@@ -72,6 +72,9 @@ script.
72
72
  url: '!{theme.comment.twikoo.envId}',
73
73
  accessToken: '!{theme.comment.twikoo.accessToken}'
74
74
  },
75
+ waline: {
76
+ url: '!{theme.comment.waline.envId}',
77
+ }
75
78
  },
76
79
  rightside: {
77
80
  enable: !{theme.rightside.enable}
@@ -54,9 +54,13 @@ if theme.aside.welcome.enable
54
54
  script(src='/js/txmap.js')
55
55
 
56
56
  if theme.comment.enable
57
- if theme.comment.type === 'twikoo'
58
- script(src='/js/extend/comment/twikoo.js')
59
- script(src='/js/commentBarrage.js')
57
+ case theme.comment.type
58
+ when 'twikoo'
59
+ script(src='/js/extend/comment/twikoo.js')
60
+ script(src='/js/commentBarrage.js')
61
+ when 'waline'
62
+ script(src='/js/extend/comment/waline.js')
63
+
60
64
 
61
65
  // pjax
62
66
  include ../widgets/third-party/pjax.pug
@@ -64,4 +68,4 @@ include ../widgets/third-party/pjax.pug
64
68
  // inject custom body
65
69
  if theme.extends.body
66
70
  each item in theme.extends.body
67
- != item
71
+ != item
@@ -18,8 +18,12 @@ link(rel="stylesheet", href=cdn.snackbarcss)
18
18
 
19
19
  // comment
20
20
  if theme.comment.enable
21
- if theme.comment.type === 'twikoo'
22
- script(src=cdn.twikoojs)
21
+ case theme.comment.type
22
+ when 'twikoo'
23
+ script(src=cdn.twikoojs)
24
+ when 'waline'
25
+ script(src=cdn.walinejs)
26
+ link(rel="stylesheet", href=cdn.walinecss)
23
27
 
24
28
  // search
25
29
  if theme.thirdparty.search.enable
@@ -1,8 +1,8 @@
1
1
  - let year
2
- each post in page.posts.data
3
- - if(year !== moment(post.date).year())
4
- - year = moment(post.date).year()
5
- div.article-sort-item.year #{year}
2
+ each post in page.posts.find({ parent: { $exists: false } }).data
3
+ if(year !== post.date.year())
4
+ - year = post.date.year()
5
+ div.article-sort-item.year #{year}
6
6
  div.article-sort-item
7
7
  a.article-sort-item-img(href=url_for(post.path) title=post.title)
8
8
  img(src=post.cover alt=post.title)
@@ -11,4 +11,6 @@ div#post-comment(view-image)
11
11
  when 'gitalk'
12
12
  include ./gitalk.pug
13
13
  when 'valine'
14
- include ./valine.pug
14
+ include ./valine.pug
15
+ when 'waline'
16
+ include ./waline.pug
@@ -0,0 +1,17 @@
1
+ - const { envId, option, pageview } = theme.comment.waline
2
+ - const { lazyload, count, type } = theme.comment
3
+
4
+ script.
5
+ async function initComment() {
6
+ (() => {
7
+ const waline = Waline.init(Object.assign({
8
+ el: '#comment',
9
+ serverURL: '!{envId}',
10
+ pageview: !{lazyload ? false : pageview},
11
+ dark: 'html[data-theme="dark"]',
12
+ path: window.location.pathname,
13
+ search: false,
14
+ comment: !{lazyload ? false : count},
15
+ }, !{JSON.stringify(option)}))
16
+ })()
17
+ }
package/layout/tag.pug CHANGED
@@ -1,19 +1,16 @@
1
1
  extends includes/layout.pug
2
2
 
3
3
  block content
4
- main.layout#content-inner
5
- div#tag
6
- div#tag-page-tags
7
- each tag in site.tags.find({ parent: { $exists: false } }).data
8
- a(id=tag.name class=(tag.name === page.tag ? 'select' : '') href=url_for(tag.path))
9
- span.tags-punctuation
10
- | #{tag.name}
11
- span.tagsPageCount #{tag.length}
12
- div.recent-posts#recent-posts
13
- - const currentTag = page.tag
14
- each post in site.posts.data
15
- each tag in post.tags.data
16
- if tag.name === currentTag
17
- include includes/widgets/home/postList
18
- include includes/mixins/pagination
19
- include includes/widgets/aside/aside
4
+ main.layout#content-inner
5
+ div#tag
6
+ div#tag-page-tags
7
+ each tag in site.tags.find({ parent: { $exists: false } }).data
8
+ a(id=tag.name class=(tag.name === page.tag ? 'select' : '') href=url_for(tag.path))
9
+ span.tags-punctuation
10
+ | #{tag.name}
11
+ span.tagsPageCount #{tag.length}
12
+ div.recent-posts#recent-posts
13
+ each post in page.posts.find({ parent: { $exists: false } }).data
14
+ include includes/widgets/home/postList
15
+ include includes/mixins/pagination
16
+ include includes/widgets/aside/aside
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hexo-theme-solitude",
3
- "version": "1.2.3",
3
+ "version": "1.2.6",
4
4
  "description": "A beautiful, powerful, and efficient Hexo theme developed by the DuoSco team",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -20,4 +20,4 @@
20
20
  "url": "https://github.com/DuoSco/Hexo-theme-solitude/issues"
21
21
  },
22
22
  "homepage": "https://github.com/DuoSco/hexo-theme-solitude#readme"
23
- }
23
+ }
@@ -16,6 +16,7 @@
16
16
  border-radius 12px
17
17
  cursor pointer
18
18
  border var(--style-border)
19
+ margin 1rem 0 1rem
19
20
 
20
21
  &:hover
21
22
  box-shadow var(--card-hover-box-shadow)
@@ -0,0 +1,75 @@
1
+ #comment
2
+ .wl-sort li
3
+ color var(--sco-gray)
4
+
5
+ &.active
6
+ color var(--sco-main) !important
7
+
8
+ .wl-comment
9
+ .wl-panel
10
+ margin 0 !important
11
+
12
+ .wl-footer
13
+ .wl-info
14
+ button
15
+ background-color var(--sco-card-bg)
16
+ border var(--style-border-always)
17
+ color var(--sco-fontcolor)
18
+
19
+ button:hover
20
+ background-color var(--sco-main)
21
+ border-color var(--sco-main)
22
+ color var(--sco-card-bg)
23
+
24
+ #wl-edit
25
+ font-size 13px
26
+ line-height 1.5
27
+ margin .75rem .25rem
28
+
29
+ .wl-action
30
+ transition .3s
31
+
32
+ &:hover
33
+ color var(--sco-main)
34
+
35
+ .wl-meta-head
36
+ .wl-count
37
+ color var(--sco-gray)
38
+ font-size 14px
39
+ font-weight normal
40
+
41
+ .wl-cards
42
+ font-size 16px!important
43
+ .wl-comment-actions
44
+ button
45
+ margin-right 15px
46
+ font-size 18px
47
+
48
+ &:hover
49
+ color var(--sco-main)
50
+ .wl-head .wl-nick
51
+ font-size 20px !important
52
+ color var(--sco-lighttext)
53
+ font-weight bolder
54
+
55
+ .wl-meta>span
56
+ background var(--sco-gray)
57
+ border-radius 5px
58
+ color var(--sco-card-bg)
59
+ margin-right 5px
60
+
61
+ .wl-user
62
+ img
63
+ flex-shrink 0
64
+ height 2.5rem
65
+ width 2.5rem
66
+ overflow hidden
67
+ text-align center
68
+ border-radius 2.5rem
69
+ border 2px solid var(--sco-white)
70
+
71
+ [data-waline] a
72
+ color var(--sco-main) !important
73
+
74
+ .wl-content pre, .wl-content pre[class*=language-]
75
+ padding .5rem!important
@@ -15,8 +15,9 @@ if hexo-config('css_prefix')
15
15
 
16
16
  // comment
17
17
  if hexo-config('comment.enable')
18
- @import '_comment/index.styl'
19
- @import '_comment/twikoo.styl' when hexo-config('comment.type') == 'twikoo'
18
+ @import '_widgets/comment/index.styl'
19
+ @import '_widgets/comment/twikoo.styl' when hexo-config('comment.type') == 'twikoo'
20
+ @import '_widgets/comment/waline.styl' when hexo-config('comment.type') == 'waline'
20
21
 
21
22
  // commentBarrage
22
23
  if hexo-config('thirdparty.comment.enable')
@@ -0,0 +1,61 @@
1
+ const changeContent = (content) => {
2
+ if (content === '') return content
3
+
4
+ content = content.replace(/<img.*?src="(.*?)"?[^\>]+>|<a[^>]+?href=["']?([^"']+)["']?[^>]*>([^<]+)<\/a>|<pre><code>.*?<\/pre>|<[^>]+>/g, (match, img, link, code) => {
5
+ if (img) return '[图片]';
6
+ if (link) return '[链接]';
7
+ if (code) return '[代码]';
8
+ return '';
9
+ })
10
+
11
+ if (content.length > 150) {
12
+ content = content.substring(0, 150) + '...'
13
+ }
14
+ return content
15
+ }
16
+
17
+ const $asideList = document.querySelector('#card-newest-comments .aside-list')
18
+ const newestCommentInit = () => {
19
+ if ($asideList) {
20
+ getComment()
21
+ }
22
+ }
23
+
24
+ const getComment = () => {
25
+ Waline.RecentComments(
26
+ options = {
27
+ serverURL: GLOBAL_CONFIG.comment.waline.url,
28
+ count: 6,
29
+ }
30
+ ).then(function (res) {
31
+ const walineArray = res.comments.map(item => ({
32
+ 'content': changeContent(item.comment),
33
+ 'avatar': item.avatar,
34
+ 'nick': item.nick,
35
+ 'url': `${item.url}#${item.objectId}`,
36
+ 'date': new Date(item.insertedAt).toISOString()
37
+ }))
38
+ generateHtml(walineArray)
39
+ }).catch(
40
+ $asideList.innerHTML = "无法获取评论,请确认相关配置是否正确"
41
+ )
42
+ }
43
+
44
+ const generateHtml = array => {
45
+ const $dom = document.querySelector('#card-newest-comments .aside-list')
46
+ $dom.innerHTML = array.length ? array.map(item => `
47
+ <div class='aside-list-item'>
48
+ <a href='${item.url}' class='thumbnail'>
49
+ <img src='${item.avatar}' alt='${item.nick}'>
50
+ <div class='name'><span>${item.nick}</span></div>
51
+ </a>
52
+ <div class='content'>
53
+ <a class='comment' href='${item.url}'>${item.content}</a>
54
+ <time class="datetime" datetime="${item.date}"></time>
55
+ </div>
56
+ </div>
57
+ `).join('') : '没有评论'
58
+ window.lazyLoadInstance && window.lazyLoadInstance.update()
59
+ window.pjax && window.pjax.refresh($dom)
60
+ changeTimeFormat()
61
+ }
package/source/js/main.js CHANGED
@@ -846,7 +846,7 @@ let sco = {
846
846
 
847
847
  pageText.addEventListener("keydown", (event) => {
848
848
  if (event.keyCode === 13) {
849
- heo.toPage();
849
+ sco.toPage();
850
850
  pjax.loadUrl(pageButton.href);
851
851
  }
852
852
  });
@@ -881,7 +881,29 @@ let sco = {
881
881
  cookiesWindow.style.display = 'none';
882
882
  }
883
883
  }
884
- }
884
+ },
885
+ /**
886
+ * 首页分页跳转
887
+ */
888
+ toPage: function () {
889
+ const pageNumbers = document.querySelectorAll(".page-number");
890
+ const maxPageNumber = parseInt(pageNumbers[pageNumbers.length - 1].innerHTML);
891
+ const inputElement = document.getElementById("toPageText");
892
+ const inputPageNumber = parseInt(inputElement.value);
893
+
894
+ if (!isNaN(inputPageNumber) && inputPageNumber > 0 && inputPageNumber <= maxPageNumber) {
895
+ const currentPageUrl = window.location.href.replace(/\/page\/\d+\/$/, "/");
896
+ let targetPageUrl;
897
+
898
+ if (inputPageNumber === 1) {
899
+ targetPageUrl = currentPageUrl;
900
+ } else {
901
+ targetPageUrl = currentPageUrl + (currentPageUrl.endsWith("/") ? "" : "/") + "page/" + inputPageNumber + "/";
902
+ }
903
+
904
+ document.getElementById("toPageButton").href = targetPageUrl;
905
+ }
906
+ },
885
907
  }
886
908
 
887
909
  /*
@@ -889,63 +911,64 @@ let sco = {
889
911
  */
890
912
  class hightlight {
891
913
  static createEle(langEl, item) {
892
- const fragment = document.createDocumentFragment();
893
- const highlightCopyEle = '<i class="scoicon sco-copy-fill"></i>';
894
- const highlightExpandEle = '<i class="scoicon sco-arrow-down expand" style="font-size: 16px"></i>';
914
+ const fragment = document.createDocumentFragment()
915
+ const highlightCopyEle = '<i class="scoicon sco-copy-fill"></i>'
916
+ const highlightExpandEle = '<i class="scoicon sco-arrow-down expand" style="font-size: 16px"></i>'
895
917
 
896
- const hlTools = document.createElement('div');
897
- hlTools.className = 'highlight-tools';
898
- hlTools.innerHTML = `${highlightExpandEle}${langEl}${highlightCopyEle}`;
899
-
900
- const itemHeight = item.clientHeight;
901
- const $table = item.querySelector('table');
902
- const $expand = item.getElementsByClassName('code-expand-btn');
903
-
904
- let expand = true;
905
- hlTools.children[0].addEventListener('click', () => {
906
- expand = !expand;
907
- hlTools.children[0].classList.toggle('closed');
908
- $table.style.display = expand ? 'none' : 'block';
909
- if ($expand.length !== 0) {
910
- $expand[0].style.display = expand ? 'none' : 'block';
911
- }
912
- if (!expand) {
913
- $table.style.height = itemHeight < 200 ? 'auto' : '200px';
914
- if (itemHeight >= 200) {
915
- item.classList.remove("expand-done");
918
+ const hlTools = document.createElement('div')
919
+ hlTools.className = `highlight-tools`
920
+ hlTools.innerHTML = highlightExpandEle + langEl + highlightCopyEle
921
+ let expand = true
922
+ hlTools.children[0].addEventListener('click', (e) => {
923
+ if (expand) {
924
+ hlTools.children[0].classList.add('closed')
925
+ $table.setAttribute('style', 'display:none')
926
+ if ($expand.length !== 0) {
927
+ $expand[0].setAttribute('style', 'display:none')
928
+ }
929
+ } else {
930
+ hlTools.children[0].classList.remove('closed')
931
+ $table.setAttribute('style', 'display:block')
932
+ if ($expand.length !== 0) {
933
+ $expand[0].setAttribute('style', 'display:block')
934
+ }
935
+ if (itemHeight < 200) {
936
+ $table.setAttribute('style', 'height: auto')
937
+ } else {
938
+ $table.setAttribute('style', 'height:200px')
939
+ ele.classList.remove("expand-done")
916
940
  }
917
941
  }
918
- });
919
-
920
- hlTools.children[2].addEventListener('click', () => {
921
- utils.copy($table.querySelector('.code').innerText);
922
- });
923
-
924
- fragment.appendChild(hlTools);
925
-
942
+ expand = !expand
943
+ })
944
+ hlTools.children[2].addEventListener('click', (e) => {
945
+ utils.copy($table.querySelector('.code').innerText)
946
+ })
947
+ const ele = document.createElement('div')
948
+ fragment.appendChild(hlTools)
949
+ const itemHeight = item.clientHeight, $table = item.querySelector('table'),
950
+ $expand = item.getElementsByClassName('code-expand-btn')
926
951
  if (GLOBAL_CONFIG.hightlight.limit && itemHeight > GLOBAL_CONFIG.hightlight.limit + 30) {
927
- $table.style.height = `${GLOBAL_CONFIG.hightlight.limit}px`;
928
- const ele = document.createElement('div');
929
- ele.className = 'code-expand-btn';
930
- ele.innerHTML = '<i class="scoicon sco-show-line" style="font-size: 1.2rem"></i>';
952
+ $table.setAttribute('style', `height: ${GLOBAL_CONFIG.hightlight.limit}px`)
953
+ ele.className = 'code-expand-btn'
954
+ ele.innerHTML = '<i class="scoicon sco-show-line" style="font-size: 1.2rem"></i>'
931
955
  ele.addEventListener('click', (e) => {
932
- $table.style.height = `${itemHeight}px`;
933
- const target = e.target.className !== 'code-expand-btn' ? e.target.parentNode : e.target;
934
- target.classList.add('expand-done');
935
- });
936
- fragment.appendChild(ele);
956
+ $table.setAttribute('style', `height: ${itemHeight}px`)
957
+ e.target.className !== 'code-expand-btn' ? e.target.parentNode.classList.add('expand-done') : e.target.classList.add('expand-done')
958
+ })
959
+ fragment.appendChild(ele)
937
960
  }
938
- item.insertBefore(fragment, item.firstChild);
961
+ item.insertBefore(fragment, item.firstChild)
939
962
  }
940
963
 
941
964
  static init() {
942
- const $figureHighlight = document.querySelectorAll('figure.highlight');
943
- $figureHighlight.forEach(item => {
944
- let langName = item.classList[1] || 'Code';
945
- if (langName === 'plaintext') langName = 'Code';
946
- const highlightLangEle = `<div class="code-lang">${langName.toUpperCase()}</div>`;
947
- this.createEle(highlightLangEle, item);
948
- });
965
+ const $figureHighlight = document.querySelectorAll('figure.highlight'), that = this
966
+ $figureHighlight.forEach(function (item) {
967
+ let langName = item.getAttribute('class').split(' ')[1]
968
+ if (langName === 'plaintext' || langName === undefined) langName = 'Code'
969
+ const highlightLangEle = `<div class="code-lang">${langName.toUpperCase()}</div>`
970
+ that.createEle(highlightLangEle, item)
971
+ })
949
972
  }
950
973
  }
951
974
 
@@ -1005,7 +1028,6 @@ window.refreshFn = () => {
1005
1028
  GLOBAL_CONFIG.lazyload.enable && sco.lazyloadImg()
1006
1029
  GLOBAL_CONFIG.lightbox && sco.lightbox('')
1007
1030
  GLOBAL_CONFIG.randomlinks && randomLinksList()
1008
- GLOBAL_CONFIG.comment.enable && newestCommentInit()
1009
1031
  if (PAGE_CONFIG.comment) {
1010
1032
  initComment()
1011
1033
  }
@@ -1022,7 +1044,10 @@ window.refreshFn = () => {
1022
1044
  sco.initConsoleState()
1023
1045
  if (document.getElementById('history-baidu')) sco.card_history() // 那年今日
1024
1046
  if (document.getElementById('welcome-info')) sco.card_welcome() // 个性定位
1025
- if (GLOBAL_CONFIG.comment.type === "twikoo" && PAGE_CONFIG.comment) initializeCommentBarrage() // 热评
1047
+ GLOBAL_CONFIG.comment.enable && newestCommentInit() // 最新评论
1048
+ if (GLOBAL_CONFIG.comment.type === "twikoo" && PAGE_CONFIG.comment) {
1049
+ initializeCommentBarrage() // 热评
1050
+ }
1026
1051
  }
1027
1052
 
1028
1053
  sco.initTheme()