Skip to content

Commit 9164884

Browse files
AimTaozkqiang
authored andcommitted
✨ 增加折叠块功能
1 parent d683101 commit 9164884

File tree

5 files changed

+85
-2
lines changed

5 files changed

+85
-2
lines changed

scripts/helpers/utils.js

Lines changed: 2 additions & 2 deletions
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

Lines changed: 20 additions & 0 deletions
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()} collapsed" data-toggle="collapse" href="#${id}" role="button" aria-expanded="false" aria-controls="${id}">
12+
<div class="fold-arrow">▶</div>${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

Lines changed: 9 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,53 @@
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+
&:not(.collapsed) > .fold-arrow
17+
transform rotate(90deg)
18+
transform-origin center center
19+
20+
.fold-arrow
21+
display inline-block
22+
margin-right 0.35rem
23+
transition transform .3s ease-out
24+
25+
.fold-content
26+
& > *
27+
margin 0
28+
29+
& > p
30+
padding 1rem 1rem
31+
32+
.fold-default
33+
background rgba(#bbbbbb, 0.25)
34+
35+
.fold-primary
36+
background rgba(#b7a0e0, 0.25)
37+
38+
.fold-info
39+
background rgba(#a0c5e4, 0.25)
40+
41+
.fold-success
42+
background rgba(#aedcae, 0.25)
43+
44+
.fold-warning
45+
background rgba(#f8d6a6, 0.25)
46+
47+
.fold-danger
48+
background rgba(#eca9a7, 0.25)
49+
50+
151
// note
252
.note
353
padding 0.75rem

0 commit comments

Comments
 (0)