提交 992dbca6 编写于 作者: EvanOne(文一)'s avatar EvanOne(文一)

style: Format and optimize code

上级 63f19feb
......@@ -15,10 +15,12 @@ hexo.extend.filter.register('after_post_render', function (data) {
var url = require('url');
var config = this.config;
var siteHost = url.parse(config.url).hostname || config.url;
// Match only a tags that don't contain html children.
var regPureATag = /<a([^>]*)href="([^"]*)"([^>]*)>([^<]*)<\/a>/gim;
data.content = data.content.replace(
/(<a([^>]*)href="([^"]*)"([^>]*)>([^<]*)<\/a>)/gim,
function (match, all, attrBegin, href, attrEnd, html) {
regPureATag,
function (match, attrBegin, href, attrEnd, html) {
// Exit if the href attribute doesn't exists.
if (!href) {
return match;
......@@ -30,25 +32,6 @@ hexo.extend.filter.register('after_post_render', function (data) {
return match;
};
var attrOther = attrBegin + attrEnd;
var className = '';
attrOther.split(/\s/gim).forEach(attr => {
var nAttr = attr.replace(/["']*/gim, '');
var aKey = (nAttr.split('=')[0] || '').trim();
var aValue = (nAttr.split('=')[1] || '').trim();
if (aKey === 'class') {
className = aValue;
}
});
// Exit if the class name is in whitelist.
var whiteList = ['friends-plugin__item'];
if (className && whiteList.includes(className)) {
return match;
}
var fa_prefix = theme.fa_prefix || 'fa';
return (
'<span class="external-link">' +
......
......@@ -28,9 +28,11 @@ hexo.extend.filter.register('after_post_render', function (data) {
placeholder = loadingBlock;
}
var className = `lazyload lazyload-${phClassName}`;
return `
<img ${attrBegin} class="lazyload lazyload-${phClassName}"
src="${placeholder}" data-src="${src}" ${attrEnd}>`;
<img ${attrBegin} class="${className}"
src="${placeholder}" data-src="${src}" ${attrEnd}>
`;
}
);
}, 1);
......@@ -19,10 +19,10 @@ hexo.extend.filter.register('after_post_render', function (data) {
return match;
}
var newHtml = (html.replace(/<[^>]+>/gim, '') || '').trim();
var filterHtml = (html.replace(/<[^>]+>/gim, '') || '').trim();
return `
<h2 ${attrBegin} id="${id}" ${attrEnd}>
<span class="heading-link">${newHtml}</span>
<span class="heading-link">${filterHtml}</span>
</h2>
`;
}
......
......@@ -30,7 +30,10 @@ hexo.extend.filter.register('after_post_render', function (data) {
var w = size.split(MULTIPLY_SIGN)[0];
var h = size.split(MULTIPLY_SIGN)[1];
var style = '';
if (!w || !h) {
return;
}
if (w) {
style += `width: ${w}px;`;
}
......@@ -38,9 +41,7 @@ hexo.extend.filter.register('after_post_render', function (data) {
style += `height: ${h}px;`;
}
var attr1 = attrBegin.trim();
var attr2 = attrEnd.trim();
return `<img ${attr1} src="${src}" style="${style}" ${attr2}>`;
return `<img ${attrBegin} src="${src}" style="${style}" ${attrEnd}>`;
}
);
}, 0);
......@@ -4,7 +4,6 @@
hexo.extend.filter.register('after_generate', function () {
var theme = hexo.theme.config;
if (!theme.shake_file) {
return;
}
......
......@@ -3,14 +3,15 @@
'use strict';
function note(args, content) {
var args = args.join(' ');
return `<div class="note-plugin ${args}">
${hexo.render
.renderSync({ text: content, engine: 'markdown' })
.split('\n')
.join('')}
</div>`;
var noteClassName = args.join(' ');
return `
<div class="note-plugin ${noteClassName}">
${hexo.render
.renderSync({ text: content, engine: 'markdown' })
.split('\n')
.join('')}
</div>
`;
}
hexo.extend.tag.register('note', note, { ends: true });
......@@ -16,28 +16,27 @@ function table(args) {
}
});
return fs.readFile(path).then(function(datas) {
if (!datas) {
return fs.readFile(path).then(function(data) {
if (!data) {
hexo.log.warn('Include file empty.');
return;
}
}
var datas = JSON.parse(datas);
var tableData = JSON.parse(data);
var result = '<table class="table-plugin"><thead><tr>';
headers.forEach(header => {
result += `<th>${header}</th>`;
});
headers.forEach(header => (result += `<th>${header}</th>`));
result += '</tr></thead><tbody>';
datas.forEach(data => {
tableData.forEach(item => {
result += '<tr style="text-align: center;">';
for (const key in data) {
if (data.hasOwnProperty(key)) {
const value = data[key];
result += `<td>${value}</td>`
for (var key in item) {
if (item.hasOwnProperty(key)) {
var value = item[key];
result += `<td>${value}</td>`;
}
}
result += '</tr>';
});
result += '</tbody></table>';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册