hexo-theme-fluid 1.8.13 → 1.9.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 (155) hide show
  1. package/LICENSE +674 -21
  2. package/README.md +17 -21
  3. package/_config.yml +164 -79
  4. package/languages/de.yml +58 -33
  5. package/languages/en.yml +58 -33
  6. package/languages/eo.yml +58 -33
  7. package/languages/es.yml +69 -0
  8. package/languages/ja.yml +58 -33
  9. package/languages/zh-CN.yml +58 -33
  10. package/languages/zh-HK.yml +69 -0
  11. package/languages/zh-TW.yml +58 -33
  12. package/layout/.DS_Store +0 -0
  13. package/layout/404.ejs +3 -1
  14. package/layout/{_partial → _partials}/archive-list.ejs +4 -4
  15. package/layout/_partials/category-chains.ejs +19 -0
  16. package/layout/_partials/category-list.ejs +62 -0
  17. package/layout/{_partial → _partials}/comments/changyan.ejs +0 -0
  18. package/layout/{_partial → _partials}/comments/cusdis.ejs +0 -0
  19. package/layout/{_partial → _partials}/comments/disqus.ejs +0 -0
  20. package/layout/_partials/comments/giscus.ejs +36 -0
  21. package/layout/{_partial → _partials}/comments/gitalk.ejs +0 -0
  22. package/layout/{_partial → _partials}/comments/livere.ejs +0 -0
  23. package/layout/{_partial → _partials}/comments/remark42.ejs +0 -0
  24. package/layout/{_partial → _partials}/comments/twikoo.ejs +3 -1
  25. package/layout/{_partial → _partials}/comments/utterances.ejs +1 -1
  26. package/layout/{_partial → _partials}/comments/valine.ejs +3 -1
  27. package/layout/{_partial → _partials}/comments/waline.ejs +6 -3
  28. package/layout/_partials/comments.ejs +5 -0
  29. package/layout/_partials/css.ejs +26 -0
  30. package/layout/_partials/footer/beian.ejs +33 -0
  31. package/layout/_partials/footer/statistics.ejs +39 -0
  32. package/layout/_partials/footer.ejs +18 -0
  33. package/layout/{_partial → _partials}/head.ejs +7 -1
  34. package/layout/_partials/header/banner.ejs +33 -0
  35. package/layout/{_partial/nav.ejs → _partials/header/navigation.ejs} +3 -2
  36. package/layout/_partials/header.ejs +8 -0
  37. package/layout/{_partial → _partials}/paginator.ejs +0 -0
  38. package/layout/_partials/plugins/analytics.ejs +87 -0
  39. package/layout/_partials/plugins/anchorjs.ejs +24 -0
  40. package/layout/_partials/plugins/code-widget.ejs +71 -0
  41. package/layout/_partials/plugins/fancybox.ejs +11 -0
  42. package/layout/_partials/plugins/highlight.ejs +13 -0
  43. package/layout/_partials/plugins/math.ejs +46 -0
  44. package/layout/_partials/plugins/mermaid.ejs +5 -0
  45. package/layout/{_partial → _partials}/plugins/nprogress.ejs +0 -0
  46. package/layout/_partials/plugins/typed.ejs +48 -0
  47. package/layout/_partials/post/category-bar.ejs +18 -0
  48. package/layout/_partials/post/copyright.ejs +56 -0
  49. package/layout/_partials/post/meta-bottom.ejs +16 -0
  50. package/layout/_partials/post/meta-top.ejs +63 -0
  51. package/layout/_partials/post/sidebar-left.ejs +10 -0
  52. package/layout/_partials/post/sidebar-right.ejs +10 -0
  53. package/layout/_partials/post/toc.ejs +34 -0
  54. package/layout/_partials/scripts.ejs +32 -0
  55. package/layout/{_partial → _partials}/search.ejs +2 -3
  56. package/layout/about.ejs +5 -3
  57. package/layout/archive.ejs +1 -1
  58. package/layout/categories.ejs +10 -59
  59. package/layout/category.ejs +1 -1
  60. package/layout/index.ejs +13 -15
  61. package/layout/layout.ejs +19 -39
  62. package/layout/links.ejs +2 -8
  63. package/layout/page.ejs +28 -12
  64. package/layout/post.ejs +65 -59
  65. package/layout/tag.ejs +1 -1
  66. package/package.json +11 -3
  67. package/scripts/.DS_Store +0 -0
  68. package/scripts/events/.DS_Store +0 -0
  69. package/scripts/events/index.js +1 -0
  70. package/scripts/events/lib/compatible-configs.js +7 -8
  71. package/scripts/events/lib/footnote.js +1 -1
  72. package/scripts/events/lib/hello.js +6 -2
  73. package/scripts/events/lib/highlight.js +93 -24
  74. package/scripts/events/lib/injects.js +118 -0
  75. package/scripts/events/lib/merge-configs.js +37 -7
  76. package/scripts/filters/default-injects.js +27 -0
  77. package/scripts/filters/post-filter.js +7 -0
  78. package/scripts/helpers/date.js +25 -0
  79. package/scripts/helpers/engine.js +9 -0
  80. package/scripts/helpers/export-config.js +8 -0
  81. package/scripts/helpers/import.js +24 -0
  82. package/scripts/helpers/injects.js +7 -0
  83. package/scripts/helpers/scope.js +44 -0
  84. package/scripts/helpers/utils.js +17 -2
  85. package/scripts/tags/checkbox.js +4 -2
  86. package/scripts/utils/.DS_Store +0 -0
  87. package/scripts/utils/object.js +5 -0
  88. package/scripts/utils/resolve.js +15 -0
  89. package/source/.DS_Store +0 -0
  90. package/source/css/_pages/_archive/archive.styl +28 -0
  91. package/source/css/_pages/_base/_widget/anchorjs.styl +8 -0
  92. package/source/css/_pages/_base/_widget/banner.styl +2 -11
  93. package/source/css/_pages/_base/_widget/board.styl +1 -4
  94. package/source/css/_pages/_base/_widget/code-widget.styl +36 -0
  95. package/source/css/_pages/_base/_widget/copyright.styl +90 -0
  96. package/source/css/_pages/_base/_widget/footer.styl +4 -1
  97. package/source/css/_pages/_base/_widget/header.styl +161 -2
  98. package/source/css/_pages/_base/_widget/modal.styl +100 -0
  99. package/source/css/_pages/_base/_widget/ngrogress.styl +12 -0
  100. package/source/css/_pages/_base/_widget/noscript.styl +12 -0
  101. package/source/css/_pages/_base/_widget/pagination.styl +23 -0
  102. package/source/css/_pages/_base/_widget/scroll-btn.styl +2 -15
  103. package/source/css/_pages/_base/_widget/toc.styl +75 -0
  104. package/source/css/_pages/_base/base.styl +23 -3
  105. package/source/css/_pages/_base/color-schema.styl +30 -58
  106. package/source/css/_pages/_base/inline.styl +2 -2
  107. package/source/css/_pages/_category/category-bar.styl +59 -0
  108. package/source/css/_pages/_category/category-chain.styl +6 -0
  109. package/source/css/_pages/_category/{categories.styl → category-list.styl} +17 -11
  110. package/source/css/_pages/_index/index.styl +7 -5
  111. package/source/css/_pages/_links/links.styl +2 -1
  112. package/source/css/_pages/_post/comment.styl +27 -0
  113. package/source/css/_pages/_post/highlight.styl +65 -0
  114. package/source/css/_pages/_post/markdown.styl +91 -0
  115. package/source/css/_pages/_post/{post.styl → post-page.styl} +44 -75
  116. package/source/css/_pages/_post/{tag_plugin.styl → post-tag.styl} +29 -27
  117. package/source/css/_variables/base.styl +30 -9
  118. package/source/css/highlight-dark.styl +6 -0
  119. package/source/css/highlight.styl +6 -0
  120. package/source/css/main.styl +7 -0
  121. package/source/img/.DS_Store +0 -0
  122. package/source/img/default.png +0 -0
  123. package/source/img/{favicon.png → fluid.png} +0 -0
  124. package/source/js/boot.js +1 -9
  125. package/source/js/color-schema.js +52 -7
  126. package/source/js/events.js +15 -15
  127. package/source/js/leancloud.js +9 -2
  128. package/source/js/local-search.js +2 -2
  129. package/source/js/plugins.js +26 -94
  130. package/source/js/utils.js +28 -12
  131. package/.editorconfig +0 -13
  132. package/.eslintrc +0 -224
  133. package/.gitattributes +0 -1
  134. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -28
  135. package/.github/ISSUE_TEMPLATE/bug_report_zh.md +0 -33
  136. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  137. package/.github/ISSUE_TEMPLATE/feature_request_zh.md +0 -20
  138. package/.github/ISSUE_TEMPLATE/question.md +0 -11
  139. package/.github/ISSUE_TEMPLATE/question_zh.md +0 -14
  140. package/.github/workflows/limit.yaml +0 -18
  141. package/README_en.md +0 -125
  142. package/layout/_partial/beian.ejs +0 -36
  143. package/layout/_partial/css.ejs +0 -47
  144. package/layout/_partial/footer.ejs +0 -11
  145. package/layout/_partial/plugins/analytics.ejs +0 -66
  146. package/layout/_partial/plugins/math.ejs +0 -69
  147. package/layout/_partial/plugins/mermaid.ejs +0 -24
  148. package/layout/_partial/plugins/typed.ejs +0 -41
  149. package/layout/_partial/post-meta.ejs +0 -51
  150. package/layout/_partial/scripts.ejs +0 -72
  151. package/layout/_partial/statistics.ejs +0 -43
  152. package/layout/_partial/toc.ejs +0 -4
  153. package/source/css/_pages/_base/_widget/copy-btn.styl +0 -42
  154. package/source/css/_pages/_base/rewrite.styl +0 -556
  155. package/source/css/_pages/_category/category.styl +0 -0
