From 3b14e379876386b4da077ddb6cc0d0e57b64b637 Mon Sep 17 00:00:00 2001 From: ppoffice Date: Thu, 10 Feb 2022 12:14:45 -0500 Subject: [PATCH] chore(core): move tag processors to hexo-component-inferno --- include/register.js | 4 +- package.json | 2 +- scripts/tags/message.js | 60 --------------------- scripts/tags/tabs.js | 116 ---------------------------------------- 4 files changed, 3 insertions(+), 179 deletions(-) delete mode 100644 scripts/tags/message.js delete mode 100644 scripts/tags/tabs.js diff --git a/include/register.js b/include/register.js index 57f02e48b..06b2e4c91 100644 --- a/include/register.js +++ b/include/register.js @@ -11,7 +11,7 @@ module.exports = hexo => { require('hexo-component-inferno/lib/hexo/generator/tags')(hexo); require('hexo-component-inferno/lib/hexo/helper/cdn')(hexo); require('hexo-component-inferno/lib/hexo/helper/page')(hexo); + require('hexo-component-inferno/lib/hexo/tag/message')(hexo); + require('hexo-component-inferno/lib/hexo/tag/tabs')(hexo); require('hexo-component-inferno/lib/core/view').init(hexo); - require('./../scripts/tags/message')(hexo); - require('./../scripts/tags/tabs')(hexo); }; diff --git a/package.json b/package.json index 156b2f29c..3fbb2b7ab 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ }, "dependencies": { "deepmerge": "^4.2.2", - "hexo-component-inferno": "^1.0.2", + "hexo-component-inferno": "^1.1.0", "inferno": "^7.3.3", "inferno-create-element": "^7.3.3", "moment": "^2.22.2", diff --git a/scripts/tags/message.js b/scripts/tags/message.js deleted file mode 100644 index 974218f16..000000000 --- a/scripts/tags/message.js +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Bulma Message Tag, see {@link https://bulma.io/documentation/components/message/}. - * - * @param {string} color The color of this message, can not be set. 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} size The size of this message, can not be set. Usable: small, medium, large. The default - * size is between small and medium. - * - * @example - * {% message color:danger icon:info-circle 'title:Very danger!' size:small %} - * **You are in danger.** - * {% endmessage %} - */ -module.exports = function(hexo) { - hexo.extend.tag.register('message', (args, content) => { - let icon = ''; - let title = ''; - let classes = ''; - let header = ''; - - args.forEach(element => { - const key = element.split(':')[0].trim(); - const value = element.split(':')[1].trim(); - if (value !== null && value !== undefined && value !== '') { - switch (key) { - case 'color': - classes += ` is-${value}`; - break; - case 'icon': - icon = ``; - break; - case 'title': - title = value; - break; - case 'size': - classes += ` is-${value}`; - break; - } - } - }); - if (icon !== '' || title !== '') { - header = ` -
- ${hexo.render.renderSync({text: icon + title, engine: 'markdown'})} -
- `; - } - - return ` -
- ${header} -
- ${hexo.render.renderSync({text: content, engine: 'md'})} -
-
- `; - }, { ends: true }); -}; diff --git a/scripts/tags/tabs.js b/scripts/tags/tabs.js deleted file mode 100644 index 226e2cd44..000000000 --- a/scripts/tags/tabs.js +++ /dev/null @@ -1,116 +0,0 @@ -/** - * Bulma Tabs Tag, see {@link https://bulma.io/documentation/components/tabs/}. - * - * The format of each item is: [content] . - * If each item's content is indented with four spaces or one tab, these indents will be ignored. - * - * @param {string} behavior The behavior of this tab, can not be set. Usable: centered, right, fullwidth. The - * default behavior is to display on the left. - * @param {string} size The size of this tab, can not be set. Usable: small, medium, large. The default - * size is between small and medium. - * @param {string} style The style of this tab, can not be set. Usable: boxed, toggle, toggle-rounded. - * - * @example - * {% tabs behavior:fullwidth size:small style:toggle-rounded %} - * This is info. - * This is hello. - * {% endmessage %} - */ -module.exports = function(hexo) { - hexo.extend.tag.register('tabs', (args, content) => { - let classes = ''; - - args.forEach(element => { - const key = element.split(':')[0].trim(); - const value = element.split(':')[1].trim(); - if (value !== null && value !== undefined && value !== '') { - switch (key) { - case 'behavior': - classes += ` is-${value}`; - break; - case 'size': - classes += ` is-${value}`; - break; - case 'style': - if (value === 'toggle-rounded') { - classes += ' is-toggle is-toggle-rounded'; - } else { - classes += ` is-${value}`; - } - break; - } - } - }); - - const blockRegExp = /([\s\S]*?)/g; - let match; - let tabsEl = ''; - let contentEl = ''; - - while ((match = blockRegExp.exec(content)) !== null) { - let active = ''; - let hidden = ' is-hidden'; - let icon = ''; - let contentString = match[5].replace(/^\n?|[ \n\t]*$/g, ''); - - if (match[1] === 'active') { - active = ' class="is-active"'; - hidden = ''; - } - if (match[3] !== undefined && match[3].substring(1) !== '') icon = ``; - if (contentString.match(/^ {4}|^\t{1}/gm) !== null && contentString.match(/^ {4}|^\t{1}/gm).length === contentString.split('\n').length) contentString = contentString.replace(/^ {4}|^\t{1}/g, '').replace(/\n {4}|\n\t{1}/g, '\n'); - - tabsEl += ` -
  • - ${hexo.render.renderSync({text: icon + match[4].substring(2, match[4].length - 1), engine: 'markdown'})} -
  • - `; - - contentEl += ` -
    - ${hexo.render.renderSync({text: contentString, engine: 'markdown'})} -
    - `; - } - - return ` -
    -
    -
      - ${tabsEl} -
    -
    -
    - ${contentEl} -
    -
    - `; - }, { ends: true }); - - hexo.extend.injector.register( - 'head_end', - ` - - ` - ); -};