hexo-theme-solitude 2.1.6 → 2.1.8

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 (73) hide show
  1. package/CONTRIBUTING.md +1 -1
  2. package/LICENSE +1 -1
  3. package/README.md +1 -1
  4. package/README_en-US.md +1 -1
  5. package/README_zh-Hant.md +1 -1
  6. package/SECURITY.md +1 -1
  7. package/_config.yml +16 -20
  8. package/languages/default.yml +173 -173
  9. package/layout/archive.pug +3 -1
  10. package/layout/category.pug +3 -1
  11. package/layout/includes/inject/body.pug +1 -1
  12. package/layout/includes/page/default.pug +1 -1
  13. package/layout/includes/page/links.pug +1 -1
  14. package/layout/includes/page/tlink.pug +1 -1
  15. package/layout/includes/rightmenu.pug +6 -5
  16. package/layout/includes/widgets/page/about/hobbies.pug +18 -17
  17. package/layout/includes/widgets/page/about/tenyear.pug +24 -25
  18. package/layout/includes/widgets/page/links/linksCard.pug +5 -2
  19. package/layout/includes/widgets/page/message/content.pug +1 -1
  20. package/layout/includes/widgets/third-party/hot/artalk.pug +56 -0
  21. package/layout/includes/widgets/third-party/hot/twikoo.pug +57 -0
  22. package/layout/includes/widgets/third-party/pjax.pug +2 -1
  23. package/layout/index.pug +1 -1
  24. package/layout/post.pug +1 -1
  25. package/layout/tag.pug +2 -0
  26. package/package.json +1 -1
  27. package/plugins.yml +10 -10
  28. package/scripts/event/init.js +0 -1
  29. package/scripts/event/merge_config.js +14 -39
  30. package/scripts/event/welcome.js +11 -7
  31. package/scripts/filter/default.js +20 -21
  32. package/scripts/filter/lazyload.js +2 -4
  33. package/scripts/filter/randomPosts.js +14 -3
  34. package/scripts/helper/getArchiveLength.js +9 -11
  35. package/scripts/helper/related_post.js +56 -56
  36. package/scripts/tags/article.js +53 -15
  37. package/scripts/tags/tabs.js +37 -46
  38. package/source/css/_comments/comment.styl +4 -3
  39. package/source/css/_comments/twikoo.styl +6 -7
  40. package/source/css/_global/animation.styl +0 -15
  41. package/source/css/_global/index.styl +19 -19
  42. package/source/css/_highlight/highlight/diff.styl +13 -1
  43. package/source/css/_highlight/index.styl +2 -2
  44. package/source/css/_highlight/prismjs/diff.styl +13 -1
  45. package/source/css/_highlight/prismjs/index.styl +1 -1
  46. package/source/css/_highlight/prismjs/line-number.styl +1 -1
  47. package/source/css/_layout/article-container.styl +1 -1
  48. package/source/css/_layout/console.styl +1 -0
  49. package/source/css/_layout/recent-post.styl +2 -2
  50. package/source/css/_page/_about/about.styl +1 -1
  51. package/source/css/_page/_about/game.styl +2 -17
  52. package/source/css/_page/error.styl +2 -3
  53. package/source/css/_page/links.styl +2 -2
  54. package/source/css/_page/other.styl +1 -0
  55. package/source/css/_page/says.styl +4 -3
  56. package/source/css/_tags/gallery.styl +1 -1
  57. package/source/css/_tags/tabs.styl +2 -2
  58. package/source/img/error_load.avif +0 -0
  59. package/source/js/covercolor/api.js +29 -14
  60. package/source/js/covercolor/ave.js +38 -24
  61. package/source/js/covercolor/local.js +60 -52
  62. package/source/js/main.js +253 -248
  63. package/source/js/music.js +21 -39
  64. package/source/js/right_menu.js +64 -127
  65. package/source/js/third_party/barrage.min.js +93 -1
  66. package/source/js/third_party/envelope.min.js +1 -1
  67. package/source/js/third_party/post_ai.min.js +184 -1
  68. package/source/js/tw_cn.js +17 -16
  69. package/source/js/utils.js +50 -57
  70. package/layout/includes/widgets/home/hot/artalk.pug +0 -45
  71. package/layout/includes/widgets/home/hot/twikoo.pug +0 -46
  72. package/source/img/loading.avif +0 -0
  73. /package/layout/includes/widgets/{home → third-party}/hot/index.pug +0 -0
