hexo-theme-solitude 1.5.9 → 1.5.10

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 (33) hide show
  1. package/.github/workflows/issue_close_question.yml +25 -0
  2. package/.github/workflows/issue_invalid.yml +18 -0
  3. package/.github/workflows/issue_question.yml +30 -0
  4. package/.github/workflows/issue_wontfix.yml +29 -0
  5. package/_config.yml +4 -6
  6. package/layout/includes/head/config.pug +6 -5
  7. package/layout/includes/inject/head.pug +1 -1
  8. package/layout/includes/page/says.pug +2 -2
  9. package/package.json +1 -1
  10. package/plugins.yml +1 -1
  11. package/scripts/event/cdn.js +1 -2
  12. package/scripts/event/init.js +1 -6
  13. package/scripts/filter/default.js +11 -12
  14. package/scripts/filter/lazyload.js +0 -2
  15. package/scripts/filter/randomPosts.js +4 -7
  16. package/scripts/helper/stylus.js +16 -0
  17. package/scripts/tags/bvideo.js +2 -2
  18. package/source/css/_global/var.styl +4 -1
  19. package/source/css/_highlight/highlight/index.styl +45 -0
  20. package/source/css/{_widgets/_post/_highlight → _highlight}/index.styl +25 -52
  21. package/source/css/_highlight/prismjs/diff.styl +184 -0
  22. package/source/css/_highlight/prismjs/index.styl +13 -0
  23. package/source/css/_highlight/prismjs/line-number.styl +30 -0
  24. package/source/css/{_widgets/_post/_highlight → _highlight}/theme/default.styl +4 -2
  25. package/source/css/{_widgets/_post/_highlight → _highlight}/theme/mac.styl +2 -1
  26. package/source/css/_page/index.styl +4 -1
  27. package/source/css/_widgets/_post/content.styl +1 -1
  28. package/source/css/_widgets/_post/index.styl +0 -2
  29. package/source/css/index.styl +4 -1
  30. package/source/js/main.js +90 -59
  31. package/source/js/utils.js +5 -6
  32. /package/source/css/{_widgets/_post/_highlight/theme.styl → _highlight/color.styl} +0 -0
  33. /package/source/css/{_widgets/_post/_highlight → _highlight/highlight}/diff.styl +0 -0
@@ -0,0 +1,25 @@
1
+ name: Close need info
2
+
3
+ on:
4
+ schedule:
5
+ - cron: "0 0 */1 * *"
6
+ workflow_dispatch:
7
+
8
+ jobs:
9
+ close-need-info:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - name: close-issues
13
+ uses: actions-cool/issues-helper@v3
14
+ with:
15
+ actions: "close-issues"
16
+ token: ${{ secrets.GITHUB_TOKEN }}
17
+ labels: "question"
18
+ inactive-day: 60
19
+ close-reason: "not_planned"
20
+ body: |
21
+ Hi there! This issue has been automatically closed because it has not had any activity for 60 days. We label issues as "questions" in hopes of community or maintainer input, and it seems this issue has gone stale.
22
+
23
+ If you still need assistance or believe this closure is a mistake, please feel free to reopen the issue or create a new one with updated details. We're here to help!
24
+
25
+ Thank you for your contributions to our project!
@@ -0,0 +1,18 @@
1
+ name: Issue Invalid
2
+
3
+ on:
4
+ issues:
5
+ types: [labeled]
6
+
7
+ jobs:
8
+ lock-issue:
9
+ runs-on: ubuntu-latest
10
+ if: github.event.label.name == 'invalid'
11
+ steps:
12
+ - name: Lock issue
13
+ uses: actions-cool/issues-helper@v2
14
+ with:
15
+ actions: "lock-issue"
16
+ token: ${{ secrets.GITHUB_TOKEN }}
17
+ issue-number: ${{ github.event.issue.number }}
18
+ lock-reason: "off-topic"
@@ -0,0 +1,30 @@
1
+ name: Issue Question
2
+
3
+ on:
4
+ issues:
5
+ types: [labeled]
6
+
7
+ jobs:
8
+ create-comment:
9
+ runs-on: ubuntu-latest
10
+ if: github.event.label.name == 'question'
11
+ steps:
12
+ - name: Create comment
13
+ uses: actions-cool/issues-helper@v2.0.0
14
+ with:
15
+ actions: "create-comment"
16
+ token: ${{ secrets.ISSUSE_TOKEN }}
17
+ issue-number: ${{ github.event.issue.number }}
18
+ body: |
19
+ Hello! 👋
20
+
21
+ Thank you for submitting your question. To ensure we can provide the best answer possible, could you please confirm you've provided the following details:
22
+ - A clear and concise description of your question.
23
+ - Any relevant code snippets or links to your project.
24
+ - What you've tried so far in attempting to solve your issue.
25
+
26
+ In the meantime, you might find the answer to your question in our [FAQs](https://solitude-docs.efu.me/faq) or [documentation](https://solitude-docs.efu.me/).
27
+
28
+ We aim to respond to questions within 48 hours. If your question is urgent, please consider reaching out through our support channels.
29
+
30
+ Thanks again for reaching out, and we look forward to assisting you!
@@ -0,0 +1,29 @@
1
+ name: Issue Wontfix
2
+
3
+ on:
4
+ issues:
5
+ types: [labeled]
6
+
7
+ jobs:
8
+ handle-wontfix:
9
+ runs-on: ubuntu-latest
10
+ if: github.event.label.name == 'wontfix'
11
+ steps:
12
+ - name: Create comment for wontfix
13
+ uses: actions-cool/issues-helper@v3
14
+ with:
15
+ actions: "create-comment"
16
+ token: ${{ secrets.GITHUB_TOKEN }}
17
+ issue-number: ${{ github.event.issue.number }}
18
+ body: |
19
+ Hi there! This issue has been marked as 'wontfix'. It means we've reviewed the issue but have chosen not to pursue it for reasons that may vary (e.g., aligning with the project's current priorities, outside of project scope, etc.).
20
+
21
+ We understand this might not be the outcome you were hoping for. If you believe this decision should be reconsidered, please provide any additional context or reasoning that was not previously considered.
22
+
23
+ Thank you for your understanding and for contributing to the project. Your efforts are greatly appreciated!
24
+ - name: Close issue after wontfix
25
+ uses: actions-cool/issues-helper@v3
26
+ with:
27
+ actions: "close-issue"
28
+ token: ${{ secrets.GITHUB_TOKEN }}
29
+ issue-number: ${{ github.event.issue.number }}
package/_config.yml CHANGED
@@ -585,13 +585,11 @@ loading:
585
585
 
