[feat] tag-plugin: icon

This commit is contained in:
xaoxuu 2024-02-02 16:53:05 +08:00
parent 1b02cc55ab
commit c93c38ee5a
5 changed files with 47 additions and 0 deletions

View File

@ -304,6 +304,9 @@ tag_plugins:
aru: https://gcore.jsdelivr.net/gh/cdn-x/emoji/aru-l/${name}.gif aru: https://gcore.jsdelivr.net/gh/cdn-x/emoji/aru-l/${name}.gif
tieba: https://gcore.jsdelivr.net/gh/cdn-x/emoji/tieba/${name}.png tieba: https://gcore.jsdelivr.net/gh/cdn-x/emoji/tieba/${name}.png
blobcat: https://gcore.jsdelivr.net/gh/norevi/waline-blobcatemojis@1.0/blobs/${name}.png blobcat: https://gcore.jsdelivr.net/gh/norevi/waline-blobcatemojis@1.0/blobs/${name}.png
icon:
# 留空时,图标和文字颜色相同
default_color: accent # theme, accent, red, orange, yellow, green, cyan, blue, purple
# {% image %} # {% image %}
image: image:
fancybox: false # true, false fancybox: false # true, false

View File

@ -29,6 +29,7 @@ hexo.extend.tag.register('checkbox', require('./lib/checkbox')(hexo, 'checkbox')
hexo.extend.tag.register('radio', require('./lib/checkbox')(hexo, 'radio')) hexo.extend.tag.register('radio', require('./lib/checkbox')(hexo, 'radio'))
hexo.extend.tag.register('copy', require('./lib/copy')(hexo)) hexo.extend.tag.register('copy', require('./lib/copy')(hexo))
hexo.extend.tag.register('emoji', require('./lib/emoji')(hexo)) hexo.extend.tag.register('emoji', require('./lib/emoji')(hexo))
hexo.extend.tag.register('icon', require('./lib/icon')(hexo))
hexo.extend.tag.register('frame', require('./lib/frame')(hexo)) hexo.extend.tag.register('frame', require('./lib/frame')(hexo))
hexo.extend.tag.register('image', require('./lib/image')(hexo)) hexo.extend.tag.register('image', require('./lib/image')(hexo))
hexo.extend.tag.register('link', require('./lib/link')(hexo)) hexo.extend.tag.register('link', require('./lib/link')(hexo))

27
scripts/tags/lib/icon.js Normal file
View File

@ -0,0 +1,27 @@
/**
* icon.js v1.0 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% icon key [color:color] [style:css] %}
*
*/
'use strict'
module.exports = ctx => function(args) {
args = ctx.args.map(args, ['color', 'style'], ['key'])
if (args.color == null) {
args.color = ctx.theme.config.tag_plugins.icon.default_color
}
var el = ''
el += '<span class="tag-plugin colorful icon"'
el += ' ' + ctx.args.joinTags(args, ['color']).join(' ')
el += '>'
var more = ''
if (args.style) {
more += `style="${args.style}"`
}
el += ctx.utils.icon(args.key, more)
el += '</span>'
return el
}

View File

@ -40,6 +40,10 @@ set_dynamic_color($theme)
set_dynamic_color($c-blue) set_dynamic_color($c-blue)
.colorful[color='purple'] .colorful[color='purple']
set_dynamic_color($c-purple) set_dynamic_color($c-purple)
.colorful[color='theme']
set_dynamic_color($color-theme)
.colorful[color='accent']
set_dynamic_color($color-accent)
.colorful[color='light'] .colorful[color='light']
--theme-block: white --theme-block: white

View File

@ -0,0 +1,12 @@
span.tag-plugin.icon
display: inline-block
margin: -4px 1px 0
vertical-align: middle
svg,img
display: block
height: 1.5em
width: auto
svg
color: var(--theme)
img
object-fit: contain