@@ -1,24 +1,25 @@
1
- - var game1 = site.data.about.game1
2
- - var game2 = site.data.about.game2
1
+ - var games = site.data.about.game
3
2
 
4
- if game1 || game2
3
+ if games
5
4
  .author-content
6
- if game1
7
- .author-content-item.game-apex(style=`background: url(${game1.img}) no-repeat top; background-size: cover;`)
5
+ each game, index in games
6
+ style.
7
+ .game-#{index}::after {
8
+ box-shadow: #{game.box_shadow} !important;
9
+ }
10
+ .author-content-item.game(class=`game-${index}`, style=`background: url(${game.img}) no-repeat top; background-size: cover;`)
8
11
  .card-content
9
- .author-content-item-tips= game1.title
10
- span.author-content-item-title= game1.subtitle
12
+ .author-content-item-tips= game.title
13
+ span.author-content-item-title= game.subtitle
11
14
  .content-bottom
12
- .tips= game1.tips_left
13
- .tips= game1.tips_right
14
- if game2
15
- .author-content-item.game-jl(style=`background: url(${game2.img}) no-repeat top; background-size: cover;`)
16
- .card-content
17
- .author-content-item-tips= game2.title
18
- span.author-content-item-title= game2.subtitle
19
- .content-bottom
20
- .tips= game2.tips_left
21
- .tips= game2.tips_right
15
+ if game.icon_group
16
+ .icon-group
17
+ each icon in game.icon_group
18
+ i(style=`background-image: url(${icon})`)
19
+ else if game.tips_left
20
+ .tips= game.tips_left
21
+ if game.tips_right
22
+ .tips= game.tips_right
22
23
 
23
24
  if site.data.about.likes
24
25
  - const likes = site.data.about.likes
@@ -2,47 +2,46 @@
2
2
  if tenyear
3
3
  .author-content#tenyear
4
4
  .create-site-post.author-content-item.single
5
- .author-content-item-tips=tenyear.tips
6
- .author-content-item-title=tenyear.title
7
- p=tenyear.text
5
+ .author-content-item-tips= tenyear.tips
6
+ .author-content-item-title= tenyear.title
7
+ p= tenyear.text
8
8
  .tenyear-timeline
9
9
  .progress
10
10
  .past-time
11
11
  .percentage-label
12
12
  .time-labels
13
- .start-time#tenyear-start-time= tenyear.start
14
- .end-time#tenyear-end-time= tenyear.end
13
+ .start-time#tenyear-start-time= new Date(tenyear.start).toLocaleDateString()
14
+ .end-time#tenyear-end-time= new Date(tenyear.end).toLocaleDateString()
15
15
 
16
16
  script.