586
586
  #代码高亮增强
587
587
  # code highlight
588
- hightlight:
589
- enable: false
590
- # 代码块行高限制
591
- # Code block line height limit
592
- hightlimit: 200
588
+ highlight:
589
+ enable: true
590
+ limit: 200 # 代码行高限制 / Code line limit
593
591
  copy: true # 是否开启复制按钮 / Whether to enable the copy button
594
- expand: false # 是否默认展开 / Whether to expand by default
592
+ expand: true # 是否默认展开 / Whether to expand by default
595
593
  # 代码块样式
596
594
  # Code block style
597
595
  theme: default # default: 默认 / mac : apple terminal
@@ -44,11 +44,12 @@ script.
44
44
  enable: !{theme.lazyload.enable},
45
45
  error: '!{theme.lazyload.errorimg}'
46
46
  },
47
- hightlight: {
48
- enable: !{theme.hightlight.enable},
49
- limit: !{theme.hightlight.hightlimit},
50
- expand: !{theme.hightlight.expand},
51
- copy: !{theme.hightlight.copy},
47
+ highlight: {
48
+ enable: !{theme.highlight.enable},
49
+ limit: !{theme.highlight.limit},
50
+ expand: !{theme.highlight.expand},
51
+ copy: !{theme.highlight.copy},
52
+ syntax: '!{config.syntax_highlighter}'
52
53
  },
53
54
  randomlinks: !{theme.footer.randomlink},
54
55
  lang: {
@@ -78,7 +78,7 @@ script.
78
78
  )(window)
79
79
 
80
80
  console.log(
81
- "%c Program: Hexo %c Theme: Solitude %c Version: v1.5.9",
81
+ "%c Program: Hexo %c Theme: Solitude %c Version: v1.5.10",
82
82
  "border-radius:5px 0 0 5px;padding: 5px 10px;color:white;background:#ff3842;",
83
83
  "padding: 5px 10px;color:white;background:#3e9f50;",
84
84
  "border-radius:0 5px 5px 0;padding: 5px 10px;background:#0084ff;color:white;"
@@ -31,7 +31,7 @@ if theme.says.enable
31
31
  if item.video.player
32
32
  video(src=item.video.player controls="controls" style="object-fit: cover;")
33
33
  if item.video.bilibili
34
- iframe(src='//player.bilibili.com/player.html?auto-play=0&bvid=' + item.video.bilibili scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true")
34
+ iframe(src='//player.bilibili.com/player.html?autoplay=0&bvid=' + item.video.bilibili scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true")
35
35
 
36
36
  if theme.says.style === 1
37
37
  hr
@@ -51,4 +51,4 @@ if theme.says.enable
51
51
  if theme.says.strip === -1
52
52
  | - 已展开所有短文 -
53
53
  else
54
- | - 只展示最近 #{theme.says.strip} 条短文 -
54
+ | - 只展示最近 #{theme.says.strip} 条短文 -
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hexo-theme-solitude",
3
- "version": "1.5.9",
3
+ "version": "1.5.10",
4
4
  "description": "A beautiful, powerful, and efficient Hexo theme developed by the wleelw",
5
5
  "main": "package.json",
6
6
  "scripts": {
package/plugins.yml CHANGED
@@ -51,7 +51,7 @@ aplayer_js:
51
51
  version: 1.10.1
52
52
  meting_js:
53
53
  name: meting
54
- file: Meting.min.js
54
+ file: dist/Meting.min.js
55
55
  version: 2.0.1
56
56
  pace_js:
57
57
  name: pace-js
@@ -120,8 +120,7 @@ hexo.extend.filter.register('before_generate', () => {
120
120
  jsdelivr: `https://cdn.jsdelivr.net/npm/${name}${verType}/${min_file}`,
121
121
  unpkg: `https://unpkg.com/${name}${verType}/${file}`,
122
122
  cdnjs: `https://cdnjs.cloudflare.com/ajax/libs/${cdnjs_name}/${version}/${min_cdnjs_file}`,
123
- custom: (CDN.custom_format || '').replace(/\$\{(.+?)\}/g, (match, $1) => value[$1]),
124
- cdncbd: `https://cdn.cbd.int/${name}${verType}/${file}`,
123
+ custom: (CDN.custom_format || '').replace(/\$\{(.+?)}/g, (match, $1) => value[$1]),
125
124
  }
126
125
 
127
126
  data[key] = cdnSource[type]
@@ -10,13 +10,8 @@ hexo.extend.filter.register('before_generate', () => {
10
10
  process.exit(-1);
11
11
  }
12
12
 
13
- if (config.prismjs.enable) {
14
- logger.error('主题尚未支持 prismjs 请使用 highlightjs !');
15
- process.exit(-1);
16
- }
17
-
18
13
  if (Number(majorVer) < 14) {
19
14
  logger.error('请将 Node.js 升级到 v14.0.0 或更高的版本!');
20
15
  process.exit(-1);
21
16
  }
22
- });
17
+ });
@@ -1,24 +1,23 @@
1
1
  'use strict';
2
2
 
3
3
  hexo.extend.filter.register('after_post_render', function (data) {
4
- const config = hexo.theme.config
5
- data.title = data.title || '无标题';
4
+ data.title = data.title || 'Untitled';
5
+ const { config } = hexo.theme;
6
6
  if (data.layout === 'post') {
7
- data.locate = data.locate || config.post.default.locate
8
- data.cc = data.cc || config.post.default.copyright
9
- data.cover = data.cover || config.post.default.cover[getRandomInt(0, config.post.default.cover.length)] || '/img/default.png'
7
+ const { copyright, locate,cover } = hexo.theme.config.post.default
8
+ data.locate = data.locate || locate
9
+ data.cc = data.cc || copyright
10
+ data.cover = data.cover || cover ? cover[getRandomInt(0, cover?.length)] : '/img/default.png'
10
11
  data.excerpt = data.description || data.excerpt
11
- if (config.aside.toc.post && data.toc !== false) data.toc = true
12
- else data.toc = false
12
+ data.toc = !!(config.aside.toc.post && data.toc !== false);
13
13
  }
14
14
  if (data.layout === 'page') {
15
- data.cover = data.cover || config.page.default.cover[getRandomInt(0, config.post.default.cover.length)] || '/img/default.png'
15
+ const { cover } = hexo.theme.config.page.default
16
+ data.cover = data.cover || cover ? cover[getRandomInt(0, cover?.length)] :'/img/default.png'
16
17
  data.excerpt = data.title
17
- if (config.aside.toc.page && data.toc !== false && data.aside) data.toc = true
18
- else data.toc = false
18
+ data.toc = !!(config.aside.toc.page && data.toc !== false && data.aside);
19
19
  }
20
- if (config.comment.enable && data.comment !== false) data.comment = true
21
- else data.comment = false
20
+ data.comment = !!(config.comment.enable && data.comment !== false);
22
21
  return data;
23
22
  });
24
23
 
@@ -1,5 +1,3 @@
1
- const urlFor = require('hexo-util').url_for.bind(hexo)
2
-
3
1
  hexo.extend.filter.register('after_render:html', function (data) {
4
2
  if (!hexo.theme.config.lazyload.enable) return
5
3
  return data.replace(
@@ -1,8 +1,5 @@
1
1
  hexo.extend.filter.register('after_render:html', function (data) {
2
- const posts = []
3
- hexo.locals.get('posts').map(function (post) {
4
- if (post.random !== false) posts.push(post.path)
5
- })
6
- data += `<script>const posts=${JSON.stringify(posts)};function toRandomPost(){ pjax.loadUrl('/'+posts[Math.floor(Math.random()*posts.length)]); };</script>`
7
- return data
8
- })
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('/'+posts[Math.floor(Math.random()*posts.length)]); };</script>`;
4
+ return data;
5
+ });
@@ -23,6 +23,22 @@ hexo.extend.filter.register('stylus:renderer', function (style) {
23
23
  style.define('about', data && data.about ? Object.keys(data.about) : []);
24
24
 
25
25
  initGroupColor(theme.config.hometop.group,style);
26
+
27
+ // hightlight
28
+ const { syntax_highlighter: syntaxHighlighter, highlight, prismjs } = hexo.config
29
+ let { enable: highlightEnable, line_number: highlightLineNumber } = highlight
30
+ let { enable: prismjsEnable, line_number: prismjsLineNumber } = prismjs
31
+
32
+ // for hexo > 7.0
33
+ if (syntaxHighlighter) {
34
+ highlightEnable = syntaxHighlighter === 'highlight.js'
35
+ prismjsEnable = syntaxHighlighter === 'prismjs'
36
+ }
37
+
38
+ style.define('$highlight_enable', highlightEnable)
39
+ style.define('$highlight_line_number', highlightLineNumber)
40
+ style.define('$prismjs_enable', prismjsEnable)
41
+ style.define('$prismjs_line_number', prismjsLineNumber)
26
42
  });
27
43
 
28
44
  function initGroupColor(gg,style) {
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  function bilibili(args) {
4
- return `<iframe class="bvideo" width="100%" height="600" src="//player.bilibili.com/player.html?aid=1351697032&bvid=${args}&p=1" border="0" frameBorder="no" framespacing="0" allowFullScreen="true"></iframe>`
4
+ return `<iframe class="bvideo" width="100%" height="600" src="//player.bilibili.com/player.html?autoplay=0&bvid=${args}" border="0" frameBorder="no" framespacing="0" allowFullScreen="true"></iframe>`
5
5
  }
6
6
 
7
- hexo.extend.tag.register('bvideo', bilibili, {ends: false})
7
+ hexo.extend.tag.register('bvideo', bilibili, {ends: false})
@@ -22,4 +22,7 @@ else if hexo-config('hightlight.theme') == 'mac'
22
22
  $hl_bg_light = #FFFFFF
23
23
  $hltools_bg_light = #E7E7E7
24
24
  $hl_bg_dark = #1C1E1E
25
- $hltools_bg_dark = #2A282A
25
+ $hltools_bg_dark = #2A282A
26
+
27
+ // code
28
+ $line-height-code-block = 1.6
@@ -0,0 +1,45 @@
1
+ @import "diff"
2
+ figure
3
+ pre
4
+ margin 0
5
+ padding 8px 0
6
+ border none
7
+ table
8
+ display block
9
+ border none
10
+ overflow-y hidden
11
+ overflow-x auto
12
+
13
+ td
14
+ padding 0
15
+ border none
16
+ height 100%
17
+
18
+ &.gutter
19
+ opacity .6
20
+ user-select none
21
+
22
+ pre
23
+ overflow auto
24
+ line-height 1.6
25
+ margin 0
26
+ padding 8px .5rem
27
+ border none
28
+ color var(--efu-secondtext)
29
+ background var(--efu-secondbg)
30
+ border-right var(--style-border-always)
31
+ text-align right
32
+
33
+ &.code
34
+ width 100%
35
+ display flex
36
+ position relative
37
+
38
+ pre
39
+ padding-right .5rem
40
+ padding-left .5rem
41
+ width 100%
42
+
43
+ .line
44
+ &.marked
45
+ background-color: rgba(97, 97, 97, .314)
@@ -1,3 +1,13 @@
1
+ @import "color"
2
+
3
+ @import "theme/" + hexo-config('highlight.theme')
4
+
5
+ if $highlight_enable
6
+ @require "highlight/index.styl"
7
+
8
+ if $prismjs_enable
9
+ @require "prismjs/index.styl"
10
+
1
11
  figure
2
12
  &:hover
3
13
  box-shadow var(--efu-shadow-border-hover)
@@ -25,11 +35,6 @@ figure
25
35
  padding 0
26
36
  line-height 1.6
27
37
 
28
- pre
29
- margin 0
30
- padding 8px 0
31
- border none
32
-
33
38
  .highlight-tools
34
39
  position relative
35
40
  display flex
@@ -43,6 +48,13 @@ figure
43
48
  border-bottom var(--style-border-always)
44
49
  color var(--efu-fontcolor)
45
50
 
51
+ &.closed
52
+ .expand
53
+ transition all .3s ease 0s
54
+
55
+ & ~ *
56
+ display none
57
+
46
58
  .st-copy-fill
47
59
  position absolute
48
60
  cursor pointer
@@ -58,9 +70,6 @@ figure
58
70
  cursor pointer
59
71
  transition transform .3s ease 0s
60
72
 
61
- &.closed
62
- transition all .3s ease 0s
63
-
64
73
  .code-lang
65
74
  text-transform capitalize
66
75
  position absolute
@@ -97,47 +106,11 @@ figure
97
106
  i
98
107
  color var(--efu-white)
99
108
 
100
- table
101
- display block
102
- border none
103
- overflow-y hidden
104
- overflow-x auto
105
-
106
- td
107
- padding 0
108
- border none
109
- height 100%
110
-
111
- &.gutter
112
- opacity .6
113
- user-select none
114
-
115
- pre
116
- overflow auto
117
- line-height 1.6
118
- margin 0
119
- padding 8px .5rem
120
- border none
121
- color var(--efu-secondtext)
122
- background var(--efu-secondbg)
123
- border-right var(--style-border-always)
124
- text-align right
125
-
126
- &.code
127
- width 100%
128
- display flex
129
- position relative
130
-
131
- pre
132
- padding-right .5rem
133
- padding-left .5rem
134
- width 100%
135
-
136
- .line
137
- &.marked
138
- background-color: rgba(97, 97, 97, .314)
139
-
140
- @import "theme"
141
- @import "diff"
142
-
143
- @import "theme/" + hexo-config('hightlight.theme')
109
+ &.expand-done
110
+ display none
111
+
112
+ &:not(.expand-done)
113
+ & ~ table,
114
+ & ~ pre
115
+ overflow: hidden
116
+ height: unit(hexo-config('highlight.limit'), px)
@@ -0,0 +1,184 @@
1
+ if hexo-config('hightlight.color') == 'default'
2
+ pre[class*='language-']
3
+ .token.function
4
+ color: #ffb62c
5
+
6
+ .token.comment,
7
+ .token.prolog,
8
+ .token.doctype,
9
+ .token.cdata
10
+ color: rgba(149, 165, 166, .8)
11
+
12
+ .token.punctuation
13
+ color: #5e6687
14
+
15
+ .token.namespace
16
+ opacity: .7
17
+
18
+ .token.operator,
19
+ .token.boolean,
20
+ .token.number
21
+ color: #c76b29
22
+
23
+ .token.property
24
+ color: #c08b30
25
+
26
+ .token.tag
27
+ color: #3d8fd1
28
+
29
+ .token.string
30
+ color: #22a2c9
31
+
32
+ .token.selector
33
+ color: #6679cc
34
+
35
+ .token.attr-name
36
+ color: #c76b29
37
+
38
+ .token.entity,
39
+ .token.url,
40
+ .language-css .token.string,
41
+ .style .token.string
42
+ color: #22a2c9
43
+
44
+ .token.attr-value,
45
+ .token.keyword,
46
+ .token.control,
47
+ .token.directive,
48
+ .token.unit
49
+ color: #ac9739
50
+
51
+ .token.statement,
52
+ .token.regex,
53
+ .token.atrule
54
+ color: #22a2c9
55
+
56
+ .token.placeholder,
57
+ .token.variable
58
+ color: #3d8fd1
59
+
60
+ .token.deleted
61
+ text-decoration: line-through
62
+
63
+ .token.inserted
64
+ border-bottom: 1px dotted #202746
65
+ text-decoration: none
66
+
67
+ .token.italic
68
+ font-style: italic
69
+
70
+ .token.important,
71
+ .token.bold
72
+ font-weight: bold
73
+
74
+ .token.important
75
+ color: #c94922
76
+
77
+ .token.entity
78
+ cursor: help
79
+
80
+ pre > code.highlight
81
+ outline: .4em solid #c94922
82
+ outline-offset: .4em
83
+
84
+ if hexo-config('hightlight.color') == 'vscode'
85
+ pre[class*='language-']
86
+ .token.comment
87
+ color #6a737d
88
+
89
+ .token.prolog
90
+ color #6a737d
91
+
92
+ .token.doctype
93
+ color #6a737d
94
+
95
+ .token.cdata
96
+ color #6a737d
97
+
98
+ .token.punctuation
99
+ color #d4d4d4
100
+
101
+ .token.namespace
102
+ opacity .7
103
+
104
+ .token.operator
105
+ color #d4d4d4
106
+
107
+ .token.boolean
108
+ color #4ec9b0
109
+
110
+ .token.number
111
+ color #4ec9b0
112
+
113
+ .token.property
114
+ color #c08b30
115
+
116
+ .token.tag
117
+ color #3d8fd1
118
+
119
+ .token.string
120
+ color #4ec9b0
121
+
122
+ .token.selector
123
+ color #6679cc
124
+
125
+ .token.attr-name
126
+ color #c76b29
127
+
128
+ .token.entity
129
+ color #c76b29
130
+
131
+ .token.url
132
+ color #22a2c9
133
+
134
+ .token.attr-value
135
+ color #4ec9b0
136
+
137
+ .token.keyword
138
+ color #c94922
139
+
140
+ .token.control
141
+ color #c94922
142
+
143
+ .token.directive
144
+ color #c94922
145
+
146
+ .token.unit
147
+ color #c94922
148
+
149
+ .token.statement
150
+ color #c94922
151
+
152
+ .token.regex
153
+ color #22a2c9
154
+
155
+ .token.atrule
156
+ color #22a2c9
157
+
158
+ .token.placeholder
159
+ color #3d8fd1
160
+
161
+ .token.variable
162
+ color #3d8fd1
163
+
164
+ .token.deleted
165
+ color #c94922
166
+
167
+ .token.inserted
168
+ color #4ec9b0
169
+
170
+ .token.italic
171
+ font-style italic
172
+
173
+ .token.important
174
+ font-weight bold
175
+
176
+ .token.important
177
+ color #c94922
178
+
179
+ .token.entity
180
+ cursor help
181
+
182
+ pre > code.highlight
183
+ outline .4em solid #c94922
184
+ outline-offset .4em
@@ -0,0 +1,13 @@
1
+ @require line-number
2
+
3
+ @require diff
4
+
5
+ #article-container
6
+ pre[class*='language-']
7
+ scrollbar-color var(--hlscrollbar-bg) transparent
8
+
9
+ &::-webkit-scrollbar-thumb
10
+ background var(--hlscrollbar-bg)
11
+
12
+ &:not(.line-numbers)
13
+ padding 10px 20px
@@ -0,0 +1,30 @@
1
+ #article-container
2
+ pre[class*='language-']
3
+ &.line-numbers
4
+ position relative
5
+ margin 0
6
+ overflow-x auto
7
+
8
+ > code
9
+ display block
10
+ position relative
11
+ padding 8px 0 8px 45px
12
+
13
+ .line-numbers-rows
14
+ position absolute
15
+ top 0
16
+ left 0
17
+ color var(--efu-secondtext)
18
+ background var(--efu-hltools-bg)
19
+ border-right var(--style-border-always)
20
+ padding 8px 0
21
+
22
+ & > span
23
+ display block
24
+ counter-increment linenumber
25
+ pointer-events none
26
+ text-align center
27
+
28
+ &:before
29
+ padding 0 0.5em
30
+ content counter(linenumber)
@@ -4,9 +4,11 @@ figure
4
4
  .st-copy-fill
5
5
  right .7rem
6
6
 
7
+ &.closed
8
+ .expand
9
+ transform rotate(-90deg)
10
+
7
11
  .expand
8
12
  & + .code-lang
9
13
  left 1.7rem
10
14
 
11
- &.closed
12
- transform rotate(-90deg)
@@ -21,5 +21,6 @@ figure
21
21
  & + .code-lang
22
22
  left 75px
23
23
 
24
- &.closed
24
+ &.closed
25
+ .expand
25
26
  transform rotate(90deg)
@@ -31,4 +31,7 @@ if hexo-config('music.enable')
31
31
  @import "share.styl"
32
32
 
33
33
  if hexo-config('google_adsense.enable')
34
- @import "google.styl"
34
+ @import "google.styl"
35
+
36
+ if hexo-config('message.enable')
37
+ @import "message/index.styl"
@@ -63,7 +63,7 @@
63
63
  img
64
64
  margin auto
65
65
 
66
- code
66
+ code:not([class*='language-'])
67
67
  color var(--efu-white)
68
68
  padding 0.2rem 0.4rem
69
69
  border-radius 4px
@@ -14,7 +14,5 @@ if hexo-config('comment.commentBarrage')
14
14
 
15
15
  @import "pagination"
16
16
 
17
- @import "_highlight/index"
18
-
19
17
  if hexo-config('post_ai.enable')
20
18
  @import "postAI"
@@ -11,4 +11,7 @@ if hexo-config('css_prefix')
11
11
  // widgets
12
12
  @import '_widgets/index.styl'
13
13
 
14
- @import '_mode/*'
14
+ @import '_mode/*'
15
+
16
+ // highlight
17
+ @import '_highlight/index'
package/source/js/main.js CHANGED
@@ -658,72 +658,103 @@ let sco = {
658
658
  },
659
659
  }
660
660
 
661
- class hightlight {
662
- static createEle(langEl, item) {
661
+ const AddHighLightTool = () => {
662
+ const highlight = GLOBAL_CONFIG.highlight;
663
+ if (!highlight) return;
664
+
665
+ const {copy, expand, limit, syntax} = highlight;
666
+ const $isPrismjs = syntax === 'prismjs';
667
+ const $isShowTool = highlight.enable || copy || expand || limit;
668
+ const expandClass = !expand === true ? 'closed' : ''
669
+ const $syntaxHighlight = syntax === 'highlight.js' ? document.querySelectorAll('figure.highlight') : document.querySelectorAll('pre[class*="language-"]')
670
+
671
+ if (!(($isShowTool || limit) && $syntaxHighlight.length)) return
672
+
673
+ const copyEle = copy ? `<i class="solitude st-copy-fill copy-button"></i>` : '<i></i>';
674
+ const expandEle = `<i class="solitude st-arrow-down expand"></i>`;
675
+ const limitEle = limit ? `<i class="solitude st-show-line"></i>` : '<i></i>';
676
+
677
+ const alertInfo = (ele, text) => {
678
+ utils.snackbarShow(text, false, 2000);
679
+ }
680
+
681
+ const copyCode = (e) => {
682
+ if (document.queryCommandSupported && document.queryCommandSupported('copy')) {
683
+ document.execCommand('copy')
684
+ alertInfo(e, GLOBAL_CONFIG.lang.copy.success)
685
+ } else {
686
+ alertInfo(e, GLOBAL_CONFIG.lang.copy.error)
687
+ }
688
+ }
689
+
690
+ const copyFn = (e) => {
691
+ const $buttonParent = e.parentNode
692
+ $buttonParent.classList.add('copy-true')
693
+ const selection = window.getSelection()
694
+ const range = document.createRange()
695
+ const preCodeSelector = $isPrismjs ? 'pre code' : 'table .code pre'
696
+ range.selectNodeContents($buttonParent.querySelectorAll(`${preCodeSelector}`)[0])
697
+ selection.removeAllRanges()
698
+ selection.addRange(range)
699
+ copyCode(e.lastChild)
700
+ selection.removeAllRanges()
701
+ $buttonParent.classList.remove('copy-true')
702
+ }
703
+
704
+ const expandClose = (e) => {
705
+ e.classList.toggle('closed')
706
+ }
707
+
708
+ const shrinkEle = function () {
709
+ this.classList.toggle('expand-done')
710
+ }
711
+
712
+ const ToolsFn = function (e) {
713
+ const $target = e.target.classList
714
+ if ($target.contains('expand')) expandClose(this)
715
+ else if ($target.contains('copy-button')) copyFn(this)
716
+ }
717
+
718
+ const createEle = (lang, item, service) => {
663
719
  const fragment = document.createDocumentFragment()
664
- const highlightCopyEle = GLOBAL_CONFIG.hightlight.copy ? '<i class="solitude st-copy-fill"></i>' : '<i></i>'
665
- const highlightExpandEle = '<i class="solitude st-arrow-down expand"></i>'
666
-
667
- const hlTools = document.createElement('div')
668
- hlTools.className = `highlight-tools`
669
- hlTools.innerHTML = highlightExpandEle + langEl + highlightCopyEle
670
- let expand = GLOBAL_CONFIG.hightlight.expand
671
- hlTools.children[0].addEventListener('click', (e) => {
672
- if (expand) {
673
- hlTools.children[0].classList.add('closed')
674
- $table.setAttribute('style', 'display:none')
675
- if ($expand.length !== 0) {
676
- $expand[0].setAttribute('style', 'display:none')
677
- }
678
- } else {
679
- hlTools.children[0].classList.remove('closed')
680
- $table.setAttribute('style', 'display:block')
681
- if ($expand.length !== 0) {
682
- $expand[0].setAttribute('style', 'display:block')
683
- }
684
- if (GLOBAL_CONFIG.hightlight.limit && itemHeight > GLOBAL_CONFIG.hightlight.limit) {
685
- $table.setAttribute('style', `height: ${GLOBAL_CONFIG.hightlight.limit}px`)
686
- } else {
687
- $table.setAttribute('style', `height: auto`)
688
- }
689
- }
690
- expand = !expand
691
- })
692
- hlTools.children[2].addEventListener('click', (e) => {
693
- utils.copy($table.querySelector('.code').innerText)
694
- })
695
- const ele = document.createElement('div')
696
- fragment.appendChild(hlTools)
697
- const itemHeight = item.clientHeight, $table = item.querySelector('table'),
698
- $expand = item.getElementsByClassName('code-expand-btn')
699
- if (GLOBAL_CONFIG.hightlight.limit && itemHeight > GLOBAL_CONFIG.hightlight.limit) {
700
- $table.setAttribute('style', `height: ${GLOBAL_CONFIG.hightlight.limit}px`)
720
+
721
+ if ($isShowTool) {
722
+ const hlTools = document.createElement('div')
723
+ hlTools.className = `highlight-tools ${expandClass}`
724
+ hlTools.innerHTML = expandEle + lang + copyEle
725
+ utils.addEventListenerPjax(hlTools, 'click', ToolsFn)
726
+ fragment.appendChild(hlTools)
727
+ }
728
+
729
+ if (limit && item.offsetHeight > limit + 30) {
730
+
731
+ const ele = document.createElement('div')
701
732
  ele.className = 'code-expand-btn'
702
- ele.innerHTML = '<i class="solitude st-show-line"></i>'
703
- ele.addEventListener('click', (e) => {
704
- $table.setAttribute('style', `height: ${itemHeight}px`)
705
- e.target.classList.add('expand-done')
706
- e.target.setAttribute('style', 'display:none')
707
- })
733
+ ele.innerHTML = limitEle
734
+ utils.addEventListenerPjax(ele, 'click', shrinkEle)
708
735
  fragment.appendChild(ele)
709
736
  }
710
- item.insertBefore(fragment, item.firstChild)
711
- if (!expand) {
712
- hlTools.children[0].classList.add('closed')
713
- $table.setAttribute('style', 'display:none')
714
- if ($expand.length !== 0) {
715
- $expand[0].setAttribute('style', 'display:none')
716
- }
737
+
738
+ if (service === 'hl') {
739
+ item.insertBefore(fragment, item.firstChild)
740
+ } else {
741
+ item.parentNode.insertBefore(fragment, item)
717
742
  }
718
743
  }
719
744
 
720
- static init() {
721
- const $figureHighlight = document.querySelectorAll('figure.highlight'), that = this
722
- $figureHighlight.forEach(function (item) {
745
+ if ($isPrismjs) {
746
+ $syntaxHighlight.forEach(item => {
747
+ const langName = item.getAttribute('data-language') || 'Code'
748
+ const highlightLangEle = `<div class="code-lang">${langName}</div>`
749
+ utils.wrap(item, 'figure', {class: 'highlight'})
750
+ createEle(highlightLangEle, item)
751
+ })
752
+ } else {
753
+ $syntaxHighlight.forEach(item => {
723
754
  let langName = item.getAttribute('class').split(' ')[1]
724
- if (langName === 'plaintext' || langName === undefined) langName = 'Code'
725
- const highlightLangEle = `<div class="code-lang">${langName.toUpperCase()}</div>`
726
- that.createEle(highlightLangEle, item)
755
+ if (langName === 'plain' || langName === undefined) langName = 'Code'
756
+ const highlightLangEle = `<div class="code-lang">${langName}</div>`
757
+ createEle(highlightLangEle, item, 'hl')
727
758
  })
728
759
  }
729
760
  }
@@ -785,7 +816,7 @@ window.refreshFn = () => {
785
816
  GLOBAL_CONFIG.randomlinks && randomLinksList()
786
817
  PAGE_CONFIG.comment && initComment()
787
818
  PAGE_CONFIG.toc && toc.init();
788
- (PAGE_CONFIG.is_post || PAGE_CONFIG.is_page) && ((GLOBAL_CONFIG.hightlight.enable && hightlight.init()) || tabs.init())
819
+ (PAGE_CONFIG.is_post || PAGE_CONFIG.is_page) && ((AddHighLightTool()) || tabs.init())
789
820
  PAGE_CONFIG.is_home && showTodayCard()
790
821
  GLOBAL_CONFIG.covercolor.enable && coverColor()
791
822
  sco.initConsoleState()
@@ -136,12 +136,11 @@ const utils = {
136
136
  },
137
137
  isMobile: () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),
138
138
  isHidden: e => 0 === e.offsetHeight && 0 === e.offsetWidth,
139
- addEventListenerPjax: function (element, eventType, callback, useCapture = false) {
140
- if (element == null) return
141
- element.addEventListener(eventType, callback, useCapture);
142
- utils.addGlobalFn("pjax", function () {
143
- element.removeEventListener(eventType, callback, useCapture);
144
- });
139
+ addEventListenerPjax: (ele, event, fn, option = false) => {
140
+ ele.addEventListener(event, fn, option)
141
+ utils.addGlobalFn('pjax', () => {
142
+ ele.removeEventListener(event, fn, option)
143
+ })
145
144
  },
146
145
  addGlobalFn: (key, fn, name = false, parent = window) => {
147
146
  const globalFn = parent.globalFn || {}