Fixed some problems

pull/1026/head
HMLTFan 2022-01-30 12:42:38 +08:00
parent ec1d2c7923
commit 3a8d5fa6dc
3 changed files with 178 additions and 174 deletions

View File

@ -12,4 +12,6 @@ module.exports = hexo => {
require('hexo-component-inferno/lib/hexo/helper/cdn')(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/helper/page')(hexo);
require('hexo-component-inferno/lib/core/view').init(hexo); require('hexo-component-inferno/lib/core/view').init(hexo);
require('./../scripts/tags/message')(hexo);
require('./../scripts/tags/tabs')(hexo);
}; };

View File

@ -13,45 +13,47 @@
* **You are in danger.** * **You are in danger.**
* {% endmessage %} * {% endmessage %}
*/ */
hexo.extend.tag.register('message', function(args, content) { module.exports = function (hexo) {
var color = 'dark'; hexo.extend.tag.register('message', function(args, content) {
var icon = ''; let color = 'dark';
var title = ''; let icon = '';
var size = ''; let title = '';
var header = ''; let size = '';
args.forEach(element => { let header = '';
var key = element.split(':')[0].trim(); args.forEach(element => {
var value = element.split(':')[1].trim(); const key = element.split(':')[0].trim();
if (value != null && value != undefined && value != '') { const value = element.split(':')[1].trim();
switch (key) { if (value !== null && value !== undefined && value !== '') {
case 'color': switch (key) {
color = value; case 'color':
break; color = value;
case 'icon': break;
icon = `<i class="fas fa-${value} mr-2"></i>`; case 'icon':
break; icon = `<i class="fas fa-${value} mr-2"></i>`;
case 'title': break;
title = value; case 'title':
break; title = value;
case 'size': break;
size = ` is-${value}`; case 'size':
break; size = ` is-${value}`;
break;
}
} }
});
if (icon !== '' || title !== '') {
header = `
<div class="message-header">
${hexo.render.renderSync({text: icon + title, engine: 'markdown'})}
</div>
`
} }
}); return `
if (icon != '' || title != '') { <article class="message is-${color}${size}">
header = ` ${header}
<div class="message-header"> <div class="message-body">
${hexo.render.renderSync({text: icon + title, engine: 'markdown'})} ${hexo.render.renderSync({text: content, engine: 'md'})}
</div> </div>
` </article>
} `;
return ` }, { ends: true });
<article class="message is-${color}${size}"> }
${header}
<div class="message-body">
${hexo.render.renderSync({text: content, engine: 'md'})}
</div>
</article>
`;
}, { ends: true });

View File

@ -18,15 +18,15 @@
* {% endmessage %} * {% endmessage %}
*/ */
hexo.extend.tag.register('tabs', function(args, content) { hexo.extend.tag.register('tabs', function(args, content) {
var id = ''; let id = '';
var behavior = ''; let behavior = '';
var size = ''; let size = '';
var style = ''; let style = '';
var contentEl = content; let contentEl = content;
args.forEach(element => { args.forEach(element => {
var key = element.split(':')[0].trim(); const key = element.split(':')[0].trim();
var value = element.split(':')[1].trim(); const value = element.split(':')[1].trim();
if (value != null && value != undefined && value != '') { if (value !== null && value !== undefined && value !== '') {
switch (key) { switch (key) {
case 'id': case 'id':
id = value; id = value;
@ -38,7 +38,7 @@
size = ` is-${value}`; size = ` is-${value}`;
break; break;
case 'style': case 'style':
if (value == 'toggle-rounded') { if (value === 'toggle-rounded') {
style = ' is-toggle is-toggle-rounded'; style = ' is-toggle is-toggle-rounded';
} else { } else {
style = ` is-${value}`; style = ` is-${value}`;
@ -48,22 +48,22 @@
} }
}); });
var blockRegExp = /<!--\s*(active)?item( \w+)( \w+)?( '.*?')\s*-->([\s\S]*?)<!--\s*enditem\s*-->/g; const blockRegExp = /<!--\s*(active)?item( \w+)( \w+)?( '.*?')\s*-->([\s\S]*?)<!--\s*enditem\s*-->/g;
var match; let match;
var tabsEl = ''; let tabsEl = '';
var contentEl = ''; let contentEl = '';
while((match = blockRegExp.exec(content)) !== null) { while((match = blockRegExp.exec(content)) !== null) {
var active = ''; let active = '';
var hidden = ' is-hidden'; let hidden = ' is-hidden';
if (match[1] != undefined) { let icon = '';
var contentString = match[5].replace(/^\n?|[ \n\t]*$/g, '');
if (match[1] === 'active') {
active = ' class="is-active"'; active = ' class="is-active"';
hidden = ''; hidden = '';
} }
var icon = ''; if (match[3] === 'active' && match[3].substring(1) !== '') icon = `<span class="icon is-small"><i class="fas fa-${match[3].substring(1)}" aria-hidden="true"></i></span>`;
if (match[3] != undefined && match[3].substring(1) != '') icon = `<span class="icon is-small"><i class="fas fa-${match[3].substring(1)}" aria-hidden="true"></i></span>`; 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');
var contentString = match[5].replace(/^\n?|[ \n\t]*$/g, '');
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 += ` tabsEl += `
<li id="${match[2].substring(1)}"${active}"> <li id="${match[2].substring(1)}"${active}">
<a onclick="switchTab(this)">${hexo.render.renderSync({text: icon + match[4].substring(2, match[4].length - 1), engine: 'markdown'})}</a> <a onclick="switchTab(this)">${hexo.render.renderSync({text: icon + match[4].substring(2, match[4].length - 1), engine: 'markdown'})}</a>
@ -95,18 +95,18 @@ hexo.extend.injector.register(
` `
<script> <script>
function switchTab(element) { function switchTab(element) {
var id = element.parentElement.id; const id = element.parentElement.id;
var tabElements = element.parentElement.parentElement.children; const tabElements = element.parentElement.parentElement.children;
var contentElements = element.parentElement.parentElement.parentElement.parentElement.children[1].children; const contentElements = element.parentElement.parentElement.parentElement.parentElement.children[1].children;
for (var i = 0; i < tabElements.length; i++) { for (let i = 0; i < tabElements.length; i++) {
var $tab = tabElements[i]; const $tab = tabElements[i];
var $content = contentElements[i]; const $content = contentElements[i];
if ($tab.id == id) { if ($tab.id === id) {
$tab.classList.add('is-active'); $tab.classList.add('is-active');
} else { } else {
$tab.classList.remove('is-active'); $tab.classList.remove('is-active');
} }
if ($content.id == id) { if ($content.id === id) {
$content.classList.remove('is-hidden'); $content.classList.remove('is-hidden');
} else { } else {
$content.classList.add('is-hidden'); $content.classList.add('is-hidden');