From 3cbb978a22f156f6f33e149e4a78e40026caa28d Mon Sep 17 00:00:00 2001 From: HMLTFan Date: Fri, 28 Jan 2022 22:54:15 +0800 Subject: [PATCH] Added messasge tag. --- scripts/tags/message.js | 60 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 scripts/tags/message.js diff --git a/scripts/tags/message.js b/scripts/tags/message.js new file mode 100644 index 0000000..29a999c --- /dev/null +++ b/scripts/tags/message.js @@ -0,0 +1,60 @@ +/** + * Bulma Message Tag, see {@link https://bulma.io/documentation/components/message/}. + * @param {string} color The color of this message. Usable: dark, primary, link, info, success, warning, danger. + * @param {string} icon The icon of this message, can not be set. + * @param {string} title The header of this message, can not be set, supported Markdown. + * @param {string} styles Additional styles of this message, can not be set. Usable: [small, medium, large]. + * @example + * {% message color:danger icon:info-circle 'title:Very danger!' style:small %} + * **You are in danger.** + * {% endmessage %} + */ +hexo.extend.tag.register('message', function(args, content) { + var color = 'dark'; + var icon = ''; + var title = ''; + var styles = ''; + var header = ''; + args.forEach(element => { + var key = element.split(':')[0]; + var value = element.split(':')[1]; + if (value != null && value != undefined && value != '') { + switch (key) { + case 'color': + color = value; + break; + case 'icon': + icon = ``; + break; + case 'title': + title = value; + break; + case 'style': + var stylesArray = value.split(' '); + var processed = []; + stylesArray.forEach(styleElement, index => { + if (styleElement != null && styleElement != undefined && styleElement != '') { + processed.push(`is-${styleElement}`); + } + }); + styles = processed.join(' '); + break; + } + } + }); + if (icon != '' || title != '') { + header = ` +
+ ${hexo.render.renderSync({text: icon + title, engine: 'markdown'})} +
+ ` + } + return ` +
+ ${header} +
+ ${hexo.render.renderSync({text: content, engine: 'md'})} +
+
+ `; +}, { ends: true }); \ No newline at end of file