Fixed some problems
parent
3a8d5fa6dc
commit
da442f6c4f
|
@ -13,13 +13,14 @@
|
||||||
* **You are in danger.**
|
* **You are in danger.**
|
||||||
* {% endmessage %}
|
* {% endmessage %}
|
||||||
*/
|
*/
|
||||||
module.exports = function (hexo) {
|
module.exports = function(hexo) {
|
||||||
hexo.extend.tag.register('message', function(args, content) {
|
hexo.extend.tag.register('message', function(args, content) {
|
||||||
let color = 'dark';
|
let color = 'dark';
|
||||||
let icon = '';
|
let icon = '';
|
||||||
let title = '';
|
let title = '';
|
||||||
let size = '';
|
let size = '';
|
||||||
let header = '';
|
let header = '';
|
||||||
|
|
||||||
args.forEach(element => {
|
args.forEach(element => {
|
||||||
const key = element.split(':')[0].trim();
|
const key = element.split(':')[0].trim();
|
||||||
const value = element.split(':')[1].trim();
|
const value = element.split(':')[1].trim();
|
||||||
|
@ -45,8 +46,9 @@
|
||||||
<div class="message-header">
|
<div class="message-header">
|
||||||
${hexo.render.renderSync({text: icon + title, engine: 'markdown'})}
|
${hexo.render.renderSync({text: icon + title, engine: 'markdown'})}
|
||||||
</div>
|
</div>
|
||||||
`
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `
|
return `
|
||||||
<article class="message is-${color}${size}">
|
<article class="message is-${color}${size}">
|
||||||
${header}
|
${header}
|
||||||
|
@ -56,4 +58,4 @@
|
||||||
</article>
|
</article>
|
||||||
`;
|
`;
|
||||||
}, { ends: true });
|
}, { ends: true });
|
||||||
}
|
};
|
||||||
|
|
|
@ -17,102 +17,107 @@
|
||||||
* <!-- activeitem hello 'Hello' -->This is hello.<!-- enditem -->
|
* <!-- activeitem hello 'Hello' -->This is hello.<!-- enditem -->
|
||||||
* {% endmessage %}
|
* {% endmessage %}
|
||||||
*/
|
*/
|
||||||
hexo.extend.tag.register('tabs', function(args, content) {
|
module.exports = function(hexo) {
|
||||||
let id = '';
|
hexo.extend.tag.register('tabs', function(args, content) {
|
||||||
let behavior = '';
|
let id = '';
|
||||||
let size = '';
|
let behavior = '';
|
||||||
let style = '';
|
let size = '';
|
||||||
let contentEl = content;
|
let style = '';
|
||||||
args.forEach(element => {
|
|
||||||
const key = element.split(':')[0].trim();
|
args.forEach(element => {
|
||||||
const 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 'id':
|
switch (key) {
|
||||||
id = value;
|
case 'id':
|
||||||
break;
|
id = value;
|
||||||
case 'behavior':
|
break;
|
||||||
behavior = ` is-${value}`;
|
case 'behavior':
|
||||||
break;
|
behavior = ` is-${value}`;
|
||||||
case 'size':
|
break;
|
||||||
size = ` is-${value}`;
|
case 'size':
|
||||||
break;
|
size = ` is-${value}`;
|
||||||
case 'style':
|
break;
|
||||||
if (value === 'toggle-rounded') {
|
case 'style':
|
||||||
style = ' is-toggle is-toggle-rounded';
|
if (value === 'toggle-rounded') {
|
||||||
} else {
|
style = ' is-toggle is-toggle-rounded';
|
||||||
style = ` is-${value}`;
|
} else {
|
||||||
}
|
style = ` is-${value}`;
|
||||||
break;
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const blockRegExp = /<!--\s*(active)?item( \w+)( \w+)?( '.*?')\s*-->([\s\S]*?)<!--\s*enditem\s*-->/g;
|
||||||
|
let match;
|
||||||
|
let tabsEl = '';
|
||||||
|
let contentEl = '';
|
||||||
|
|
||||||
|
while((match = blockRegExp.exec(content)) !== null) {
|
||||||
|
let active = '';
|
||||||
|
let hidden = ' is-hidden';
|
||||||
|
let icon = '';
|
||||||
|
var contentString = match[5].replace(/^\n?|[ \n\t]*$/g, '');
|
||||||
|
|
||||||
|
if (match[1] === 'active') {
|
||||||
|
active = ' class="is-active"';
|
||||||
|
hidden = '';
|
||||||
|
}
|
||||||
|
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 (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 += `
|
||||||
|
<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>
|
||||||
|
</li>
|
||||||
|
`;
|
||||||
|
|
||||||
|
contentEl += `
|
||||||
|
<div id="${match[2].substring(1)}" class="tab-content${hidden}">
|
||||||
|
${hexo.render.renderSync({text: contentString, engine: 'markdown'})}
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
const blockRegExp = /<!--\s*(active)?item( \w+)( \w+)?( '.*?')\s*-->([\s\S]*?)<!--\s*enditem\s*-->/g;
|
return `
|
||||||
let match;
|
|
||||||
let tabsEl = '';
|
|
||||||
let contentEl = '';
|
|
||||||
|
|
||||||
while((match = blockRegExp.exec(content)) !== null) {
|
|
||||||
let active = '';
|
|
||||||
let hidden = ' is-hidden';
|
|
||||||
let icon = '';
|
|
||||||
var contentString = match[5].replace(/^\n?|[ \n\t]*$/g, '');
|
|
||||||
if (match[1] === 'active') {
|
|
||||||
active = ' class="is-active"';
|
|
||||||
hidden = '';
|
|
||||||
}
|
|
||||||
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 (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 += `
|
|
||||||
<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>
|
|
||||||
</li>
|
|
||||||
`;
|
|
||||||
contentEl += `
|
|
||||||
<div id="${match[2].substring(1)}" class="tab-content${hidden}">
|
|
||||||
${hexo.render.renderSync({text: contentString, engine: 'markdown'})}
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return `
|
|
||||||
<div>
|
|
||||||
<div class="tabs my-3${behavior}${size}${style}">
|
|
||||||
<ul class="mx-0 my-0">
|
|
||||||
${tabsEl}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<div>
|
<div>
|
||||||
${contentEl}
|
<div class="tabs my-3${behavior}${size}${style}">
|
||||||
|
<ul class="mx-0 my-0">
|
||||||
|
${tabsEl}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
${contentEl}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
`;
|
||||||
`;
|
}, { ends: true });
|
||||||
}, { ends: true });
|
|
||||||
|
|
||||||
hexo.extend.injector.register(
|
hexo.extend.injector.register(
|
||||||
"head_end",
|
"head_end",
|
||||||
`
|
`
|
||||||
<script>
|
<script>
|
||||||
function switchTab(element) {
|
function switchTab(element) {
|
||||||
const id = element.parentElement.id;
|
const id = element.parentElement.id;
|
||||||
const tabElements = element.parentElement.parentElement.children;
|
const tabElements = element.parentElement.parentElement.children;
|
||||||
const contentElements = element.parentElement.parentElement.parentElement.parentElement.children[1].children;
|
const contentElements = element.parentElement.parentElement.parentElement.parentElement.children[1].children;
|
||||||
for (let i = 0; i < tabElements.length; i++) {
|
for (let i = 0; i < tabElements.length; i++) {
|
||||||
const $tab = tabElements[i];
|
const $tab = tabElements[i];
|
||||||
const $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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
</script>
|
||||||
</script>
|
`
|
||||||
`
|
);
|
||||||
);
|
};
|
||||||
|
|
Loading…
Reference in New Issue