Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add folding tag #1489

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions scripts/tags/folding.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use strict';

// Usage:
// {% folding 参数(可选), 标题 %}
//
// ![](https://cdn.jsdelivr.net/gh/xaoxuu/cdn-wallpaper/abstract/41F215B9-261F-48B4-80B5-4E86E165259E.jpeg)
//
// {% endfolding %}
// 颜色: blue, cyan, green, yellow, red
// 状态: 状态填写 open 代表默认打开。

// 举例:
// {% folding cyan open, 查看默认打开的折叠框 %}
//
// 这是一个默认打开的折叠框。
//
// {% endfolding %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Usage:
// {% folding 参数(可选), 标题 %}
//
// ![](https://cdn.jsdelivr.net/gh/xaoxuu/cdn-wallpaper/abstract/41F215B9-261F-48B4-80B5-4E86E165259E.jpeg)
//
// {% endfolding %}
// 颜色: blue, cyan, green, yellow, red
// 状态: 状态填写 open 代表默认打开。
// 举例:
// {% folding cyan open, 查看默认打开的折叠框 %}
//
// 这是一个默认打开的折叠框。
//
// {% endfolding %}
/**
* Usage:
* {% folding [args], title %}
* content
* {% endfolding %}
*
* args:
* - color: blue, cyan, green, yellow, red
* - status: open # means open by default
*
* example:
* {% folding cyan open, view the default folding box %}
* This is a folding box that opens by default
* {% endfolding %}
*/

function postFolding(args, content) {
args = args.join(' ').split(',');
let style = ''
let title = ''
if (args.length > 1) {
style = args[0].trim()
title = args[1].trim()
} else if (args.length > 0) {
title = args[0].trim()
}
if (style != undefined) {
return `<details ${style}><summary> ${hexo.render.renderSync({text: title, engine: 'markdown'}).split('\n').join('')} </summary>
<div class='content'>
${hexo.render.renderSync({text: content, engine: 'markdown'}).split('\n').join('')}
</div>
</details>`;
} else {
return `<details><summary> ${hexo.render.renderSync({text: title, engine: 'markdown'}).split('\n').join('')} </summary>
<div class='content'>
${hexo.render.renderSync({text: content, engine: 'markdown'}).split('\n').join('')}
</div>
</details>`;
}

}

hexo.extend.tag.register('folding', postFolding, {ends: true});
170 changes: 170 additions & 0 deletions source/css/_common/scaffolding/tags/folding.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
// gap
$gap = 16px // base gap
$gap-h2 = 48px
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The font size is recommended to use rem

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

px与rem的区别在于,当父级的字体大小改变时,是否发生改变(简单的理解为是否需要随文章字体大小而改变)

你这里用px,确定h2~h4这些标题,不需要随文章字体大小而改变么?

$gap-h3 = 32px
$gap-h4 = 16px
$gap-paragraph = 1rem // 区块间距
$gap-row = .5rem // 行间距
$gap-card = $gap
// border radius
$border-codeblock = 4px
// common
$color-card = white
$color-text = #555
jiangtj marked this conversation as resolved.
Show resolved Hide resolved
$color-block = #f6f6f6
// font size
$fontsize-meta = .875rem // 14px
$fontsize-list = .9375rem // 15px
//color
$color-p = #555
$color-md-blue = #e8f4fd
$color-md-blue1 = rgba(33,150,243,0.3)

$color-mac-cyan = #e8fafe
$color-mac-cyan1 = rgba(27,205,252,0.3)
$color-mac-green = #ebf9ed
$color-mac-green1 =rgba(61,197,80,.3)
$color-mac-yellow = #fff8e9
$color-mac-yellow1 = rgba(255,189,43,0.3)
$color-mac-red = #feefee
$color-mac-red1 = rgba(254,95,88,0.3)
// transition time
$time = 0.28s

details
display: block
padding: $gap
margin: $gap-row 0
border-radius: $border-codeblock
background: $color-card
font-size: $fontsize-list
transition: all $time ease
-moz-transition: all $time ease
-webkit-transition: all $time ease
-o-transition: all $time ease

summary
cursor: url(/images/ayuda.cur),auto;
padding: $gap
outline:none;
margin: 0 - $gap
border-radius: $border-codeblock
color: alpha($color-p, .7)
font-size: $fontsize-meta
font-weight: bold
position: relative
line-height: normal


>p, h1, h2, h3, h4, h5, h6
display: inline !important
border-bottom: none !important
cursor: url(/images/ayuda.cur),auto;

&:hover
color: $color-p

&:after
position: absolute
content: '+'
text-align: center
top: 50%
transform: translateY(-50%)
right: $gap

border: 1px solid $color-block

> summary
background: $color-block

&[blue]
border-color: $color-md-blue

> summary
background:$color-md-blue

&[cyan]
border-color:$color-mac-cyan

> summary
background:$color-mac-cyan

&[green]
border-color:$color-mac-green

> summary
background:$color-mac-green

&[yellow]
border-color:$color-mac-yellow

> summary
background:$color-mac-yellow

&[red]
border-color:$color-mac-red

> summary
background:$color-mac-red

details[open]
border-color: alpha($color-p, .2)

> summary
border-bottom: 1px solid alpha($color-p, .2)
border-bottom-left-radius: 0
border-bottom-right-radius: 0

&[blue]
border-color: alpha($color-md-blue1, .3)

> summary
border-bottom-color: alpha($color-md-blue1, .3)

&[cyan]
border-color: alpha($color-mac-cyan1, .3)

> summary
border-bottom-color: alpha($color-mac-cyan1, .3)

&[green]
border-color: alpha($color-mac-green1, .3)

> summary
border-bottom-color: alpha($color-mac-green1, .3)

&[yellow]
border-color: alpha($color-mac-yellow1, .3)

> summary
border-bottom-color: alpha($color-mac-yellow1, .3)

&[red]
border-color: alpha($color-mac-red1, .3)

> summary
border-bottom-color: alpha($color-mac-red1, .3)

> summary
color: $color-p
margin-bottom: 0

&:hover
&:after
content: '-'

> div.content
padding: $gap
margin: 0 - $gap
margin-top: 0

p > a:hover
text-decoration: underline

>
p, .tabs, ul, ol, .highlight, .note, .fancybox, details
&:first-child
margin-top: 0

&:last-child
margin-bottom: 0
1 change: 1 addition & 0 deletions source/css/_common/scaffolding/tags/tags.styl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@import 'group-pictures';
@import 'label';
@import 'tabs';
@import 'folding';

@import 'note' if (hexo-config('note.style') != 'disabled');

Expand Down