package/layout/links.ejs CHANGED
@@ -29,17 +29,11 @@ page.banner_mask_alpha = theme.links.banner_mask_alpha
29
29
  <% } %>
30
30
  </div>
31
31
 
32
- <% if(theme.links.custom.enable && theme.links.custom.content) { %>
32
+ <% if(theme.links.custom && theme.links.custom.enable && theme.links.custom.content) { %>
33
33
  <!-- Custom -->
34
34
  <div class="custom mx-auto">
35
35
  <%- theme.links.custom.content %>
36
36
  </div>
37
37
  <% } %>
38
38
 
39
- <% if(theme.links.comments.enable) { %>
40
- <!-- Comments -->
41
- <article class="comments" id="comments">
42
- <% var type = '_partial/comments/' + theme.links.comments.type %>
43
- <%- partial(type) %>
44
- </article>
45
- <% } %>
39
+ <%- inject_point('linksComments') %>
package/layout/page.ejs CHANGED
@@ -10,16 +10,32 @@ page.banner_mask_alpha = page.banner_mask_alpha || theme.page.banner_mask_alpha
10
10
  <article class="page-content">
11
11
  <%- page.content %>
12
12
 
13
- <% if(page.comments) { %>
14
- <!-- Comments -->
15
- <article class="comments" id="comments">
16
- <% var type %>
17
- <% if (typeof page.comment === 'string' && page.comment !== '') { %>
18
- <% type = '_partial/comments/' + page.comment %>
19
- <% } else { %>
20
- <% type = '_partial/comments/' + theme.post.comments.type %>
21
- <% } %>
22
- <%- partial(type) %>
23
- </article>
24
- <% } %>
13
+ <%- inject_point('pageComments') %>
25
14
  </article>
15
+
16
+ <% if (/<[^>]+? class="[^"]*?markdown-body[^"]*?"/gims.test(page.content)) { %>
17
+ <% import_css(theme.static_prefix.github_markdown, 'github-markdown.min.css') %>
18
+ <% import_css(theme.static_prefix.hint, 'hint.min.css') %>
19
+
20
+ <% if (theme.code.highlight.enable) { %>
21
+ <%- partial('_partials/plugins/highlight.ejs') %>
22
+ <% } %>
23
+ <% if ((theme.code.language.enable && theme.code.language.default) || theme.code.copy_btn) { %>
24
+ <%- partial('_partials/plugins/code-widget.ejs') %>
25
+ <% } %>
26
+ <% if (theme.fun_features.anchorjs.enable && page.anchorjs !== false) { %>
27
+ <%- partial('_partials/plugins/anchorjs.ejs') %>
28
+ <% } %>
29
+ <% if (theme.post.image_zoom.enable && page.image_zoom !== false) { %>
30
+ <%- partial('_partials/plugins/fancybox.ejs') %>
31
+ <% } %>
32
+ <% if (theme.post.image_caption.enable) { %>
33
+ <% import_script('<script>Fluid.plugins.imageCaption();</script>') %>
34
+ <% } %>
35
+ <% if (theme.post.math.enable && (!theme.post.math.specific || (theme.post.math.specific && page.math))) { %>
36
+ <%- partial('_partials/plugins/math.ejs') %>
37
+ <% } %>
38
+ <% if (theme.post.mermaid.enable && (!theme.post.mermaid.specific || (theme.post.mermaid.specific && page.mermaid))) { %>
39
+ <%- partial('_partials/plugins/mermaid.ejs') %>
40
+ <% } %>
41
+ <% } %>
package/layout/post.ejs CHANGED
@@ -6,72 +6,64 @@ page.banner_mask_alpha = page.banner_mask_alpha || theme.post.banner_mask_alpha
6
6
 
7
7
  <div class="container-fluid nopadding-x">
8
8
  <div class="row nomargin-x">
9
- <div class="d-none d-lg-block col-lg-2"></div>
9
+ <div class="side-col d-none d-lg-block col-lg-2">
10
+ <%- inject_point('postLeft') %>
11
+ </div>
12
+
10
13
  <div class="col-lg-8 nopadding-x-md">
11
14
  <div class="container nopadding-x-md" id="board-ctn">
12
- <div class="py-5" id="board">
15
+ <div id="board">
13
16
  <article class="post-content mx-auto">
14
17
  <!-- SEO header -->
15
18
  <h1 style="display: none"><%= page.subtitle || page.title %></h1>
16
- <% if(theme.post.updated && theme.post.updated.enable) { %>
17
- <p class="note note-info">
19
+ <% if (theme.post.updated.enable && theme.post.updated && compare_date(page.date, page.updated)) { %>
20
+ <p class="note note-<%= theme.post.updated.note_class || 'info' %>">
18
21
  <% if (theme.post.updated.relative) { %>
19
- <%- theme.post.updated.content %><%- relative_date(page.updated, theme.post.meta.date.format) %>
22
+ <% if (theme.post.updated.content) { %>
23
+ <!-- compatible with older versions-->
24
+ <%- theme.post.updated.content %><%- relative_date(page.updated, theme.post.updated.date_format) %>
25
+ <% } else { %>
26
+ <%- __('post.updated', relative_date(page.updated, theme.post.updated.date_format)) %>
27
+ <% } %>
20
28
  <% } else { %>
21
- <%- theme.post.updated.content %><%- date(page.updated, theme.post.meta.date.format) %>
29
+ <% if (theme.post.updated.content) { %>
30
+ <!-- compatible with older versions-->
31
+ <%- theme.post.updated.content %><%- date(page.updated, theme.post.updated.date_format) %>
32
+ <% } else { %>
33
+ <%- __('post.updated', date(page.updated, theme.post.updated.date_format)) %>
34
+ <% } %>
22
35
  <% } %>
23
36
  </p>
24
37
  <% } %>
25
38
  <div class="markdown-body">
39
+ <%- inject_point('postMarkdownBegin') %>
26
40
  <%- page.content %>
41
+ <%- inject_point('postMarkdownEnd') %>
27
42
  </div>
28
- <hr>
43
+ <hr/>
29
44
  <div>
30
- <div class="post-metas mb-3">
31
- <% if (page.categories && page.categories.length > 0) { %>
32
- <div class="post-meta mr-3">
33
- <i class="iconfont icon-category"></i>
34
- <% page.categories.each(function(cate) { %>
35
- <a class="hover-with-bg" href="<%= url_for(cate.path) %>"><%- cate.name %></a>
36
- <% }) %>
37
- </div>
38
- <% } %>
39
- <% if (page.tags && page.tags.length > 0 ) { %>
40
- <div class="post-meta">
41
- <i class="iconfont icon-tags"></i>
42
- <% page.tags.each(function(tag) { %>
43
- <a class="hover-with-bg" href="<%= url_for(tag.path) %>"><%- tag.name %></a>
44
- <% }) %>
45
- </div>
46
- <% } %>
47
- </div>
48
- <% if(theme.post.copyright.enable && theme.post.copyright.content && page.copyright !== false) { %>
49
- <p class="note note-warning">
50
- <% if (typeof page.copyright === 'string' && page.copyright !== '') { %>
51
- <%- page.copyright %>
52
- <% } else { %>
53
- <%- theme.post.copyright.content %>
54
- <% } %>
55
- </p>
56
- <% } %>
45
+ <%- inject_point('postMetaBottom') %>
46
+
47
+ <%- inject_point('postCopyright') %>
48
+
57
49
  <% if(theme.post.prev_next.enable && !page.hide) { %>
58
- <div class="post-prevnext">
50
+ <div class="post-prevnext my-3">
59
51
  <article class="post-prev col-6">
60
52
  <% const prev = prev_post(page) %>
61
53
  <% if (prev) { %>
62
- <a href="<%= url_for(prev.path) %>">
54
+ <a href="<%= url_for(prev.path) %>" title="<%= prev.title %>">
63
55
  <i class="iconfont icon-arrowleft"></i>
64
- <span class="hidden-mobile"><%- prev.title %></span>
65
- <span class="visible-mobile"><%= __('post.pre') %></span>
56
+ <span class="hidden-mobile"><%= prev.title %></span>
57
+ <span class="visible-mobile"><%- __('post.prev_post') %></span>
66
58
  </a>
67
59
  <% } %>
68
60
  </article>
69
61
  <article class="post-next col-6">
70
62
  <% const next = next_post(page) %>
71
63
  <% if (next) { %>
72
- <a href="<%= url_for(next.path) %>">
73
- <span class="hidden-mobile"><%- next.title %></span>
74
- <span class="visible-mobile"><%= __('post.next') %></span>
64
+ <a href="<%= url_for(next.path) %>" title="<%= next.title %>">
65
+ <span class="hidden-mobile"><%= next.title %></span>
66
+ <span class="visible-mobile"><%- __('post.next_post') %></span>
75
67
  <i class="iconfont icon-arrowright"></i>
76
68
  </a>
77
69
  <% } %>
@@ -80,31 +72,45 @@ page.banner_mask_alpha = page.banner_mask_alpha || theme.post.banner_mask_alpha
80
72
  <% } %>
81
73
  </div>
82
74
 
83
- <% if(page.comments && theme.post.comments.enable) { %>
84
- <!-- Comments -->
85
- <article class="comments" id="comments">
86
- <% if (typeof page.comment === 'string' && page.comment !== '') { %>
87
- <% type = '_partial/comments/' + page.comment %>
88
- <% } else { %>
89
- <% type = '_partial/comments/' + theme.post.comments.type %>
90
- <% } %>
91
- <%- partial(type) %>
92
- </article>
93
- <% } %>
75
+ <%- inject_point('postComments') %>
94
76
  </article>
95
77
  </div>
96
78
  </div>
97
79
  </div>
98
- <% if(theme.post.toc.enable && page.toc !== false){ %>
99
- <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
100
- <%- partial('_partial/toc') %>
101
- </div>
102
- <% } %>
80
+
81
+ <div class="side-col d-none d-lg-block col-lg-2">
82
+ <%- inject_point('postRight') %>
83
+ </div>
103
84
  </div>
104
85
  </div>
105
86
 
106
- <!-- Custom -->
107
- <% if(theme.post.custom.enable && theme.post.custom.content && page.custom !== false) { %>
87
+ <% import_css(theme.static_prefix.github_markdown, 'github-markdown.min.css') %>
88
+ <% import_css(theme.static_prefix.hint, 'hint.min.css') %>
89
+
90
+ <% if (theme.code.highlight.enable) { %>
91
+ <%- partial('_partials/plugins/highlight.ejs') %>
92
+ <% } %>
93
+ <% if ((theme.code.language.enable && theme.code.language.default) || theme.code.copy_btn) { %>
94
+ <%- partial('_partials/plugins/code-widget.ejs') %>
95
+ <% } %>
96
+ <% if (theme.fun_features.anchorjs.enable && page.anchorjs !== false) { %>
97
+ <%- partial('_partials/plugins/anchorjs.ejs') %>
98
+ <% } %>
99
+ <% if (theme.post.image_zoom.enable && page.image_zoom !== false) { %>
100
+ <%- partial('_partials/plugins/fancybox.ejs') %>
101
+ <% } %>
102
+ <% if (theme.post.image_caption.enable) { %>
103
+ <% import_script('<script>Fluid.plugins.imageCaption();</script>') %>
104
+ <% } %>
105
+ <% if (theme.post.math.enable && (!theme.post.math.specific || (theme.post.math.specific && page.math))) { %>
106
+ <%- partial('_partials/plugins/math.ejs') %>
107
+ <% } %>
108
+ <% if (theme.post.mermaid.enable && (!theme.post.mermaid.specific || (theme.post.mermaid.specific && page.mermaid))) { %>
109
+ <%- partial('_partials/plugins/mermaid.ejs') %>
110
+ <% } %>
111
+
112
+ <% if(theme.post.custom && theme.post.custom.enable && theme.post.custom.content && page.custom !== false) { %>
113
+ <!-- Custom -->
108
114
  <div class="col-lg-7 mx-auto nopadding-x-md">
109
115
  <div class="container custom post-custom mx-auto">
110
116
  <%- page.custom || theme.post.custom.content %>
package/layout/tag.ejs CHANGED
@@ -9,4 +9,4 @@ page.banner_mask_alpha = theme.tag.banner_mask_alpha
9
9
  var tag = site.tags.find({name: page.tag}).filter(tag => tag.length).data[0]
10
10
  %>
11
11
 
12
- <%- partial('_partial/archive-list.ejs', { params: { postTotal: tag ? tag.posts.length : 0 } }) %>
12
+ <%- partial('_partials/archive-list.ejs', { params: { key: page.layout, postTotal: tag ? tag.posts.length : 0 } }) %>
package/package.json CHANGED
@@ -1,7 +1,15 @@
1
1
  {
2
2
  "name": "hexo-theme-fluid",
3
- "version": "1.8.13",
3
+ "version": "1.9.1",
4
4
  "description": "An elegant Material-Design theme for Hexo.",
5
+ "main": "package.json",
6
+ "files": [
7
+ "languages",
8
+ "layout",
9
+ "scripts",
10
+ "source",
11
+ "_config.yml"
12
+ ],
5
13
  "repository": {
6
14
  "type": "git",
7
15
  "url": "git+https://github.com/fluid-dev/hexo-theme-fluid.git"
@@ -12,8 +20,8 @@
12
20
  "fluid",
13
21
  "material"
14
22
  ],
15
- "author": "fluid-dev (https://github.com/fluid-dev)",
16
- "license": "MIT",
23
+ "author": "Fluid-dev (https://github.com/fluid-dev)",
24
+ "license": "GPL-V3",
17
25
  "bugs": {
18
26
  "url": "https://github.com/fluid-dev/hexo-theme-fluid/issues"
19
27
  },
Binary file
Binary file
@@ -5,6 +5,7 @@
5
5
  hexo.on('generateBefore', () => {
6
6
  require('./lib/merge-configs')(hexo);
7
7
  require('./lib/compatible-configs')(hexo);
8
+ require('./lib/injects')(hexo);
8
9
  require('./lib/highlight')(hexo);
9
10
  require('./lib/lazyload')(hexo);
10
11
  require('./lib/footnote')(hexo);
@@ -16,8 +16,7 @@ module.exports = (hexo) => {
16
16
  enable : hexo.theme.config.highlight.enable,
17
17
  lib : 'highlightjs',
18
18
  highlightjs: {
19
- style : hexo.theme.config.highlight.style,
20
- bg_color: hexo.theme.config.highlight.bg_color
19
+ style: hexo.theme.config.highlight.style
21
20
  },
22
21
  prismjs: {
23
22
  style : 'default',
@@ -28,14 +27,14 @@ module.exports = (hexo) => {
28
27
  }
29
28
 
30
29
  // Some configs that require hexo >= 5.0
31
- if (hexo.version[0] < '5') {
30
+ if (parseInt(hexo.version[0], 10) < 5) {
31
+ if (isZh) {
32
+ hexo.log.warn('[Fluid] 检测到 Hexo 版本低于 5.0.0,部分功能可能会受影响');
33
+ } else {
34
+ hexo.log.warn('[Fluid] Hexo version < 5.0.0 detected, some features may not be available.');
35
+ }
32
36
  if (hexo.theme.config.code.highlight.lib === 'prismjs' && hexo.theme.config.code.highlight.prismjs.preprocess) {
33
37
  hexo.theme.config.code.highlight.prismjs.preprocess = false;
34
- if (isZh) {
35
- hexo.log.warn('[Fluid] 检测到 Hexo 版本低于 5.0.0,配置项 "prismjs:preprocess" 参数值被强制设置为 false');
36
- } else {
37
- hexo.log.warn('[Fluid] Hexo version < 5.0.0 detected, "prismjs:preprocess" in theme config is forced to false.');
38
- }
39
38
  }
40
39
  }
41
40
 
@@ -11,7 +11,7 @@ module.exports = (hexo) => {
11
11
  }
12
12
 
13
13
  /**
14
- * Modify by https://github.com/kchen0x/hexo-reference
14
+ * Modified from https://github.com/kchen0x/hexo-reference
15
15
  *
16
16
  * Render markdown footnotes
17
17
  * @param {String} text
@@ -1,8 +1,11 @@
1
1
  'use strict';
2
2
 
3
3
  module.exports = (hexo) => {
4
- const isZh = hexo.theme.i18n.languages[0].search(/zh-CN/i) !== -1;
5
- if (isZh) {
4
+ if (hexo.theme.has_hello) {
5
+ return;
6
+ }
7
+
8
+ if (hexo.theme.i18n.languages[0].search(/zh-CN/i) !== -1) {
6
9
  hexo.log.info(`
7
10
  ------------------------------------------------
8
11
  | |
@@ -36,4 +39,5 @@ module.exports = (hexo) => {
36
39
  `);
37
40
  }
38
41
 
42
+ hexo.theme.has_hello = true;
39
43
  };
@@ -1,8 +1,67 @@
1
1
  'use strict';
2
2
 
3
+ const fs = require('fs');
3
4
  const objUtil = require('../../utils/object');
5
+ const resolveModule = require('../../utils/resolve');
4
6
 
5
7
  module.exports = (hexo) => {
8
+
9
+ function parseStyleValue(line, attr) {
10
+ return line.split(attr)[1].replace(';', '').trim();
11
+ }
12
+
13
+ function resolveHighlight(name) {
14
+ if (!name) {
15
+ name = 'github-gist';
16
+ }
17
+ const cssName = name.toLowerCase().replace(/([^0-9])\s+?([^0-9])/g, '$1-$2').replace(/\s/g, '');
18
+ let file = resolveModule('highlight.js', `styles/${cssName}.css`);
19
+ if (cssName === 'github-gist' && !fs.existsSync(file)) {
20
+ file = resolveModule('highlight.js', 'styles/github.css');
21
+ }
22
+ let backgroundColor;
23
+ if (fs.existsSync(file)) {
24
+ const css = fs.readFileSync(file).toString();
25
+ let rule = '';
26
+ css.replace(/\.hljs(\s+|,[^{]+){(.*?)}/sg, (match, $1, content) => {
27
+ rule += content;
28
+ return match;
29
+ });
30
+ rule.split('\n').forEach(line => {
31
+ if (line.includes('background:')) {
32
+ backgroundColor = parseStyleValue(line, 'background:');
33
+ } else if (line.includes('background-color:')) {
34
+ backgroundColor = parseStyleValue(line, 'background-color:');
35
+ }
36
+ });
37
+ } else {
38
+ hexo.log.error(`[Fluid] highlightjs style '${name}' not found`);
39
+ return {};
40
+ }
41
+ return { file, backgroundColor };
42
+ }
43
+
44
+ function resolvePrism(name) {
45
+ if (!name) {
46
+ name = 'default';
47
+ }
48
+ let cssName = name.toLowerCase().replace(/[\s-]/g, '');
49
+ if (cssName === 'prism' || cssName === 'default') {
50
+ cssName = '';
51
+ } else if (cssName === 'tomorrownight') {
52
+ cssName = 'tomorrow';
53
+ }
54
+ let file = resolveModule('prismjs', `themes/${cssName ? 'prism-' + cssName : 'prism'}.css`);
55
+ if (!fs.existsSync(file)) {
56
+ file = resolveModule('prism-themes', `themes/${cssName}.css`);
57
+ }
58
+ if (!fs.existsSync(file)) {
59
+ hexo.log.error(`[Fluid] prismjs style '${name}' not found`);
60
+ return {};
61
+ }
62
+ return { file };
63
+ }
64
+
6
65
  const config = hexo.theme.config;
7
66
  if (!config.code || !config.code.highlight.enable) {
8
67
  return;
@@ -20,34 +79,33 @@ module.exports = (hexo) => {
20
79
  auto_detect: true,
21
80
  line_number: config.code.highlight.line_number || false
22
81
  });
82
+ hexo.theme.config.code.highlight.highlightjs = objUtil.merge({}, hexo.theme.config.code.highlight.highlightjs, {
83
+ light: resolveHighlight(hexo.theme.config.code.highlight.highlightjs.style),
84
+ dark : hexo.theme.config.dark_mode.enable && resolveHighlight(hexo.theme.config.code.highlight.highlightjs.style_dark)
85
+ });
23
86
 
24
87
  hexo.extend.filter.register('after_post_render', (page) => {
25
- if (config.code.highlight.highlightjs.bg_color) {
26
- page.content = page.content.replace(/(?<!<div class="hljs code-wrapper">)(<pre.+?<\/pre>)/gims, (str, p1) => {
88
+ if (hexo.config.highlight.line_number) {
89
+ page.content = page.content.replace(/<figure[^>]+?highlight.+?<td[^>]+?code[^>]+?>.*?(<pre.+?<\/pre>).+?<\/figure>/gims, (str, p1) => {
27
90
  if (/<code[^>]+?mermaid[^>]+?>/ims.test(p1)) {
28
- return str.replace(/(class=".*?)hljs(.*?")/gims, '$1$2');
91
+ return p1.replace(/(class="[^>]*?)hljs([^>]*?")/gims, '$1$2').replace(/<br>/gims, '\n');
29
92
  }
30
- return `<div class="hljs code-wrapper">${p1}</div>`;
93
+ return str;
31
94
  });
32
- page.content = page.content.replace(/<td class="gutter/gims, '<td class="gutter hljs');
33
- } else if (!hexo.config.highlight.line_number) {
34
- page.content = page.content.replace(/(?<!<div class="code-wrapper">)(<pre.+?<\/pre>)/gims, (str, p1) => {
35
- if (/<code[^>]+?mermaid[^>]+?>/ims.test(p1)) {
95
+ } else {
96
+ page.content = page.content.replace(/(?<!<div class="code-wrapper">)<pre.+?<\/pre>/gims, (str) => {
97
+ if (/<code[^>]+?mermaid[^>]+?>/ims.test(str)) {
36
98
  return str.replace(/(class=".*?)hljs(.*?")/gims, '$1$2');
37
99
  }
38
- return `<div class="code-wrapper">${p1}</div>`;
100
+ return `<div class="code-wrapper">${str}</div>`;
39
101
  });
40
102
  }
41
103
 
42
- if (hexo.config.highlight.line_number) {
43
- // Mermaid block adaptation
44
- page.content = page.content.replace(/<figure.+?<td class="code">.*?(<pre.+?<\/pre>).+?<\/figure>/gims, (str, p1) => {
45
- if (/<code[^>]+?mermaid[^>]+?>/ims.test(p1)) {
46
- return p1.replace(/(class=".*?)hljs(.*?")/gims, '$1$2').replace(/<br>/gims, '\n');
47
- }
48
- return str;
49
- });
50
- }
104
+ // 适配缩进型代码块
105
+ page.content = page.content.replace(/<pre><code>/gims, (str) => {
106
+ return '<pre><code class="hljs">';
107
+ });
108
+
51
109
  return page;
52
110
  });
53
111
  } else if (config.code.highlight.lib === 'prismjs') {
@@ -60,19 +118,30 @@ module.exports = (hexo) => {
60
118
  preprocess : config.code.highlight.prismjs.preprocess || false,
61
119
  line_number: config.code.highlight.line_number || false
62
120
  });
121
+ hexo.theme.config.code.highlight.prismjs = objUtil.merge({}, hexo.theme.config.code.highlight.prismjs, {
122
+ light: resolvePrism(hexo.theme.config.code.highlight.prismjs.style),
123
+ dark : hexo.theme.config.dark_mode.enable && resolvePrism(hexo.theme.config.code.highlight.prismjs.style_dark)
124
+ });
63
125
 
64
126
  hexo.extend.filter.register('after_post_render', (page) => {
65
- page.content = page.content.replace(/(?<!<div class="code-wrapper">)(<pre.+?<\/pre>)/gims, (str, p1) => {
66
- if (/<code[^>]+?mermaid[^>]+?>/ims.test(p1)) {
67
- str = str.replace(/<pre[^>]*?>/gims, '<pre>')
68
- .replace(/(class=".*?)language-mermaid(.*?")/gims, '$1mermaid$2');
127
+ page.content = page.content.replace(/(?<!<div class="code-wrapper">)<pre.+?<\/pre>/gims, (str) => {
128
+ if (/<code[^>]+?mermaid[^>]+?>/ims.test(str)) {
69
129
  if (hexo.config.highlight.line_number) {
70
- str = str.replace(/<span.+?line-numbers-rows.+?>.+?<\/span><\/code>/, '</code>');
130
+ str = str.replace(/<span[^>]+?line-numbers-rows[^>]+?>.+?<\/span><\/code>/, '</code>');
71
131
  }
132
+ str = str.replace(/<pre[^>]*?>/gims, '<pre>')
133
+ .replace(/(class=".*?)language-mermaid(.*?")/gims, '$1mermaid$2')
134
+ .replace(/<span[^>]+?>(.+?)<\/span>/gims, '$1');
72
135
  return str;
73
136
  }
74
- return `<div class="code-wrapper">${p1}</div>`;
137
+ return `<figure><div class="code-wrapper">${str}</div></figure>`;
75
138
  });
139
+
140
+ // 适配缩进型代码块
141
+ page.content = page.content.replace(/<pre><code>/gims, (str) => {
142
+ return '<pre class="language-none"><code class="language-none">';
143
+ });
144
+
76
145
  return page;
77
146
  });
78
147
  }
@@ -0,0 +1,118 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Modified from https://github.com/next-theme/hexo-theme-next/blob/master/scripts/events/lib/injects.js
5
+ */
6
+
7
+ const fs = require('fs');
8
+ const path = require('path');
9
+ const defaultExtname = '.ejs';
10
+
11
+ // Defining stylus types
12
+ class StylusInject {
13
+
14
+ constructor(base_dir) {
15
+ this.base_dir = base_dir;
16
+ this.files = [];
17
+ }
18
+
19
+ push(file) {
20
+ // Get absolute path base on hexo dir
21
+ this.files.push(path.resolve(this.base_dir, file));
22
+ }
23
+ }
24
+
25
+ // Defining view types
26
+ class ViewInject {
27
+
28
+ constructor(base_dir) {
29
+ this.base_dir = base_dir;
30
+ this.raws = [];
31
+ }
32
+
33
+ raw(name, raw, ...args) {
34
+ // Set default extname
35
+ if (path.extname(name) === '') {
36
+ name += defaultExtname;
37
+ }
38
+ this.raws.push({ name, raw, args });
39
+ }
40
+
41
+ file(name, file, ...args) {
42
+ // Set default extname from file's extname
43
+ if (path.extname(name) === '') {
44
+ name += path.extname(file);
45
+ }
46
+ // Get absolute path base on hexo dir
47
+ this.raw(name, fs.readFileSync(path.resolve(this.base_dir, file), 'utf8'), ...args);
48
+ }
49
+ }
50
+
51
+ const points = {
52
+ views: [
53
+ 'head',
54
+ 'header',
55
+ 'bodyBegin',
56
+ 'bodyEnd',
57
+ 'footer',
58
+ 'postMetaTop',
59
+ 'postMetaBottom',
60
+ 'postMarkdownBegin',
61
+ 'postMarkdownEnd',
62
+ 'postLeft',
63
+ 'postRight',
64
+ 'postCopyright',
65
+ 'postComments',
66
+ 'pageComments',
67
+ 'linksComments'
68
+ ],
69
+ styles: [
70
+ 'variable',
71
+ 'mixin',
72
+ 'style'
73
+ ]
74
+ };
75
+
76
+ // Init injects
77
+ function initInject(base_dir) {
78
+ const injects = {};
79
+ points.styles.forEach(item => {
80
+ injects[item] = new StylusInject(base_dir);
81
+ });
82
+ points.views.forEach(item => {
83
+ injects[item] = new ViewInject(base_dir);
84
+ });
85
+ return injects;
86
+ }
87
+
88
+ module.exports = (hexo) => {
89
+ // Exec theme_inject filter
90
+ const injects = initInject(hexo.base_dir);
91
+ hexo.execFilterSync('theme_inject', injects);
92
+ hexo.theme.config.injects = {};
93
+
94
+ // Inject stylus
95
+ points.styles.forEach(type => {
96
+ hexo.theme.config.injects[type] = injects[type].files;
97
+ });
98
+
99
+ // Inject views
100
+ points.views.forEach(type => {
101
+ const configs = Object.create(null);
102
+ hexo.theme.config.injects[type] = [];
103
+ // Add or override view.
104
+ injects[type].raws.forEach((injectObj, index) => {
105
+ const name = `inject/${type}/${injectObj.name}`;
106
+ hexo.theme.setView(name, injectObj.raw);
107
+ configs[name] = {
108
+ layout : name,
109
+ locals : injectObj.args[0],
110
+ options: injectObj.args[1],
111
+ order : injectObj.args[2] || index
112
+ };
113
+ });
114
+ // Views sort.
115
+ hexo.theme.config.injects[type] = Object.values(configs)
116
+ .sort((x, y) => x.order - y.order);
117
+ });
118
+ };