hexo-theme-solitude 1.2.4 → 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.
@@ -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
@@ -7,7 +7,7 @@ block content
7
7
  div.category-bar-items#category-bar-items
8
8
  include includes/widgets/home/categoryBar
9
9
  div.recent-posts#recent-posts
10
- each post in site.posts.find({ parent: { $exists: false } }).data
10
+ each post in page.posts.find({ parent: { $exists: false } }).data
11
11
  include includes/widgets/home/postList
12
12
  include includes/mixins/pagination
13
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
@@ -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)
package/layout/tag.pug CHANGED
@@ -10,7 +10,7 @@ block content
10
10
  | #{tag.name}
11
11
  span.tagsPageCount #{tag.length}
12
12
  div.recent-posts#recent-posts
13
- each post in site.posts.find({ parent: { $exists: false } }).data
13
+ each post in page.posts.find({ parent: { $exists: false } }).data
14
14
  include includes/widgets/home/postList
15
15
  include includes/mixins/pagination
16
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.4",
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
+ }
@@ -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
@@ -911,63 +911,64 @@ let sco = {
911
911
  */
912
912
  class hightlight {
913
913
  static createEle(langEl, item) {
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>';
917
-
918
- const hlTools = document.createElement('div');
919
- hlTools.className = 'highlight-tools';
920
- hlTools.innerHTML = `${highlightExpandEle}${langEl}${highlightCopyEle}`;
921
-
922
- const itemHeight = item.clientHeight;
923
- const $table = item.querySelector('table');
924
- const $expand = item.getElementsByClassName('code-expand-btn');
925
-
926
- let expand = true;
927
- hlTools.children[0].addEventListener('click', () => {
928
- expand = !expand;
929
- hlTools.children[0].classList.toggle('closed');
930
- $table.style.display = expand ? 'none' : 'block';
931
- if ($expand.length !== 0) {
932
- $expand[0].style.display = expand ? 'none' : 'block';
933
- }
934
- if (!expand) {
935
- $table.style.height = itemHeight < 200 ? 'auto' : '200px';
936
- if (itemHeight >= 200) {
937
- item.classList.remove("expand-done");
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>'
917
+
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")
938
940
  }
939
941
  }
940
- });
941
-
942
- hlTools.children[2].addEventListener('click', () => {
943
- utils.copy($table.querySelector('.code').innerText);
944
- });
945
-
946
- fragment.appendChild(hlTools);
947
-
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')
948
951
  if (GLOBAL_CONFIG.hightlight.limit && itemHeight > GLOBAL_CONFIG.hightlight.limit + 30) {
949
- $table.style.height = `${GLOBAL_CONFIG.hightlight.limit}px`;
950
- const ele = document.createElement('div');
951
- ele.className = 'code-expand-btn';
952
- 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>'
953
955
  ele.addEventListener('click', (e) => {
954
- $table.style.height = `${itemHeight}px`;
955
- const target = e.target.className !== 'code-expand-btn' ? e.target.parentNode : e.target;
956
- target.classList.add('expand-done');
957
- });
958
- 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)
959
960
  }
960
- item.insertBefore(fragment, item.firstChild);
961
+ item.insertBefore(fragment, item.firstChild)
961
962
  }
962
963
 
963
964
  static init() {
964
- const $figureHighlight = document.querySelectorAll('figure.highlight');
965
- $figureHighlight.forEach(item => {
966
- let langName = item.classList[1] || 'Code';
967
- if (langName === 'plaintext') langName = 'Code';
968
- const highlightLangEle = `<div class="code-lang">${langName.toUpperCase()}</div>`;
969
- this.createEle(highlightLangEle, item);
970
- });
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
+ })
971
972
  }
972
973
  }
973
974
 
@@ -1043,9 +1044,9 @@ window.refreshFn = () => {
1043
1044
  sco.initConsoleState()
1044
1045
  if (document.getElementById('history-baidu')) sco.card_history() // 那年今日
1045
1046
  if (document.getElementById('welcome-info')) sco.card_welcome() // 个性定位
1047
+ GLOBAL_CONFIG.comment.enable && newestCommentInit() // 最新评论
1046
1048
  if (GLOBAL_CONFIG.comment.type === "twikoo" && PAGE_CONFIG.comment) {
1047
1049
  initializeCommentBarrage() // 热评
1048
- GLOBAL_CONFIG.comment.enable && newestCommentInit()
1049
1050
  }
1050
1051
  }
1051
1052