17
- function parseDateString(e) {
18
- return e.replace(/年|月/g, '-').replace(/日/g, '');
19
- }
17
+ const tenYear = () => {
18
+ const progressElement = document.querySelector(".progress");
19
+ const pastTimeElement = document.querySelector(".past-time");
20
+ const percentageLabelElement = document.querySelector(".percentage-label");
21
+ const startTimeElement = document.getElementById("tenyear-start-time");
22
+ const endTimeElement = document.getElementById("tenyear-end-time");
20
23
 
21
- function tenYear() {
22
- let progressElement = document.querySelector(".progress");
23
- let pastTimeElement = document.querySelector(".past-time");
24
- let percentageLabelElement = document.querySelector(".percentage-label");
25
- let startTimeElement = document.getElementById("tenyear-start-time");
26
- let endTimeElement = document.getElementById("tenyear-end-time");
24
+ const startTime = new Date(startTimeElement.textContent).getTime();
25
+ const endTime = new Date(endTimeElement.textContent).getTime();
27
26
 
28
- let startTime = new Date(parseDateString(startTimeElement.textContent)).getTime();
29
- let endTime = new Date(parseDateString(endTimeElement.textContent)).getTime();
30
-
31
- function updateProgress() {
32
- let currentTime = new Date().getTime();
33
- let progress = ((currentTime - startTime) / (endTime - startTime) * 100);
34
- let progressPercentage = progress <= 100 ? progress + "%" : "100%";
27
+ const updateProgress = () => {
28
+ const currentTime = new Date().getTime();
29
+ const progress = ((currentTime - startTime) / (endTime - startTime) * 100);
30
+ const progressPercentage = Math.min(progress, 100) + "%";
35
31
 
36
32
  pastTimeElement.style.setProperty("--past-time-percentage", progress + "%");
37
33
  progressElement.style.setProperty("--progress-percentage", progressPercentage);
38
- if(progress > 5){
34
+ if (progress > 5) {
39
35
  percentageLabelElement.textContent = `${progress.toFixed(0)}%`;
40
36
  percentageLabelElement.style.left = `calc(${progress}% - 35px)`;
41
37
  }
42
- }
38
+ };
43
39
 
44
40
  percentageLabelElement.style.visibility = "visible";
45
41
  updateProgress();
46
- }
42
+ };
47
43
 
48
- document.getElementById("tenyear") && tenYear() && window.Pjax.on('complete', tenYear)
44
+ if (document.getElementById("tenyear")) {
45
+ tenYear();
46
+ window.Pjax.on('complete', tenYear);
47
+ }
@@ -2,8 +2,11 @@
2
2
  each item in data.link_list
3
3
  .site-card
4
4
  if item.tag
5
- span.site-card-tag(class=item.color)= item.tag
6
- i.light
5
+ if item.color == 'vip' || item.color == 'speed'
6
+ span.site-card-tag(class=item.color)= item.tag
7
+ i.light
8
+ else
9
+ span.site-card-tag(style=`background-color: ${item.color};`)= item.tag
7
10
  a.img(title=item.name, href=url_for(item.link))
8
11
  img.flink-avatar(src=item.topimg + (data.topimg_suffix || ''), alt=item.name)
9
12
  a.info.cf-friends-link(title=item.name, href=url_for(item.link))
@@ -1,4 +1,4 @@
1
- #article-container
1
+ .article-container
2
2
  != page.content
3
3
  if theme.envelope.enable
4
4
  .switch_message
@@ -0,0 +1,56 @@
1
+ - const { server, site } = theme.artalk
2
+
3
+ script.
4
+ function updatePostsBasedOnComments() {
5
+ const location = window.location;
6
+ const posts = Array.from(document.querySelectorAll('.recent-post-item[onclick] .post_cover a'))
7
+ .map(item => item.href.replace(location, ''));
8
+
9
+ fetchCommentsData(posts)
10
+ .then(data => updatePostElements(posts, data))
11
+ .catch(error => console.error("Error fetching comments:", error));
12
+ }
13
+
14
+ function fetchCommentsData(posts) {
15
+ const url = `!{server}/api/v2/stats/page_comment?page_keys=${posts.join(',')}&site_name=!{site}`;
16
+ return fetch(url)
17
+ .then(res => res.json())
18
+ .then(data => data.data);
19
+ }
20
+
21
+ function updatePostElements(posts, data) {
22
+ posts.forEach(post => {
23
+ const commentCount = data[post];
24
+ if (commentCount > !{count}) {
25
+ const postElement = document.querySelector(`.recent-post-item[onclick*="${post}"]`);
26
+ if (postElement) {
27
+ addHotTipIfNeeded(postElement);
28
+ }
29
+ }
30
+ });
31
+ }
32
+
33
+ function addHotTipIfNeeded(postElement) {
34
+ const infoTopTips = postElement.querySelector(".recent-post-info-top-tips");
35
+ const originalSpan = infoTopTips?.querySelector(".original");
36
+ const existingHotTip = infoTopTips?.querySelector(".hot-tip");
37
+
38
+ if (!existingHotTip && originalSpan) {
39
+ const hotTip = createHotTipElement();
40
+ infoTopTips.insertBefore(hotTip, originalSpan);
41
+ }
42
+ }
43
+
44
+ function createHotTipElement() {
45
+ const hotTip = document.createElement("span");
46
+ hotTip.classList.add("hot-tip");
47
+
48
+ const icon = document.createElement("i");
49
+ icon.classList.add("solitude", "fas", "fa-fire-flame-curved");
50
+ hotTip.appendChild(icon);
51
+
52
+ const commentCount = document.createTextNode("!{_p('hot-tip')}");
53
+ hotTip.appendChild(commentCount);
54
+
55
+ return hotTip;
56
+ }
@@ -0,0 +1,57 @@
1
+ script.
2
+ function updatePostsBasedOnComments() {
3
+ const location = window.location.origin;
4
+ const posts = Array.from(document.querySelectorAll('.recent-post-item[onclick] .post_cover a'))
5
+ .map(item => item.href.replace(location, ''));
6
+
7
+ const fetchCommentsCount = () => {
8
+ twikoo.getCommentsCount({
9
+ envId: "!{theme.twikoo.envId}",
10
+ urls: posts,
11
+ includeReply: true
12
+ }).then(handleCommentsResponse)
13
+ .catch(error => console.error("Error fetching comments:", error));
14
+ };
15
+
16
+ const handleCommentsResponse = (response) => {
17
+ response.forEach(comment => {
18
+ if (comment.count > !{count}) {
19
+ const postElement = document.querySelector(`.recent-post-item[onclick*="${comment.url}"]`);
20
+ if (postElement) {
21
+ updatePostElement(postElement);
22
+ }
23
+ }
24
+ });
25
+ };
26
+
27
+ const updatePostElement = (postElement) => {
28
+ const infoTopTips = postElement.querySelector(".recent-post-info-top-tips");
29
+ const originalSpan = infoTopTips?.querySelector(".original");
30
+ const existingHotTip = infoTopTips?.querySelector(".hot-tip");
31
+
32
+ if (!existingHotTip && originalSpan) {
33
+ const hotTip = createHotTipElement();
34
+ infoTopTips.insertBefore(hotTip, originalSpan);
35
+ }
36
+ };
37
+
38
+ const createHotTipElement = () => {
39
+ const hotTip = document.createElement("span");
40
+ hotTip.classList.add("hot-tip");
41
+
42
+ const icon = document.createElement("i");
43
+ icon.classList.add("solitude", "fas", "fa-fire-flame-curved");
44
+ hotTip.appendChild(icon);
45
+
46
+ const commentCount = document.createTextNode("!{_p('hot-tip')}");
47
+ hotTip.appendChild(commentCount);
48
+
49
+ return hotTip;
50
+ };
51
+
52
+ if (typeof twikoo === 'object') {
53
+ fetchCommentsCount();
54
+ } else {
55
+ utils.getScript('!{url_for(theme.cdn.twikoo)}').then(fetchCommentsCount);
56
+ }
57
+ }
@@ -1,9 +1,10 @@
1
1
  - const google_adsense = theme.google_adsense.enable
2
+ - const select = ['title','#body-wrap','#site-config','meta[name="description"]','.js-pjax','meta[property^="og:"]','#config-diff', '.rs_show', '.rs_hide']
2
3
 
3
4
  script.
4
5
  const pjax = new Pjax({
5
6
  elements: 'a:not([target="_blank"])',
6
- selectors: ['title','#body-wrap','#site-config','meta[name="description"]','.js-pjax','meta[property^="og:"]','#config-diff', '.rs_show', '.rs_hide'],
7
+ selectors: !{JSON.stringify(select)},
7
8
  cacheBust: false,
8
9
  analytics: !{google_adsense},
9
10
  scrollRestoration: false
package/layout/index.pug CHANGED
@@ -13,7 +13,7 @@ block content
13
13
  include ./includes/widgets/home/categoryBar
14
14
  .recent-posts#recent-posts
15
15
  if theme.comment.hot_tip.enable
16
- include ./includes/widgets/home/hot/index.pug
16
+ include ./includes/widgets/third-party/hot/index.pug
17
17
  if theme.carousel && is_home_first_page()
18
18
  include ./includes/widgets/home/carousel.pug
19
19
  for post, index in page.posts.sort("-sticky" || "-date").data
package/layout/post.pug CHANGED
@@ -5,7 +5,7 @@ block content
5
5
  #post
6
6
  if page.not_cover
7
7
  include includes/widgets/post/postInfo
8
- article.post-content#article-container
8
+ article.post-content.article-container
9
9
  if theme.post_ai.enable && page.ai
10
10
  include includes/widgets/post/post-ai
11
11
  != page.content
package/layout/tag.pug CHANGED
@@ -14,4 +14,6 @@ block content
14
14
  each post,index in page.posts.find({ parent: { $exists: false } }).data
15
15
  include includes/widgets/home/postList
16
16
  include includes/mixins/pagination
17
+ if theme.comment.hot_tip.enable
18
+ include ./includes/widgets/third-party/hot/index.pug
17
19
  include includes/widgets/aside/aside
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hexo-theme-solitude",
3
- "version": "2.1.6",
3
+ "version": "2.1.8",
4
4
  "description": "A beautiful, powerful, and efficient Hexo theme developed by everfu.",
5
5
  "main": "package.json",
6
6
  "scripts": {
package/plugins.yml CHANGED
@@ -1,11 +1,11 @@
1
1
  algolia_search:
2
2
  name: algoliasearch
3
3
  file: dist/algoliasearch.umd.js
4
- version: 5.9.1
4
+ version: 5.14.2
5
5
  instantsearch:
6
6
  name: instantsearch.js
7
7
  file: dist/instantsearch.production.min.js
8
- version: 4.74.1
8
+ version: 4.75.5
9
9
  pjax:
10
10
  name: pjax
11
11
  file: pjax.min.js
@@ -13,16 +13,16 @@ pjax:
13
13
  twikoo:
14
14
  name: twikoo
15
15
  file: dist/twikoo.all.min.js
16
- version: 1.6.39
16
+ version: 1.6.40
17
17
  waline_js:
18
18
  name: '@waline/client'
19
19
  file: dist/waline.js
20
20
  other_name: waline
21
- version: 3.3.1
21
+ version: 3.3.2
22
22
  waline_css:
23
23
  name: '@waline/client'
24
24
  file: dist/waline.css
25
- version: 3.3.1
25
+ version: 3.3.2
26
26
  other_name: waline
27
27
  valine:
28
28
  name: valine
@@ -31,11 +31,11 @@ valine:
31
31
  artalk_css:
32
32
  name: artalk
33
33
  file: dist/Artalk.css
34
- version: 2.9.0
34
+ version: 2.9.1
35
35
  artalk_js:
36
36
  name: artalk
37
37
  file: dist/Artalk.js
38
- version: 2.9.0
38
+ version: 2.9.1
39
39
  katex:
40
40
  name: katex
41
41
  file: dist/katex.min.css
@@ -106,7 +106,7 @@ fancyapps_css:
106
106
  mermaid_js:
107
107
  name: mermaid
108
108
  file: dist/mermaid.js
109
- version: 10.9.1
109
+ version: 11.4.0
110
110
  chart_js:
111
111
  name: chart.js
112
112
  file: dist/chart.umd.js
@@ -115,7 +115,7 @@ chart_js:
115
115
  typeit_js:
116
116
  name: typeit
117
117
  file: index.umd.min.js
118
- version: 8.8.4
118
+ version: 8.8.7
119
119
  other_name: typeit
120
120
  blueimp_md5:
121
121
  name: blueimp-md5
@@ -129,5 +129,5 @@ qrcode:
129
129
  color_thief:
130
130
  name: colorthief
131
131
  file: color-thief.min.js
132
- version: 2.4.0
132
+ version: 2.6.0
133
133
  other_name: color-thief
@@ -3,7 +3,6 @@ hexo.extend.filter.register('before_generate', () => {
3
3
  const nodeVer = process.version.replace(/^v/, '');
4
4
  const [majorVer] = nodeVer.split('.');
5
5
  const logger = hexo.log;
6
- const config = hexo.config;
7
6
 
8
7
  if (hexoVer < 7.0) {
9
8
  logger.error('请把 Hexo 升级到 V7.0.0 或更高的版本!');
@@ -33,18 +33,9 @@ hexo.extend.filter.register('before_generate', () => {
33
33
  }
34
34
  },
35
35
  aside: {
36
- home: {
37
- noSticky: 'about',
38
- Sticky: 'allInfo'
39
- },
40
- post: {
41
- noSticky: 'about',
42
- Sticky: 'allInfo'
43
- },
44
- page: {
45
- noSticky: 'about',
46
- Sticky: 'allInfo'
47
- },
36
+ home: { noSticky: 'about', Sticky: 'allInfo' },
37
+ post: { noSticky: 'about', Sticky: 'allInfo' },
38
+ page: { noSticky: 'about', Sticky: 'allInfo' },
48
39
  card: {
49
40
  style: 0,
50
41
  author: {
@@ -73,24 +64,12 @@ hexo.extend.filter.register('before_generate', () => {
73
64
  },
74
65
  newest_comment: {
75
66
  enable: false,
76
- storage: .5,
67
+ storage: 0.5,
77
68
  limit: 5
78
69
  },
79
- toc: {
80
- post: true,
81
- page: false,
82
- vague: true,
83
- },
84
- tags: {
85
- enable: true,
86
- limit: 20,
87
- highlight: false,
88
- list: [],
89
- },
90
- archive: {
91
- enable: true,
92
- type: 'month'
93
- },
70
+ toc: { post: true, page: false, vague: true },
71
+ tags: { enable: true, limit: 20, highlight: false, list: [] },
72
+ archive: { enable: true, type: 'month' },
94
73
  siteinfo: {
95
74
  postcount: true,
96
75
  wordcount: false,
@@ -111,9 +90,7 @@ hexo.extend.filter.register('before_generate', () => {
111
90
  tags: true,
112
91
  categories: true,
113
92
  archives: 0,
114
- default: {
115
- cover: ['/img/default.avif'],
116
- }
93
+ default: { cover: ['/img/default.avif'] },
117
94
  },
118
95
  post: {
119
96
  default: {
@@ -150,10 +127,7 @@ hexo.extend.filter.register('before_generate', () => {
150
127
  api: 'https://api.qjqq.cn/api/Imgcolor?img=',
151
128
  time: 43200000,
152
129
  },
153
- share: {
154
- enable: false,
155
- list: []
156
- },
130
+ share: { enable: false, list: [] },
157
131
  footer: {
158
132
  enable: true,
159
133
  desc: "The article from Solitude",
@@ -341,7 +315,7 @@ hexo.extend.filter.register('before_generate', () => {
341
315
  enable: false,
342
316
  recentComment: {
343
317
  enable: false,
344
- storage: .2,
318
+ storage: 0.2,
345
319
  },
346
320
  card: {
347
321
  tags: true,
@@ -404,7 +378,7 @@ hexo.extend.filter.register('before_generate', () => {
404
378
  enable: false,
405
379
  dark: 'https://bu.dusays.com/2023/09/29/651685ce667d1.jpg',
406
380
  light: 'https://bu.dusays.com/2023/09/29/651685cc18d39.jpg',
407
- opacity: .2,
381
+ opacity: 0.2,
408
382
  },
409
383
  translate: {
410
384
  enable: false,
@@ -427,6 +401,7 @@ hexo.extend.filter.register('before_generate', () => {
427
401
  custom_format: '//open.lightxi.com/cdnjs/ajax/libs/${cdnjs_name}/${version}/${min_cdnjs_file}',
428
402
  option: {}
429
403
  }
430
- }
431
- hexo.theme.config = Object.assign(defaultConfig, hexo.theme.config)
404
+ };
405
+
406
+ hexo.theme.config = { ...defaultConfig, ...hexo.theme.config };
432
407
  }, 1)
@@ -1,14 +1,18 @@
1
1
  hexo.on('ready', () => {
2
- const {version} = require('../../package.json')
3
- hexo.log.info(`
4
- =====================[ Hexo Theme - Solitude ]=====================
2
+ const { version } = require('../../package.json')
3
+ const logo = `
5
4
  ##### #### # ##### ###### # # ###### ######
6
5
  # # # # # # # # # # #
7
6
  ##### # # # # # # # # # ######
8
7
  # # # # # # # # # # #
9
8
  ###### #### ##### ##### # ### ###### ######
10
- ${version}
11
- ===================================================================
12
- GitHub: https://github.com/everfu/hexo-theme-solitude
13
- `)
9
+ `.replace(/#/g, '●')
10
+ const message = `
11
+ \x1b[38;5;45m=====================[ Hexo Theme - Solitude ]=====================\x1b[0m
12
+ \x1b[38;5;45m${logo}\x1b[0m
13
+ \x1b[38;5;45m version: ${version}\x1b[0m
14
+ \x1b[38;5;45m===================================================================\x1b[0m
15
+ \x1b[38;5;45mGitHub: https://github.com/everfu/hexo-theme-solitude\x1b[0m
16
+ `
17
+ hexo.log.info(message)
14
18
  })
@@ -2,32 +2,31 @@
2
2
 
3
3
  hexo.extend.filter.register('after_post_render', function (data) {
4
4
  data.title = data.title || 'Untitled';
5
- const {config} = hexo.theme;
6
- if (data.layout === 'post') {
7
- let {copyright, locate, cover} = hexo.theme.config.post.default
8
- cover = cover !== null ? cover : ['/img/default.avif']
9
- data.locate = data.locate || locate
10
- data.cc = data.cc || copyright
11
- data.cover = data.cover || cover[getRandomInt(0, cover?.length)]
12
- data.excerpt = data.description || data.excerpt
13
- data.toc = !!(config.aside.toc.post && data.toc !== false)
14
- data.ai = data.ai !== false;
15
- data.aside = data.aside || true;
5
+ const { config } = hexo.theme;
6
+ const defaultCover = ['/img/default.avif'];
7
+
8
+ const setCoverAndExcerpt = (layout) => {
9
+ const { copyright, locate, cover } = hexo.theme.config[layout].default;
10
+ data.locate = data.locate || locate;
11
+ data.cc = data.cc || copyright;
12
+ data.cover = data.cover || (cover?.length ? cover[getRandomInt(0, cover.length)] : defaultCover[0]);
13
+ data.excerpt = layout === 'post' ? data.description || data.excerpt : data.title;
14
+ data.toc = !!(config.aside.toc[layout] && data.toc !== false);
15
+ data.aside = layout === 'post' ? (data.aside || true) : (data.aside || false);
16
+ };
17
+
18
+ if (data.layout === 'post' || data.layout === 'page') {
19
+ setCoverAndExcerpt(data.layout);
16
20
  }
17
- if (data.layout === 'page') {
18
- let {cover} = hexo.theme.config.page.default
19
- cover = cover !== null ? cover : ['/img/default.avif']
20
- data.cover = data.cover || cover[getRandomInt(0, cover?.length)]
21
- data.excerpt = data.title
22
- data.toc = !!(config.aside.toc.page && data.toc !== false && data.aside);
23
- data.aside = data.aside || false;
21
+
22
+ if (data.layout === 'post') {
23
+ data.ai = data.ai || true;
24
24
  }
25
+
25
26
  data.comment = !!(config.comment.use && data.comment !== false);
26
27
  return data;
27
28
  });
28
29
 
29
30
  function getRandomInt(min, max) {
30
- min = Math.ceil(min);
31
- max = Math.floor(max);
32
- return Math.floor(Math.random() * (max - min)) + min;
31
+ return Math.floor(Math.random() * (max - min)) + Math.ceil(min);
33
32
  }
@@ -1,7 +1,5 @@
1
1
  'use strict'
2
2
 
3
- const urlFor = require('hexo-util').url_for.bind(hexo)
4
-
5
3
  const lazyload = (content, img) => {
6
4
  return content.replace(/(<img(?!.*?class[\t]*=[\t]*['"].*?nolazyload.*?['"]).*? src=)/gi, `$1 "${img}" data-lazy-src=`)
7
5
  }
@@ -9,12 +7,12 @@ const lazyload = (content, img) => {
9
7
  hexo.extend.filter.register('after_render:html', function (data) {
10
8
  const { enable, placeholder ,field } = hexo.theme.config.lazyload
11
9
  if (!enable || field !== 'site') return;
12
- return lazyload(data, urlFor(placeholder))
10
+ return lazyload(data, placeholder)
13
11
  })
14
12
 
15
13
  hexo.extend.filter.register('after_post_render', data => {
16
14
  const { enable, placeholder, field } = hexo.theme.config.lazyload
17
15
  if (!enable || field !== 'post') return
18
- data.content = lazyload(data.content, urlFor(placeholder))
16
+ data.content = lazyload(data.content, placeholder)
19
17
  return data
20
18
  })
@@ -1,5 +1,16 @@
1
1
  hexo.extend.filter.register('after_render:html', function (data) {
2
- const posts = hexo.locals.get('posts').filter(post => post.random !== false).map(post => post.path);
3
- data += `<script>const posts=${JSON.stringify(posts)};function toRandomPost(){ pjax.loadUrl(GLOBAL_CONFIG.root+posts[Math.floor(Math.random()*posts.length)]); }</script>`;
4
- return data;
2
+ const posts = hexo.locals.get('posts')
3
+ .filter(post => post.random !== false)
4
+ .map(post => post.path);
5
+
6
+ const scriptContent = `
7
+ <script>
8
+ const posts = ${JSON.stringify(posts)};
9
+ function toRandomPost() {
10
+ const randomPost = posts[Math.floor(Math.random() * posts.length)];
11
+ pjax.loadUrl(GLOBAL_CONFIG.root + randomPost);
12
+ }
13
+ </script>`;
14
+
15
+ return data + scriptContent;
5
16
  });
@@ -1,14 +1,12 @@
1
- const moment = require('moment')
1
+ const moment = require('moment');
2
2
 
3
- hexo.extend.helper.register('getArchiveLength', function (type) {
4
- if (type !== 'year' && type !== 'month') {
5
- type = 'year';
6
- }
7
- const posts = this.site.posts.sort('-date').data
8
- let archive = {}
9
- for (const post of posts) {
10
- const postdate = type === 'year' ? moment(post.date).format('YYYY') : moment(post.date).format('YYYY/MM');
3
+ hexo.extend.helper.register('getArchiveLength', function (type = 'year') {
4
+ const validTypes = ['year', 'month'];
5
+ type = validTypes.includes(type) ? type : 'year';
6
+
7
+ return this.site.posts.sort('-date').data.reduce((archive, post) => {
8
+ const postdate = moment(post.date).format(type === 'year' ? 'YYYY' : 'YYYY/MM');
11
9
  archive[postdate] = (archive[postdate] || 0) + 1;
12
- }
13
- return archive;
10
+ return archive;
11
+ }, {});
14
12
  });