Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 924829c

Browse files
AimTaozkqiang
authored andcommittedOct 22, 2023
✨ 增加折叠块功能
1 parent d683101 commit 924829c

File tree

5 files changed

+80
-2
lines changed

5 files changed

+80
-2
lines changed
 

‎scripts/helpers/utils.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
'use strict';
44

5-
const crypto = require('crypto');
5+
const md5 = require('../utils/crypto');
66
const { decodeURL } = require('hexo-util');
77
const compareVersions = require('../../scripts/utils/compare-versions');
88

99
hexo.extend.helper.register('md5', function(string) {
10-
return crypto.createHash('md5').update(string).digest('hex');
10+
return md5(string);
1111
});
1212

1313
hexo.extend.helper.register('require_version', function(current, require) {

‎scripts/tags/fold.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const md5 = require('../utils/crypto');
2+
3+
hexo.extend.tag.register('fold', (args, content) => {
4+
args = args.join(' ').split('@');
5+
const classes = args[0] || 'default';
6+
const text = args[1] || '';
7+
const id = 'collapse-' + md5(content).slice(0, 8);
8+
9+
return `
10+
<div class="fold">
11+
<div class="fold-title fold-${classes.trim()}" data-toggle="collapse" href="#${id}" role="button" aria-expanded="false" aria-controls="${id}">
12+
${text}
13+
</div>
14+
<div class='fold-content collapse' id="${id}">
15+
${hexo.render.renderSync({ text: content, engine: 'markdown' }).split('\n').join('')}
16+
</div>
17+
</div>`;
18+
}, {
19+
ends: true
20+
});

‎scripts/utils/crypto.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
const crypto = require('crypto');
4+
5+
const md5 = (content) => {
6+
return crypto.createHash('md5').update(content).digest('hex');
7+
}
8+
9+
module.exports = md5;

‎source/css/_pages/_base/color-schema.styl

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
--button-hover-bg-color $button-hover-bg-color
2020
--highlight-bg-color $highlight-bg-color
2121
--inlinecode-bg-color $inlinecode-bg-color
22+
--fold-title-color $text-color
23+
--fold-border-color $line-color
2224

2325
dark-colors()
2426
--body-bg-color $body-bg-color-dark
@@ -40,6 +42,8 @@ dark-colors()
4042
--button-hover-bg-color $button-hover-bg-color-dark
4143
--highlight-bg-color $highlight-bg-color-dark
4244
--inlinecode-bg-color $inlinecode-bg-color-dark
45+
--fold-title-color $text-color
46+
--fold-border-color $line-color
4347

4448
img
4549
-webkit-filter brightness(.9)

‎source/css/_pages/_post/post-tag.styl

+45
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,48 @@
1+
// fold
2+
.fold
3+
margin 1rem 0
4+
border 0.5px solid var(--fold-border-color)
5+
position relative
6+
clear both
7+
border-radius 0.125rem
8+
9+
.fold-title
10+
color var(--fold-title-color)
11+
padding 0.5rem 0.75rem
12+
font-size 0.9rem
13+
font-weight bold
14+
border-radius 0.125rem
15+
16+
.fold-title:before
17+
content "▶ "
18+
font-weight bold
19+
20+
.fold-content
21+
& > *
22+
margin 0
23+
24+
& > p
25+
padding 1rem 1rem
26+
27+
.fold-default
28+
background rgba(#bbbbbb, 0.25)
29+
30+
.fold-primary
31+
background rgba(#b7a0e0, 0.25)
32+
33+
.fold-info
34+
background rgba(#a0c5e4, 0.25)
35+
36+
.fold-success
37+
background rgba(#aedcae, 0.25)
38+
39+
.fold-warning
40+
background rgba(#f8d6a6, 0.25)
41+
42+
.fold-danger
43+
background rgba(#eca9a7, 0.25)
44+
45+
146
// note
247
.note
348
padding 0.75rem

0 commit comments

Comments
 (0)
Please sign in to comment.