This commit is contained in:
xaoxuu 2021-07-10 11:12:06 +08:00
parent 487216e888
commit c753b3dfbc
2 changed files with 37 additions and 15 deletions

View File

@ -1,19 +1,21 @@
/** /**
* note.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/ * note.js v1.1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来 * 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
* *
* note: * note:
* {% note [color:color] [title] content %} * {% note [color:color] [title] content %}
* *
* noteblock: * noteblock:
* {% noteblock [color:color] title %} * {% noteblock [color:color] [codeblock:bool] title %}
* markdown content * markdown content
* {% endnoteblock %} * {% endnoteblock %}
*/ */
'use strict'; 'use strict';
function outputNoteBlock(color, title, content) { function outputNoteBlock(args, content) {
const color = args.color;
const title = args.title;
var el = ''; var el = '';
const defaultColor = hexo.theme.config.tag_plugins.note.default_color; const defaultColor = hexo.theme.config.tag_plugins.note.default_color;
if (!color && defaultColor) { if (!color && defaultColor) {
@ -24,6 +26,9 @@ function outputNoteBlock(color, title, content) {
if (color && color.length > 0) { if (color && color.length > 0) {
el += ' color="' + color + '"'; el += ' color="' + color + '"';
} }
if (args.codeblock !== undefined) {
el += ' codeblock="' + args.codeblock + '"';
}
el += '>'; el += '>';
// title // title
if (title && title.length > 0) { if (title && title.length > 0) {
@ -39,14 +44,14 @@ function outputNoteBlock(color, title, content) {
hexo.extend.tag.register('note', function(args) { hexo.extend.tag.register('note', function(args) {
args = hexo.args.map(args, ['color'], ['title', 'content']); args = hexo.args.map(args, ['color'], ['title', 'content']);
if (args.content) { if (args.content === undefined || args.content.length <= 0) {
return outputNoteBlock(args.color, args.title, args.content); args.content = args.title;
} else { args.title = '';
return outputNoteBlock(args.color, '', args.title);
} }
return outputNoteBlock(args, args.content);
}); });
hexo.extend.tag.register('noteblock', function(args, content) { hexo.extend.tag.register('noteblock', function(args, content) {
args = hexo.args.map(args, ['color'], ['title']); args = hexo.args.map(args, ['color', 'codeblock'], ['title']);
return outputNoteBlock(args.color, args.title, content); return outputNoteBlock(args, content);
}, {ends: true}); }, {ends: true});

View File

@ -1,20 +1,37 @@
.md div.note .md .tag-plugin.note
$border-block = 4px $border-block = 4px
position: relative position: relative
margin-top: 1rem margin-top: 1rem
margin-bottom: 1rem margin-bottom: 1rem
padding: 1rem padding: 0 1rem
border-radius: $border-block border-radius: $border-block
font-size: $fs-15 font-size: $fs-15
background: var(--theme-bg) background: var(--theme-bg)
border: 1px solid var(--theme) border: 1px solid var(--theme)
color: var(--text-p1) color: var(--text-p1)
div.title >.title
inside-box: $fs-15 inside-box: $fs-15
margin-bottom: 0.5rem line-height: 1.2
div.body margin-top: 1rem
>.body
inside-box: $fs-14 inside-box: $fs-14
line-height: 1.5
margin-top: .5rem
margin-bottom: 1rem
>.body:only-child
margin: 1rem 0
.md div.note:not([color])
.md .tag-plugin.note:not([color])
.highlight .highlight
background: var(--block-hover) background: var(--block-hover)
.md .tag-plugin.note[codeblock=true]
padding: 0
>.title, >.body:only-child
margin-top: 0
>.body
margin-bottom: 0
.highlight
margin: 0
border: none
background: none