[opt] tag-plugins

This commit is contained in:
xaoxuu 2022-12-11 18:05:21 +08:00
parent 7963ea7289
commit 40f6ee4fda
43 changed files with 1003 additions and 1011 deletions

View File

@ -1,33 +0,0 @@
/**
* ablock.js v1.0 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% ablock [color:color] [child:codeblock/tabs] title %}
* body
* {% endablock %}
*/
'use strict';
hexo.extend.tag.register('ablock', function(args, content) {
args = hexo.args.map(args, ['color', 'child'], ['title']);
const { title } = args;
if (args.color == null) {
args.color = hexo.theme.config.tag_plugins.note.default_color
}
var el = '';
// header
el += '<div class="tag-plugin note"';
el += ' ' + hexo.args.joinTags(args, ['color', 'child']).join(' ');
el += '>';
// title
if (title && title.length > 0) {
el += '<div class="title"><strong>' + title + '</strong></div>';
}
// content
el += '<div class="body">';
el += hexo.render.renderSync({text: content, engine: 'markdown'}).split('\n').join('');
el += '</div></div>';
return el;
}, {ends: true});

View File

@ -1,48 +0,0 @@
/**
* about.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% about [avatar:xxx] [height:80px] %}
* title / body
* {% endabout %}
*/
'use strict';
const url_for = require('hexo-util').url_for.bind(hexo);
hexo.extend.tag.register('about', function(args, content) {
args = hexo.args.map(args, ['avatar', 'height', 'border', 'back']);
var rows = hexo.render.renderSync({text: content, engine: 'markdown'}).split('\n');
var el = '';
// wrapper
el += '<div class="tag-plugin about">';
if (args.back) {
el += '<a class="nav-back cap" href="' + url_for(hexo.config.root) + '">';
el += '<svg aria-hidden="true" viewBox="0 0 16 16" fill="currentColor"><path fill-rule="evenodd" d="M7.78 12.53a.75.75 0 01-1.06 0L2.47 8.28a.75.75 0 010-1.06l4.25-4.25a.75.75 0 011.06 1.06L4.81 7h7.44a.75.75 0 010 1.5H4.81l2.97 2.97a.75.75 0 010 1.06z"></path></svg>';
el += '</a>';
}
// avatar
var avatar_url = args.avatar;
if (avatar_url) {
el += '<div class="about-header">';
el += '<div class="avatar">';
el += '<img src="' + avatar_url + '"';
if (args.border && args.border.length > 0) {
el += ' style="border-radius:' + args.border + '"';
}
if (args.height && args.height.length > 0) {
el += ' height="' + args.height + '"';
}
el += '/>';
el += '</div>';
el += '</div>';
}
// content
el += '<div class="about-body fs14">';
el += rows.join('');
el += '</div>';
el += '</div>';
return el;
}, {ends: true});

View File

@ -1,38 +0,0 @@
/**
* checkbox.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
* radio.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% checkbox [checked:false] [color:cyan] [symbol:plus/minus/times] text %}
* {% radio [checked:false] [color:cyan] text %}
*/
'use strict';
function layoutDiv(args, type) {
args = hexo.args.map(args, ['color', 'checked', 'symbol'], ['text']);
var el = '';
// div
el += '<div class="tag-plugin checkbox"';
el += ' ' + hexo.args.joinTags(args, ['color', 'symbol']).join(' ');
el += '>';
// input
el += '<input type="' + type + '"';
if (args.checked == 'true') {
el += ' checked="true"';
}
el += '/>';
// text
el += '<span>' + args.text + '</span>';
// div
el += '</div>';
return el;
}
hexo.extend.tag.register('checkbox', function(args) {
return layoutDiv(args, 'checkbox');
});
hexo.extend.tag.register('radio', function(args) {
return layoutDiv(args, 'radio');
});

View File

@ -1,40 +0,0 @@
/**
* emoji.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% emoji [source] name [height:1.75em] %}
*
*/
'use strict';
hexo.extend.tag.register('emoji', function(args) {
const config = hexo.theme.config.tag_plugins.emoji;
args = hexo.args.map(args, ['height'], ['source', 'name']);
var el = '';
if (args.source == undefined) {
return el;
}
el += '<span class="tag-plugin emoji">';
if (args.name == undefined) {
// 省略了 source
for (let id in config) {
if (config[id]) {
args.name = args.source;
args.source = id;
break;
}
}
}
if (config[args.source] && args.name) {
let url = config[args.source].replace('%s', args.name);
el += '<img no-lazy="" class="inline"';
el += ' src="' + url + '"';
if (args.height) {
el += ' style="height:' + args.height + '"';
}
el += '/>';
}
el += '</span>';
return el;
});

View File

@ -1,30 +0,0 @@
/**
* folding.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% folding [color:yellow] [child:codeblock] [open:false] title %}
* body
* {% endtable %}
*/
'use strict';
hexo.extend.tag.register('folding', function(args, content) {
args = hexo.args.map(args, ['color', 'child', 'open'], ['title']);
var el = '';
// header
el += '<details class="tag-plugin folding"';
el += ' ' + hexo.args.joinTags(args, ['color', 'child']).join(' ');
if (args.open && args.open == 'true') {
el += ' open';
}
el += '>';
// summary
el += '<summary><span>' + (args.title || '') + '</span></summary>';
// content
el += '<div class="body">';
el += hexo.render.renderSync({text: content, engine: 'markdown'}).split('\n').join('');
el += '</div></details>';
return el;
}, {ends: true});

View File

@ -1,66 +0,0 @@
/**
* frame.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% frame iphone11 [img:src] [video:url] [focus:top/bottom] [alt] %}
*/
'use strict';
hexo.extend.tag.register('frame', function(args) {
args = hexo.args.map(args, ['focus', 'img', 'video'], ['device', 'alt']);
const img = args.img || '';
const video = args.video || '';
const device = args.device || '';
const focus = args.focus || '';
const alt = args.alt || '';
if ((img.length == 0 && video.length == 0) || device.length == 0) {
return;
}
var el = '';
function imgTag(url, alt) {
let i = '';
i += '<img class="img" src="' + url + '"';
if (alt.length > 0) {
i += ' alt="' + alt + '"';
}
i += '/>';
return i;
}
if (video.length > 0) {
el += '<div class="tag-plugin video-wrap">';
el += '<div class="frame-wrap" id="' + device + '"';
if (focus.length > 0) {
el += 'focus="' + focus + '">';
} else {
el += '>';
}
el += '<video';
if (img.length > 0) {
el += ' poster="' + img + '"';
}
el += ' playsinline="" muted="" loop="" autoplay="" preload="metadata">';
el += '<source src="' + video + '" type="video/mp4">';
el += '</video>';
el += '<div class="frame"></div>';
el += '</div>';
el += '</div>';
} else if (img.length > 0) {
el += '<div class="tag-plugin img-wrap">';
el += '<div class="frame-wrap" id="' + device + '"';
if (focus.length > 0) {
el += 'focus="' + focus + '">';
} else {
el += '>';
}
el += imgTag(img, alt);
el += '<div class="frame"></div>';
el += '</div>';
if (alt.length > 0) {
el += '<span class="image-caption">' + alt + '</span>';
}
el += '</div>';
}
return el;
});

View File

@ -1,53 +0,0 @@
/**
* friends.js v2 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% friends [group] [repo:owner/repo] [api:http] %}
*/
'use strict';
hexo.extend.tag.register('friends', function(args) {
args = hexo.args.map(args, ['repo', 'api'], ['group']);
var links = hexo.locals.get('data').links;
if (links == undefined) {
links = {};
}
var api;
if (args.api) {
api = args.api;
} else if (args.repo) {
api = 'https://api.vlts.cc/output_data/v2/' + args.repo;
}
var el = '<div class="tag-plugin users-wrap">';
if (api) {
el += '<div class="stellar-friends-api"';
el += ' api="' + api + '"';
el += '>';
el += '<div class="group-body"></div>';
el += '</div>';
} else if (args.group) {
function cell(item) {
if (item.url && item.title) {
var cell = '<div class="user-card">';
cell += '<a class="card-link" target="_blank" rel="external nofollow noopener noreferrer" href="' + item.url + '">';
cell += '<img src="' + (item.avatar || hexo.theme.config.default.avatar) + '" onerror="javascript:this.removeAttribute(&quot;data-src&quot;);this.src=&quot;' + hexo.theme.config.default.avatar + '&quot;;"/>';
cell += '<div class="name"><span>' + item.title + '</span></div>';
cell += '</a></div>'
return cell;
} else {
return '';
}
}
el += '<div class="group-body">';
const items = links[args.group] || [];
items.forEach((item, i) => {
el += cell(item);
});
el += '</div>';
}
el += '</div>';
return el;
});

View File

@ -2,10 +2,36 @@
'use strict';
const postTabs = require('./lib/tabs')(hexo);
hexo.extend.tag.register('tabs', postTabs, true);
hexo.extend.tag.register('subtabs', postTabs, true);
hexo.extend.tag.register('subsubtabs', postTabs, true);
// container
hexo.extend.tag.register('tabs', require('./lib/tabs')(hexo), true)
hexo.extend.tag.register('ablock', require('./lib/ablock')(hexo), true)
hexo.extend.tag.register('about', require('./lib/about')(hexo), true)
hexo.extend.tag.register('folding', require('./lib/folding')(hexo), true)
hexo.extend.tag.register('folders', require('./lib/folders')(hexo), true)
hexo.extend.tag.register('grid', require('./lib/grid')(hexo), true)
hexo.extend.tag.register('swiper', require('./lib/swiper')(hexo), true)
const users = require('./lib/users')(hexo);
hexo.extend.tag.register('users', users);
// data
hexo.extend.tag.register('users', require('./lib/friends')(hexo))
hexo.extend.tag.register('friends', require('./lib/friends')(hexo))
hexo.extend.tag.register('sites', require('./lib/sites')(hexo))
hexo.extend.tag.register('ghcard', require('./lib/ghcard')(hexo))
hexo.extend.tag.register('toc', require('./lib/toc')(hexo))
hexo.extend.tag.register('timeline', require('./lib/timeline')(hexo), {ends: true})
// express
hexo.extend.tag.register('checkbox', require('./lib/checkbox')(hexo, 'checkbox'))
hexo.extend.tag.register('radio', require('./lib/checkbox')(hexo, 'radio'))
hexo.extend.tag.register('copy', require('./lib/copy')(hexo))
hexo.extend.tag.register('emoji', require('./lib/emoji')(hexo))
hexo.extend.tag.register('frame', require('./lib/frame')(hexo))
hexo.extend.tag.register('image', require('./lib/image')(hexo))
hexo.extend.tag.register('link', require('./lib/link')(hexo))
hexo.extend.tag.register('mark', require('./lib/mark')(hexo))
hexo.extend.tag.register('navbar', require('./lib/navbar')(hexo))
hexo.extend.tag.register('note', require('./lib/note')(hexo))
hexo.extend.tag.register('poetry', require('./lib/poetry')(hexo), true)
hexo.extend.tag.register('quot', require('./lib/quot')(hexo))
hexo.extend.tag.register('tag', require('./lib/tag')(hexo))
// others

View File

@ -5,40 +5,40 @@
* {% psw 这是密码 %}
*/
'use strict';
'use strict'
hexo.extend.tag.register('u', function(args) {
return `<u>${args.join(' ')}</u>`;
});
return `<u>${args.join(' ')}</u>`
})
hexo.extend.tag.register('emp', function(args) {
return `<emp>${args.join(' ')}</emp>`;
});
return `<emp>${args.join(' ')}</emp>`
})
hexo.extend.tag.register('wavy', function(args) {
return `<wavy>${args.join(' ')}</wavy>`;
});
return `<wavy>${args.join(' ')}</wavy>`
})
hexo.extend.tag.register('del', function(args) {
return `<del>${args.join(' ')}</del>`;
});
return `<del>${args.join(' ')}</del>`
})
hexo.extend.tag.register('kbd', function(args) {
return `<kbd>${args.join(' ')}</kbd>`;
});
return `<kbd>${args.join(' ')}</kbd>`
})
hexo.extend.tag.register('psw', function(args) {
return `<psw>${args.join(' ')}</psw>`;
});
return `<psw>${args.join(' ')}</psw>`
})
hexo.extend.tag.register('sup', function(args) {
args = hexo.args.map(args, ['color'], ['text']);
var el = '';
el += '<sup class="tag-plugin sup"' + ' ' + hexo.args.joinTags(args, ['color']).join(' ') + '>';
el += args.text;
el += '</sup>';
return el;
});
args = hexo.args.map(args, ['color'], ['text'])
var el = ''
el += '<sup class="tag-plugin sup"' + ' ' + hexo.args.joinTags(args, ['color']).join(' ') + '>'
el += args.text
el += '</sup>'
return el
})
hexo.extend.tag.register('sub', function(args) {
args = hexo.args.map(args, ['color'], ['text']);
var el = '';
el += '<sub class="tag-plugin sub"' + ' ' + hexo.args.joinTags(args, ['color']).join(' ') + '>';
el += args.text;
el += '</sub>';
return el;
});
args = hexo.args.map(args, ['color'], ['text'])
var el = ''
el += '<sub class="tag-plugin sub"' + ' ' + hexo.args.joinTags(args, ['color']).join(' ') + '>'
el += args.text
el += '</sub>'
return el
})

View File

@ -0,0 +1,33 @@
/**
* ablock.js v1.0 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% ablock [color:color] [child:codeblock/tabs] title %}
* body
* {% endablock %}
*/
'use strict';
module.exports = ctx => function(args, content) {
args = ctx.args.map(args, ['color', 'child'], ['title'])
const { title } = args
if (args.color == null) {
args.color = ctx.theme.config.tag_plugins.note.default_color
}
var el = ''
// header
el += '<div class="tag-plugin note"'
el += ' ' + ctx.args.joinTags(args, ['color', 'child']).join(' ')
el += '>'
// title
if (title && title.length > 0) {
el += '<div class="title"><strong>' + title + '</strong></div>'
}
// content
el += '<div class="body">'
el += ctx.render.renderSync({text: content, engine: 'markdown'}).split('\n').join('')
el += '</div></div>'
return el
}

48
scripts/tags/lib/about.js Normal file
View File

@ -0,0 +1,48 @@
/**
* about.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% about [avatar:xxx] [height:80px] %}
* title / body
* {% endabout %}
*/
'use strict';
module.exports = ctx => function(args, content) {
const url_for = require('hexo-util').url_for.bind(ctx)
args = ctx.args.map(args, ['avatar', 'height', 'border', 'back'])
var rows = ctx.render.renderSync({text: content, engine: 'markdown'}).split('\n')
var el = ''
// wrapper
el += '<div class="tag-plugin about">'
if (args.back) {
el += '<a class="nav-back cap" href="' + url_for(ctx.config.root) + '">'
el += '<svg aria-hidden="true" viewBox="0 0 16 16" fill="currentColor"><path fill-rule="evenodd" d="M7.78 12.53a.75.75 0 01-1.06 0L2.47 8.28a.75.75 0 010-1.06l4.25-4.25a.75.75 0 011.06 1.06L4.81 7h7.44a.75.75 0 010 1.5H4.81l2.97 2.97a.75.75 0 010 1.06z"></path></svg>'
el += '</a>'
}
// avatar
var avatar_url = args.avatar
if (avatar_url) {
el += '<div class="about-header">'
el += '<div class="avatar">'
el += '<img src="' + avatar_url + '"'
if (args.border && args.border.length > 0) {
el += ' style="border-radius:' + args.border + '"'
}
if (args.height && args.height.length > 0) {
el += ' height="' + args.height + '"'
}
el += '/>'
el += '</div>'
el += '</div>'
}
// content
el += '<div class="about-body fs14">'
el += rows.join('')
el += '</div>'
el += '</div>'
return el
}

View File

@ -0,0 +1,30 @@
/**
* checkbox.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
* radio.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% checkbox [checked:false] [color:cyan] [symbol:plus/minus/times] text %}
* {% radio [checked:false] [color:cyan] text %}
*/
'use strict'
module.exports = (ctx, type) => function(args) {
args = ctx.args.map(args, ['color', 'checked', 'symbol'], ['text'])
var el = ''
// div
el += '<div class="tag-plugin checkbox"'
el += ' ' + ctx.args.joinTags(args, ['color', 'symbol']).join(' ')
el += '>'
// input
el += '<input type="' + (type || 'checkbox') + '"'
if (args.checked == 'true') {
el += ' checked="true"'
}
el += '/>'
// text
el += '<span>' + args.text + '</span>'
// div
el += '</div>'
return el
}

View File

@ -7,43 +7,43 @@
*
*/
'use strict';
'use strict'
var copy_index = 0;
var copy_index = 0
hexo.extend.tag.register('copy', function(args) {
args = hexo.args.map(args, ['width', 'git'], ['text']);
module.exports = ctx => function(args) {
args = ctx.args.map(args, ['width', 'git'], ['text'])
if (args == undefined || args.text == undefined) {
return '';
return ''
}
var text = args.text;
var text = args.text
if (args.git) {
if (text.substr(0,1) == '/') {
text = text.substring(1);
text = text.substring(1)
}
if (args.git == 'ssh') {
text = 'git@github.com:' + text + '.git';
text = 'git@github.com:' + text + '.git'
} else if (args.git == 'gh') {
text = 'gh repo clone ' + text;
text = 'gh repo clone ' + text
} else {
text = 'https://github.com/' + text + '.git';
text = 'https://github.com/' + text + '.git'
}
}
const copy_id = 'copy_' + ++copy_index;
const copy_id = 'copy_' + ++copy_index
var el = '';
el += '<div class="tag-plugin copy"';
var el = ''
el += '<div class="tag-plugin copy"'
if (args.width) {
el += ' width="' + args.width + '"';
el += ' width="' + args.width + '"'
}
el += '>';
el += '<input class="copy-area" readonly id="' + copy_id + '"';
el += ' value="' + text + '">';
el += '<button class="copy-btn" onclick="util.copy(&quot;' + copy_id + '&quot;,&quot;Copied!&quot;)">';
el += '<svg class="icon copy-btn" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M5.75 1a.75.75 0 00-.75.75v3c0 .414.336.75.75.75h4.5a.75.75 0 00.75-.75v-3a.75.75 0 00-.75-.75h-4.5zm.75 3V2.5h3V4h-3zm-2.874-.467a.75.75 0 00-.752-1.298A1.75 1.75 0 002 3.75v9.5c0 .966.784 1.75 1.75 1.75h8.5A1.75 1.75 0 0014 13.25v-9.5a1.75 1.75 0 00-.874-1.515.75.75 0 10-.752 1.298.25.25 0 01.126.217v9.5a.25.25 0 01-.25.25h-8.5a.25.25 0 01-.25-.25v-9.5a.25.25 0 01.126-.217z"></path></svg>';
el += '</button>';
el += '>'
el += '<input class="copy-area" readonly id="' + copy_id + '"'
el += ' value="' + text + '">'
el += '<button class="copy-btn" onclick="util.copy(&quot' + copy_id + '&quot,&quotCopied!&quot)">'
el += '<svg class="icon copy-btn" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M5.75 1a.75.75 0 00-.75.75v3c0 .414.336.75.75.75h4.5a.75.75 0 00.75-.75v-3a.75.75 0 00-.75-.75h-4.5zm.75 3V2.5h3V4h-3zm-2.874-.467a.75.75 0 00-.752-1.298A1.75 1.75 0 002 3.75v9.5c0 .966.784 1.75 1.75 1.75h8.5A1.75 1.75 0 0014 13.25v-9.5a1.75 1.75 0 00-.874-1.515.75.75 0 10-.752 1.298.25.25 0 01.126.217v9.5a.25.25 0 01-.25.25h-8.5a.25.25 0 01-.25-.25v-9.5a.25.25 0 01.126-.217z"></path></svg>'
el += '</button>'
el += '</div>';
return el;
});
el += '</div>'
return el
}

40
scripts/tags/lib/emoji.js Normal file
View File

@ -0,0 +1,40 @@
/**
* emoji.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% emoji [source] name [height:1.75em] %}
*
*/
'use strict'
module.exports = ctx => function(args) {
const config = ctx.theme.config.tag_plugins.emoji
args = ctx.args.map(args, ['height'], ['source', 'name'])
var el = ''
if (args.source == undefined) {
return el
}
el += '<span class="tag-plugin emoji">'
if (args.name == undefined) {
// 省略了 source
for (let id in config) {
if (config[id]) {
args.name = args.source
args.source = id
break
}
}
}
if (config[args.source] && args.name) {
let url = config[args.source].replace('%s', args.name)
el += '<img no-lazy="" class="inline"'
el += ' src="' + url + '"'
if (args.height) {
el += ' style="height:' + args.height + '"'
}
el += '/>'
}
el += '</span>'
return el
}

View File

@ -10,44 +10,44 @@
* {% endtable %}
*/
'use strict';
'use strict'
hexo.extend.tag.register('folders', function(args, content) {
args = hexo.args.map(args, ['color']);
var el = '';
el += '<div class="tag-plugin folders"';
el += ' ' + hexo.args.joinTags(args, ['color']).join(' ');
el += '>';
module.exports = ctx => function(args, content) {
args = ctx.args.map(args, ['color'])
var el = ''
el += '<div class="tag-plugin folders"'
el += ' ' + ctx.args.joinTags(args, ['color']).join(' ')
el += '>'
var arr = content.split(/<!--\s*folder (.*?)\s*-->/g).filter(item => item.trim().length > 0)
if (arr.length > 0) {
var nodes = [];
var nodes = []
arr.forEach((item, i) => {
if (i % 2 == 0) {
nodes.push({
header: item
});
})
} else if (nodes.length > 0) {
var node = nodes[nodes.length-1];
var node = nodes[nodes.length-1]
if (node.body == undefined) {
node.body = item;
node.body = item
} else {
node.body += '\n' + item;
node.body += '\n' + item
}
}
});
})
nodes.forEach((node, i) => {
el += '<details class="folder" index="' + (i) + '">';
el += '<details class="folder" index="' + (i) + '">'
// summary
el += '<summary><span>' + (node.header || '') + '</span></summary>';
el += '<summary><span>' + (node.header || '') + '</span></summary>'
// content
el += '<div class="body">';
el += hexo.render.renderSync({text: (node.body || ''), engine: 'markdown'}).split('\n').join('');
el += '</div></details>';
});
el += '<div class="body">'
el += ctx.render.renderSync({text: (node.body || ''), engine: 'markdown'}).split('\n').join('')
el += '</div></details>'
})
}
el += '</div>';
el += '</div>'
return el;
}, {ends: true});
return el
}

View File

@ -0,0 +1,30 @@
/**
* folding.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% folding [color:yellow] [child:codeblock] [open:false] title %}
* body
* {% endtable %}
*/
'use strict'
module.exports = ctx => function(args, content) {
args = ctx.args.map(args, ['color', 'child', 'open'], ['title'])
var el = ''
// header
el += '<details class="tag-plugin folding"'
el += ' ' + ctx.args.joinTags(args, ['color', 'child']).join(' ')
if (args.open && args.open == 'true') {
el += ' open'
}
el += '>'
// summary
el += '<summary><span>' + (args.title || '') + '</span></summary>'
// content
el += '<div class="body">'
el += ctx.render.renderSync({text: content, engine: 'markdown'}).split('\n').join('')
el += '</div></details>'
return el
}

66
scripts/tags/lib/frame.js Normal file
View File

@ -0,0 +1,66 @@
/**
* frame.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% frame iphone11 [img:src] [video:url] [focus:top/bottom] [alt] %}
*/
'use strict'
module.exports = ctx => function(args) {
args = ctx.args.map(args, ['focus', 'img', 'video'], ['device', 'alt'])
const img = args.img || ''
const video = args.video || ''
const device = args.device || ''
const focus = args.focus || ''
const alt = args.alt || ''
if ((img.length == 0 && video.length == 0) || device.length == 0) {
return
}
var el = ''
function imgTag(url, alt) {
let i = ''
i += '<img class="img" src="' + url + '"'
if (alt.length > 0) {
i += ' alt="' + alt + '"'
}
i += '/>'
return i
}
if (video.length > 0) {
el += '<div class="tag-plugin video-wrap">'
el += '<div class="frame-wrap" id="' + device + '"'
if (focus.length > 0) {
el += 'focus="' + focus + '">'
} else {
el += '>'
}
el += '<video'
if (img.length > 0) {
el += ' poster="' + img + '"'
}
el += ' playsinline="" muted="" loop="" autoplay="" preload="metadata">'
el += '<source src="' + video + '" type="video/mp4">'
el += '</video>'
el += '<div class="frame"></div>'
el += '</div>'
el += '</div>'
} else if (img.length > 0) {
el += '<div class="tag-plugin img-wrap">'
el += '<div class="frame-wrap" id="' + device + '"'
if (focus.length > 0) {
el += 'focus="' + focus + '">'
} else {
el += '>'
}
el += imgTag(img, alt)
el += '<div class="frame"></div>'
el += '</div>'
if (alt.length > 0) {
el += '<span class="image-caption">' + alt + '</span>'
}
el += '</div>'
}
return el
}

View File

@ -0,0 +1,53 @@
/**
* friends.js v2 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% friends [group] [repo:owner/repo] [api:http] %}
*/
'use strict'
module.exports = ctx => function(args) {
args = ctx.args.map(args, ['repo', 'api'], ['group'])
var links = ctx.locals.get('data').links
if (links == undefined) {
links = {}
}
var api
if (args.api) {
api = args.api
} else if (args.repo) {
api = 'https://api.vlts.cc/output_data/v2/' + args.repo
}
var el = '<div class="tag-plugin users-wrap">'
if (api) {
el += '<div class="stellar-friends-api"'
el += ' api="' + api + '"'
el += '>'
el += '<div class="group-body"></div>'
el += '</div>'
} else if (args.group) {
function cell(item) {
if (item.url && item.title) {
var cell = '<div class="user-card">'
cell += '<a class="card-link" target="_blank" rel="external nofollow noopener noreferrer" href="' + item.url + '">'
cell += '<img src="' + (item.avatar || ctx.theme.config.default.avatar) + '" onerror="javascript:this.removeAttribute(&quotdata-src&quot)this.src=&quot' + ctx.theme.config.default.avatar + '&quot"/>'
cell += '<div class="name"><span>' + item.title + '</span></div>'
cell += '</a></div>'
return cell
} else {
return ''
}
}
el += '<div class="group-body">'
const items = links[args.group] || []
items.forEach((item, i) => {
el += cell(item)
})
el += '</div>'
}
el += '</div>'
return el
}

View File

@ -11,29 +11,29 @@
* API: https://github.com/anuraghazra/github-readme-stats
*/
'use strict';
'use strict'
hexo.extend.tag.register('ghcard', function(args) {
var params = ['show_owner', 'theme', 'title_color', 'text_color', 'icon_color', 'bg_color', 'hide_border', 'cache_seconds', 'locale'];
args = hexo.args.map(args, params, ['repo']);
const path = args.repo;
var el = '';
el += '<div class="tag-plugin ghcard">';
el += '<a class="ghcard" rel="external nofollow noopener noreferrer" href="https://github.com/' + path + '">';
let url = '';
module.exports = ctx => function(args) {
var params = ['show_owner', 'theme', 'title_color', 'text_color', 'icon_color', 'bg_color', 'hide_border', 'cache_seconds', 'locale']
args = ctx.args.map(args, params, ['repo'])
const path = args.repo
var el = ''
el += '<div class="tag-plugin ghcard">'
el += '<a class="ghcard" rel="external nofollow noopener noreferrer" href="https://github.com/' + path + '">'
let url = ''
if (path.includes('/')) {
// is repo
const ps = path.split('/');
url += 'https://github-readme-stats.xaoxuu.com/api/pin/?username=' + ps[0] + '&repo=' + ps[1];
const ps = path.split('/')
url += 'https://github-readme-stats.xaoxuu.com/api/pin/?username=' + ps[0] + '&repo=' + ps[1]
} else {
// is user
url += 'https://github-readme-stats.xaoxuu.com/api/?username=' + path;
url += 'https://github-readme-stats.xaoxuu.com/api/?username=' + path
}
url += '&' + hexo.args.joinURLParams(args, params);
url += '&' + ctx.args.joinURLParams(args, params)
if (!url.includes('&show_owner=')) {
url += '&show_owner=true';
url += '&show_owner=true'
}
el += '<img src="' + url + '"/>';
el += '</a></div>';
return el;
});
el += '<img src="' + url + '"/>'
el += '</a></div>'
return el
}

View File

@ -10,40 +10,40 @@
* {% endgrid %}
*/
'use strict';
'use strict'
hexo.extend.tag.register('grid', function(args, content) {
args = hexo.args.map(args, ['bg']);
var el = '';
el += '<div class="tag-plugin grid"';
el += ' ' + hexo.args.joinTags(args, ['bg']).join(' ');
el += '>';
module.exports = ctx => function(args, content) {
args = ctx.args.map(args, ['bg'])
var el = ''
el += '<div class="tag-plugin grid"'
el += ' ' + ctx.args.joinTags(args, ['bg']).join(' ')
el += '>'
var arr = content.split(/<!--\s*cell (.*?)\s*-->/g).filter(item => item.trim().length > 0)
if (arr.length > 0) {
var nodes = [];
var nodes = []
arr.forEach((item, i) => {
if (i % 2 == 0) {
nodes.push({
header: item
});
})
} else if (nodes.length > 0) {
var node = nodes[nodes.length-1];
var node = nodes[nodes.length-1]
if (node.body == undefined) {
node.body = item;
node.body = item
} else {
node.body += '\n' + item;
node.body += '\n' + item
}
}
});
})
nodes.forEach((node, i) => {
el += '<div class="cell" index="' + (i) + '">';
el += hexo.render.renderSync({text: (node.body || ''), engine: 'markdown'}).split('\n').join('');
el += '</div>';
});
el += '<div class="cell" index="' + (i) + '">'
el += ctx.render.renderSync({text: (node.body || ''), engine: 'markdown'}).split('\n').join('')
el += '</div>'
})
}
el += '</div>';
el += '</div>'
return el;
}, {ends: true});
return el
}

View File

@ -5,82 +5,82 @@
* {% image src [alt] [width:400px] [bg:#eee] [download:true/false/url] %}
*/
'use strict';
'use strict'
hexo.extend.tag.register('image', function(args) {
args = hexo.args.map(args, ['width', 'height', 'bg', 'download', 'padding', 'fancybox'], ['src', 'alt']);
var style = '';
module.exports = ctx => function(args) {
args = ctx.args.map(args, ['width', 'height', 'bg', 'download', 'padding', 'fancybox'], ['src', 'alt'])
var style = ''
if (args.width) {
style += 'width:' + args.width + ';';
style += 'width:' + args.width + ';'
}
if (args.height) {
style += 'height:' + args.height + ';';
style += 'height:' + args.height + ';'
}
// fancybox
var fancybox = false;
if (hexo.theme.config.plugins.fancybox && hexo.theme.config.plugins.fancybox.enable) {
var fancybox = false
if (ctx.theme.config.plugins.fancybox && ctx.theme.config.plugins.fancybox.enable) {
// 主题配置
if (hexo.theme.config.tag_plugins.image && hexo.theme.config.tag_plugins.image.fancybox) {
fancybox = hexo.theme.config.tag_plugins.image.fancybox;
if (ctx.theme.config.tag_plugins.image && ctx.theme.config.tag_plugins.image.fancybox) {
fancybox = ctx.theme.config.tag_plugins.image.fancybox
}
// 覆盖配置
if (args.fancybox && args.fancybox.length > 0) {
if (args.fancybox == 'true') {
fancybox = true;
fancybox = true
} else if (args.fancybox == 'false') {
fancybox = false;
fancybox = false
}
}
}
function img(src, alt, style) {
let img = '';
img += '<img src="' + src + '"';
let img = ''
img += '<img src="' + src + '"'
if (alt) {
img += ' alt="' + alt + '"';
img += ' alt="' + alt + '"'
}
if (fancybox) {
img += ' fancybox="true"';
img += ' fancybox="true"'
}
if (style.length > 0) {
img += ' style="' + style + '"';
img += ' style="' + style + '"'
}
img += '/>';
return img;
img += '/>'
return img
}
var el = '';
var el = ''
// wrap
el += '<div class="tag-plugin image">';
el += '<div class="tag-plugin image">'
// bg
el += '<div class="image-bg"';
el += '<div class="image-bg"'
if (args.bg || args.padding) {
el += ' style="';
el += ' style="'
if (args.bg && args.bg.length > 0) {
el += 'background:' + args.bg + ';';
el += 'background:' + args.bg + ';'
}
if (args.padding) {
el += 'padding:' + args.padding + ';';
el += 'padding:' + args.padding + ';'
}
el += '"';
el += '"'
}
el += '>';
el += img(args.src, args.alt, style);
el += '>'
el += img(args.src, args.alt, style)
if (args.download && args.download.length > 0) {
let href = args.download;
let href = args.download
if (args.download == 'true') {
href = args.src;
href = args.src
}
el += '<a class="image-download blur" style="opacity:0" href="' + href + '"><svg class="icon" style="width: 1em; height: 1em;vertical-align: middle;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3734"><path d="M561.00682908 685.55838913a111.03077546 111.03077546 0 0 1-106.8895062 0L256.23182837 487.72885783a55.96309219 55.96309219 0 0 1 79.13181253-79.18777574L450.70357448 523.88101491V181.55477937a55.96309219 55.96309219 0 0 1 111.92618438 0v344.06109173l117.07478902-117.07478901a55.96309219 55.96309219 0 0 1 79.13181252 79.18777574zM282.81429711 797.1487951h447.70473912a55.96309219 55.96309219 0 0 1 0 111.92618438H282.81429711a55.96309219 55.96309219 0 0 1 0-111.92618438z" p-id="3735"></path></svg></a>';
el += '<a class="image-download blur" style="opacity:0" href="' + href + '"><svg class="icon" style="width: 1em; height: 1em;vertical-align: middle;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3734"><path d="M561.00682908 685.55838913a111.03077546 111.03077546 0 0 1-106.8895062 0L256.23182837 487.72885783a55.96309219 55.96309219 0 0 1 79.13181253-79.18777574L450.70357448 523.88101491V181.55477937a55.96309219 55.96309219 0 0 1 111.92618438 0v344.06109173l117.07478902-117.07478901a55.96309219 55.96309219 0 0 1 79.13181252 79.18777574zM282.81429711 797.1487951h447.70473912a55.96309219 55.96309219 0 0 1 0 111.92618438H282.81429711a55.96309219 55.96309219 0 0 1 0-111.92618438z" p-id="3735"></path></svg></a>'
}
el += '</div>';
el += '</div>'
if (args.alt && args.alt.length > 0) {
el += '<div class="image-meta">';
el += '<span class="image-caption center">' + args.alt + '</span>';
el += '</div>';
el += '<div class="image-meta">'
el += '<span class="image-caption center">' + args.alt + '</span>'
el += '</div>'
}
el += '</div>';
return el;
});
el += '</div>'
return el
}

78
scripts/tags/lib/link.js Normal file
View File

@ -0,0 +1,78 @@
/**
* link.js v1.1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% link url [title] [desc:true/false] [icon:src] %}
*/
'use strict'
module.exports = ctx => function(args) {
const full_url_for = require('hexo-util').full_url_for.bind(ctx)
args = ctx.args.map(args, ['icon', 'desc'], ['url', 'title'])
var autofill = []
if (!args.title) {
autofill.push('title')
}
if (!args.icon) {
autofill.push('icon')
}
if (args.desc) {
autofill.push('desc')
}
var el = ''
el += '<div class="tag-plugin link dis-select">'
el += '<a class="link-card' + (args.desc ? ' rich' : ' plain') + '" title="' + (args.title || '') + '" href="' + args.url + '"'
if (args.url.includes('://')) {
el += ' target="_blank" rel="external nofollow noopener noreferrer"'
}
el += ' cardlink'
el += ' autofill="'
el += autofill.join(',')
el += '"'
el += '>'
function loadIcon() {
var el = ''
if (ctx.theme.config.plugins.lazyload && ctx.theme.config.plugins.lazyload.enable) {
el += '<div class="lazy img" data-bg="' + (args.icon || ctx.theme.config.default.link) + '"></div>'
} else {
el += '<div class="lazy img" style="background-image:url(&quot;' + (args.icon || ctx.theme.config.default.link) + '&quot;)"></div>'
}
return el
}
function loadTitle() {
return '<span class="title">' + (args.title || args.url) + '</span>'
}
function loadDesc() {
return '<span class="cap desc fs12"></span>'
}
function loadLink() {
return '<span class="cap link fs12">' + full_url_for(args.url) + '</span>'
}
if (args.desc) {
// top
el += '<div class="top">'
el += loadIcon() + loadLink()
el += '</div>'
// bottom
el += '<div class="bottom">'
el += loadTitle() + loadDesc()
el += '</div>'
} else {
// left
el += '<div class="left">'
el += loadTitle() + loadLink()
el += '</div>'
// right
el += '<div class="right">'
el += loadIcon()
el += '</div>'
}
// end
el += '</a></div>'
return el
}

23
scripts/tags/lib/mark.js Normal file
View File

@ -0,0 +1,23 @@
/**
* mark.js v1.0 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% mark text [color:color] %}
*
*/
'use strict'
module.exports = ctx => function(args) {
args = ctx.args.map(args, ['color'], ['text'])
if (args.color == null) {
args.color = ctx.theme.config.tag_plugins.mark.default_color
}
var el = ''
el += '<mark class="tag-plugin mark"'
el += ' ' + ctx.args.joinTags(args, ['color']).join(' ')
el += '>'
el += args.text
el += '</mark>'
return el
}

View File

@ -0,0 +1,57 @@
/**
* navbar.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% navbar [markdown link] ... %}
*
* example:
* {% navbar active:1 [Home](/) [About](/about/) [Comments](#comments) %}
*/
'use strict'
module.exports = ctx => function(args) {
if (args.length == 0) {
return
}
args = ctx.args.map(args, ['active'], ['links'])
if (args.links) {
args.links = args.links.split(' ')
}
var el = '<div class="tag-plugin navbar"><nav class="cap">'
function layoutItem(a, i) {
var text = ''
var href = ''
var el = '<a'
if ((i+1).toString() === args.active) {
el += ' class="active"'
}
if (a.includes('](')) {
// markdown
let tmp = a.split('](')
if (tmp.length > 1) {
text = tmp[0]
if (text.length > 1) {
text = text.substring(1, text.length)
}
href = tmp[1]
if (href.length > 1) {
href = href.substring(0, href.length-1)
}
el += ' href="' + href + '"'
}
} else {
el += ' href="#' + a + '"'
text = a
}
el += '>'
el += text
el += '</a>'
return el
}
(args.links || []).forEach((item, i) => {
el += layoutItem(item, i)
})
el += '</nav></div>'
return el
}

35
scripts/tags/lib/note.js Normal file
View File

@ -0,0 +1,35 @@
/**
* note.js v1.1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% note [color:color] [title] content %}
*/
'use strict'
module.exports = ctx => function(args) {
args = ctx.args.map(args, ['color'], ['title', 'content'])
if (args.content == undefined || args.content.length <= 0) {
args.content = args.title
args.title = ''
}
const { title } = args
if (args.color == null) {
args.color = ctx.theme.config.tag_plugins.note.default_color
}
var el = ''
// header
el += '<div class="tag-plugin note"'
el += ' ' + ctx.args.joinTags(args, ['color', 'child']).join(' ')
el += '>'
// title
if (title && title.length > 0) {
el += '<div class="title">' + title + '</div>'
}
// content
el += '<div class="body">'
el += ctx.render.renderSync({text: args.content, engine: 'markdown'}).split('\n').join('')
el += '</div></div>'
return el
}

View File

@ -0,0 +1,47 @@
/**
* poetry.js v1.1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* poetry:
* {% poetry [title] [author:作者] [date:日期] [footer:footer] %}
* body
* {% endpoetry %}
*
*/
'use strict'
module.exports = ctx => function(args, content) {
var el = ''
args = ctx.args.map(args, ['author', 'date', 'footer'], ['title'])
el += '<div class="tag-plugin poetry"'
el += '>'
el += '<div class="content">'
if (args.title) {
el += '<div class="title">'
el += args.title
el += '</div>'
}
if (args.author || args.date) {
el += '<div class="meta">'
if (args.author) {
el += '<span>' + args.author + '</span>'
}
if (args.date) {
el += '<span>' + args.date + '</span>'
}
el += '</div>'
}
el += '<div class="body">'
el += ctx.render.renderSync({text: content, engine: 'markdown'}).split('\n').join('')
el += '</div>'
if (args.footer) {
el += '<div class="footer">'
el += args.footer
el += '</div>'
}
el += '</div>'
el += '</div>'
return el
}

View File

@ -7,49 +7,49 @@
*
*/
'use strict';
'use strict'
hexo.extend.tag.register('quot', function(args) {
var el = '';
args = hexo.args.map(args, ['el', 'icon'], ['text']);
module.exports = ctx => function(args) {
var el = ''
args = ctx.args.map(args, ['el', 'icon'], ['text'])
if (!args.el) {
args.el = 'p';
args.el = 'p'
}
var type = '';
var type = ''
if (args.icon && args.icon != 'square' && args.icon != 'quotes') {
type = ' type="icon"';
type = ' type="icon"'
} else {
type = ' type="text"';
type = ' type="text"'
}
function content() {
if (!args.icon) {
return args.text;
return args.text
}
var el = '';
const cfg = hexo.theme.config.tag_plugins.quot[args.icon];
var el = ''
const cfg = ctx.theme.config.tag_plugins.quot[args.icon]
if (cfg && cfg.prefix) {
el += '<img class="icon prefix" src="' + cfg.prefix + '" />';
el += '<img class="icon prefix" src="' + cfg.prefix + '" />'
}
el += args.text;
el += args.text
if (cfg && cfg.suffix) {
el += '<img class="icon suffix" src="' + cfg.suffix + '" />';
el += '<img class="icon suffix" src="' + cfg.suffix + '" />'
}
return el;
return el
}
if (args.el.includes('h')) {
el += '<div' + ' class="tag-plugin quot">'
el += '<' + args.el + ' class="content" id="' + args.text + '"' + type + '>';
el += '<a href="#' + args.text + '" class="headerlink" title="' + args.text + '"></a>';
el += content();
el += '</' + args.el + '>';
el += '<' + args.el + ' class="content" id="' + args.text + '"' + type + '>'
el += '<a href="#' + args.text + '" class="headerlink" title="' + args.text + '"></a>'
el += content()
el += '</' + args.el + '>'
el += '</div>'
} else {
el += '<div' + ' class="tag-plugin quot">'
el += '<' + args.el + ' class="content"' + type + '>';
el += content();
el += '</' + args.el + '>';
el += '<' + args.el + ' class="content"' + type + '>'
el += content()
el += '</' + args.el + '>'
el += '</div>'
}
return el;
});
return el
}

57
scripts/tags/lib/sites.js Normal file
View File

@ -0,0 +1,57 @@
/**
* sites.js v2 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% sites [group] [repo:owner/repo] [api:http] %}
*/
'use strict'
module.exports = ctx => function(args) {
args = ctx.args.map(args, ['repo', 'api'], ['group'])
var links = ctx.locals.get('data').links
if (links == undefined) {
links = {}
}
var api
if (args.api) {
api = args.api
} else if (args.repo) {
api = 'https://api.vlts.cc/output_data/v2/' + args.repo
}
var el = '<div class="tag-plugin sites-wrap">'
if (api) {
el += '<div class="stellar-sites-api"'
el += ' api="' + api + '"'
el += '>'
el += '<div class="group-body"></div>'
el += '</div>'
} else if (args.group) {
function cell(item) {
if (item.url && item.title) {
var cell = '<div class="site-card">'
cell += '<a class="card-link" target="_blank" rel="external nofollow noopener noreferrer" href="' + item.url + '">'
cell += '<img src="' + (item.screenshot || ('https://screenshot-api.xaoxuu.com/api?url=' + item.url + '&width=1280&height=720')) + '" onerror="javascript:this.removeAttribute(&quot;data-src&quot;);this.src=&quot;' + ctx.theme.config.default.cover + '&quot;;"/>'
cell += '<div class="info">'
cell += '<img src="' + (item.avatar || ctx.theme.config.default.link) + '" onerror="javascript:this.removeAttribute(&quot;data-src&quot;);this.src=&quot;' + ctx.theme.config.default.link + '&quot;;"/>'
cell += '<span class="title">' + item.title + '</span>'
cell += '<span class="desc">' + (item.description || item.url) + '</span>'
cell += '</div>'
cell += '</a></div>'
return cell
} else {
return ''
}
}
el += '<div class="group-body">'
const items = links[args.group] || []
items.forEach((item, i) => {
el += cell(item)
})
el += '</div>'
}
el += '</div>'
return el
}

View File

@ -0,0 +1,38 @@
/**
* swiper.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% swiper %}
* ![img](src)
* {% endswiper %}
*/
'use strict'
module.exports = ctx => function(args, content) {
args = ctx.args.map(args, ['width'])
var el = ''
function slide() {
let imgs = ctx.render.renderSync({text: content, engine: 'markdown'})
imgs = imgs.match(/<img(.*?)src="(.*?)"(.*?)>/gi)
if (imgs && imgs.length > 0) {
imgs.forEach((img, i) => {
img = img.replace('<img src', '<img no-lazy src')
el += '<div class="swiper-slide">' + img + '</div>'
})
}
}
el += '<div class="tag-plugin swiper-container" id="swiper-api"'
if (args.width && args.width.length > 0) {
el += ' ' + ctx.args.joinTags(args, 'width').join(' ')
}
el += '>'
el += '<div class="swiper-wrapper">'
slide()
el += '</div>'
el += '<div class="swiper-pagination"></div>'
el += '<div class="swiper-button-prev blur"></div>'
el += '<div class="swiper-button-next blur"></div>'
el += '</div>'
return el
}

View File

@ -2,7 +2,7 @@
* tabs.js v2 | 基于NexT修改 https://theme-next.js.org/docs/tag-plugins/tabs
*/
'use strict';
'use strict'
var tab_index = 0

View File

@ -6,15 +6,15 @@
*
*/
'use strict';
'use strict'
const tag_colors = ['red', 'orange', 'yellow', 'green', 'cyan', 'blue', 'purple']
var tag_index = 0;
var tag_index = 0
hexo.extend.tag.register('tag', function(args) {
args = hexo.args.map(args, ['color'], ['text', 'href']);
module.exports = ctx => function(args) {
args = ctx.args.map(args, ['color'], ['text', 'href'])
if (args.color == null) {
const default_color = hexo.theme.config.tag_plugins.tag?.default_color
const default_color = ctx.theme.config.tag_plugins.tag?.default_color
if (default_color) {
args.color = default_color
} else {
@ -25,11 +25,11 @@ hexo.extend.tag.register('tag', function(args) {
}
}
}
var el = '';
el += '<a class="tag-plugin tag"';
el += ' ' + hexo.args.joinTags(args, ['color', 'href']).join(' ');
el += '>';
el += args.text;
el += '</a>';
return el;
});
var el = ''
el += '<a class="tag-plugin tag"'
el += ' ' + ctx.args.joinTags(args, ['color', 'href']).join(' ')
el += '>'
el += args.text
el += '</a>'
return el
}

View File

@ -0,0 +1,78 @@
/**
* timeline.js v2 | https://github.com/xaoxuu/hexo-theme-stellar/
*
* {% timeline %}
*
* <!-- node header1 -->
* what happened 1
*
* <!-- node header2 -->
* what happened 2
*
* {% endtimeline %}
*/
'use strict'
function layoutNodeTitle(ctx, content) {
var el = ''
el += '<div class="header">'
if (content && content.length > 0) {
el += ctx.render.renderSync({text: content, engine: 'markdown'}).split('\n').join('')
}
el += '</div>'
return el
}
function layoutNodeContent(ctx, content) {
var el = ''
el += '<div class="body fs14">'
if (content && content.length > 0) {
el += ctx.render.renderSync({text: content, engine: 'markdown'}).split('\n').join('')
}
el += '</div>'
return el
}
module.exports = ctx => function(args, content = '') {
args = ctx.args.map(args, ['api', 'user', 'type', 'limit', 'hide'])
var el = ''
if (!args.type) {
args.type = 'timeline'
}
if (args.api && args.api.length > 0) {
el += '<div class="tag-plugin timeline stellar-' + args.type + '-api"'
el += ' ' + ctx.args.joinTags(args, ['api', 'user', 'limit', 'hide']).join(' ')
el += '>'
} else {
el += '<div class="tag-plugin timeline">'
}
var arr = content.split(/<!--\s*node (.*?)\s*-->/g).filter(item => item.trim().length > 0)
if (arr.length > 0) {
var nodes = []
arr.forEach((item, i) => {
if (i % 2 == 0) {
nodes.push({
header: item
})
} else if (nodes.length > 0) {
var node = nodes[nodes.length-1]
if (node.body == undefined) {
node.body = item
} else {
node.body += '\n' + item
}
}
})
nodes.forEach((node, i) => {
el += '<div class="timenode" index="' + (i) + '">'
el += layoutNodeTitle(ctx, node.header)
el += layoutNodeContent(ctx, node.body)
el += '</div>'
})
}
el += '</div>'
return el
}

72
scripts/tags/lib/toc.js Normal file
View File

@ -0,0 +1,72 @@
/**
* toc.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% toc wiki:xxx [title] [open:true] [display:mobile] %}
*/
'use strict'
function layoutDocTree(pages) {
var el = ''
el += '<ul class="toc">'
pages.forEach((p, i) => {
el += '<li>'
el += '<a class="list-link" href="' + p.permalink + '">'
el += '<span>' + (p.title || p.seo_title) + '</span>'
el += '</a>'
el += '</li>'
})
el += '</ul>'
return el
}
module.exports = ctx => function(args) {
args = ctx.args.map(args, ['wiki', 'open', 'display'], ['title'])
var el = ''
el += '<div class="tag-plugin toc"'
el += ' ' + ctx.args.joinTags(args, ['display']).join(' ')
if (args.display === 'mobile') {
el += ' style="display:none"'
}
el += '>'
el += '<details class="toc"'
if (args.open != 'false') {
el += ' open'
}
el += '>'
el += '<summary>'
el += args.title || 'TOC'
el += '</summary>'
if (args.wiki) {
const proj = ctx.theme.config.wiki.projects[args.wiki]
if (proj == undefined) {
return ''
}
if (proj.sections && proj.sections.length > 1) {
el += '<div class="body fs14 multi">'
proj.sections.forEach((sec, i) => {
el += '<section>'
el += '<div class="header">'
el += sec.title
el += '</div>'
el += layoutDocTree(sec.pages)
el += '</section>'
})
el += '</div>'
} else {
el += '<div class="body fs14">'
el += '<div class="body">'
el += layoutDocTree(proj.pages)
el += '</div>'
el += '</div>'
}
}
el += '</details>'
// end
el += '</div>'
return el
}

View File

@ -1,22 +0,0 @@
/**
* users.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% users api:https://api.github.com/repos/xaoxuu/hexo-theme-stellar/contributors %}
*/
'use strict';
module.exports = ctx => function(args) {
args = ctx.args.map(args, ['api']);
var el = '<div class="tag-plugin users-wrap">';
el += '<div class="stellar-friends-api"';
el += ' api="' + args.api + '"';
el += '>';
el += '<div class="group-body"></div>';
el += '</div>';
el += '</div>';
return el;
};

View File

@ -1,79 +0,0 @@
/**
* link.js v1.1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% link url [title] [desc:true/false] [icon:src] %}
*/
'use strict';
const full_url_for = require('hexo-util').full_url_for.bind(hexo);
hexo.extend.tag.register('link', function(args) {
args = hexo.args.map(args, ['icon', 'desc'], ['url', 'title']);
var autofill = [];
if (!args.title) {
autofill.push('title');
}
if (!args.icon) {
autofill.push('icon');
}
if (args.desc) {
autofill.push('desc');
}
var el = '';
el += '<div class="tag-plugin link dis-select">';
el += '<a class="link-card' + (args.desc ? ' rich' : ' plain') + '" title="' + (args.title || '') + '" href="' + args.url + '"';
if (args.url.includes('://')) {
el += ' target="_blank" rel="external nofollow noopener noreferrer"';
}
el += ' cardlink';
el += ' autofill="';
el += autofill.join(',');
el += '"';
el += '>';
function loadIcon() {
var el = '';
if (hexo.theme.config.plugins.lazyload && hexo.theme.config.plugins.lazyload.enable) {
el += '<div class="lazy img" data-bg="' + (args.icon || hexo.theme.config.default.link) + '"></div>';
} else {
el += '<div class="lazy img" style="background-image:url(&quot;' + (args.icon || hexo.theme.config.default.link) + '&quot;)"></div>';
}
return el;
}
function loadTitle() {
return '<span class="title">' + (args.title || args.url) + '</span>';
}
function loadDesc() {
return '<span class="cap desc fs12"></span>';
}
function loadLink() {
return '<span class="cap link fs12">' + full_url_for(args.url) + '</span>';
}
if (args.desc) {
// top
el += '<div class="top">';
el += loadIcon() + loadLink();
el += '</div>';
// bottom
el += '<div class="bottom">';
el += loadTitle() + loadDesc();
el += '</div>';
} else {
// left
el += '<div class="left">';
el += loadTitle() + loadLink();
el += '</div>';
// right
el += '<div class="right">';
el += loadIcon();
el += '</div>';
}
// end
el += '</a></div>';
return el;
});

View File

@ -1,23 +0,0 @@
/**
* mark.js v1.0 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% mark text [color:color] %}
*
*/
'use strict';
hexo.extend.tag.register('mark', function(args) {
args = hexo.args.map(args, ['color'], ['text']);
if (args.color == null) {
args.color = hexo.theme.config.tag_plugins.mark.default_color
}
var el = '';
el += '<mark class="tag-plugin mark"';
el += ' ' + hexo.args.joinTags(args, ['color']).join(' ');
el += '>';
el += args.text;
el += '</mark>';
return el;
});

View File

@ -1,57 +0,0 @@
/**
* navbar.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% navbar [markdown link] ... %}
*
* example:
* {% navbar active:1 [Home](/) [About](/about/) [Comments](#comments) %}
*/
'use strict';
hexo.extend.tag.register('navbar', function(args) {
if (args.length == 0) {
return;
}
args = hexo.args.map(args, ['active'], ['links']);
if (args.links) {
args.links = args.links.split(' ');
}
var el = '<div class="tag-plugin navbar"><nav class="cap">';
function layoutItem(a, i) {
var text = '';
var href = '';
var el = '<a';
if ((i+1).toString() === args.active) {
el += ' class="active"';
}
if (a.includes('](')) {
// markdown
let tmp = a.split('](');
if (tmp.length > 1) {
text = tmp[0];
if (text.length > 1) {
text = text.substring(1, text.length);
}
href = tmp[1];
if (href.length > 1) {
href = href.substring(0, href.length-1);
}
el += ' href="' + href + '"';
}
} else {
el += ' href="#' + a + '"';
text = a;
}
el += '>';
el += text;
el += '</a>';
return el;
}
(args.links || []).forEach((item, i) => {
el += layoutItem(item, i);
});
el += '</nav></div>';
return el;
});

View File

@ -1,35 +0,0 @@
/**
* note.js v1.1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% note [color:color] [title] content %}
*/
'use strict';
hexo.extend.tag.register('note', function(args) {
args = hexo.args.map(args, ['color'], ['title', 'content']);
if (args.content == undefined || args.content.length <= 0) {
args.content = args.title;
args.title = '';
}
const { title } = args;
if (args.color == null) {
args.color = hexo.theme.config.tag_plugins.note.default_color
}
var el = '';
// header
el += '<div class="tag-plugin note"';
el += ' ' + hexo.args.joinTags(args, ['color', 'child']).join(' ');
el += '>';
// title
if (title && title.length > 0) {
el += '<div class="title">' + title + '</div>';
}
// content
el += '<div class="body">';
el += hexo.render.renderSync({text: args.content, engine: 'markdown'}).split('\n').join('');
el += '</div></div>';
return el;
});

View File

@ -1,47 +0,0 @@
/**
* poetry.js v1.1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* poetry:
* {% poetry [title] [author:作者] [date:日期] [footer:footer] %}
* body
* {% endpoetry %}
*
*/
'use strict';
hexo.extend.tag.register('poetry', function(args, content) {
var el = '';
args = hexo.args.map(args, ['author', 'date', 'footer'], ['title']);
el += '<div class="tag-plugin poetry"';
el += '>';
el += '<div class="content">'
if (args.title) {
el += '<div class="title">';
el += args.title;
el += '</div>';
}
if (args.author || args.date) {
el += '<div class="meta">';
if (args.author) {
el += '<span>' + args.author + '</span>';
}
if (args.date) {
el += '<span>' + args.date + '</span>';
}
el += '</div>';
}
el += '<div class="body">';
el += hexo.render.renderSync({text: content, engine: 'markdown'}).split('\n').join('');
el += '</div>';
if (args.footer) {
el += '<div class="footer">';
el += args.footer;
el += '</div>';
}
el += '</div>'
el += '</div>';
return el;
}, {ends: true});

View File

@ -1,57 +0,0 @@
/**
* sites.js v2 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% sites [group] [repo:owner/repo] [api:http] %}
*/
'use strict';
hexo.extend.tag.register('sites', function(args) {
args = hexo.args.map(args, ['repo', 'api'], ['group']);
var links = hexo.locals.get('data').links;
if (links == undefined) {
links = {};
}
var api;
if (args.api) {
api = args.api;
} else if (args.repo) {
api = 'https://api.vlts.cc/output_data/v2/' + args.repo;
}
var el = '<div class="tag-plugin sites-wrap">';
if (api) {
el += '<div class="stellar-sites-api"';
el += ' api="' + api + '"';
el += '>';
el += '<div class="group-body"></div>';
el += '</div>';
} else if (args.group) {
function cell(item) {
if (item.url && item.title) {
var cell = '<div class="site-card">';
cell += '<a class="card-link" target="_blank" rel="external nofollow noopener noreferrer" href="' + item.url + '">';
cell += '<img src="' + (item.screenshot || ('https://screenshot-api.xaoxuu.com/api?url=' + item.url + '&width=1280&height=720')) + '" onerror="javascript:this.removeAttribute(&quot;data-src&quot;);this.src=&quot;' + hexo.theme.config.default.cover + '&quot;;"/>';
cell += '<div class="info">';
cell += '<img src="' + (item.avatar || hexo.theme.config.default.link) + '" onerror="javascript:this.removeAttribute(&quot;data-src&quot;);this.src=&quot;' + hexo.theme.config.default.link + '&quot;;"/>';
cell += '<span class="title">' + item.title + '</span>';
cell += '<span class="desc">' + (item.description || item.url) + '</span>';
cell += '</div>';
cell += '</a></div>'
return cell;
} else {
return '';
}
}
el += '<div class="group-body">';
const items = links[args.group] || [];
items.forEach((item, i) => {
el += cell(item);
});
el += '</div>';
}
el += '</div>';
return el;
});

View File

@ -1,38 +0,0 @@
/**
* swiper.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% swiper %}
* ![img](src)
* {% endswiper %}
*/
'use strict';
hexo.extend.tag.register('swiper', function(args, content) {
args = hexo.args.map(args, ['width']);
var el = '';
function slide() {
let imgs = hexo.render.renderSync({text: content, engine: 'markdown'});
imgs = imgs.match(/<img(.*?)src="(.*?)"(.*?)>/gi);
if (imgs && imgs.length > 0) {
imgs.forEach((img, i) => {
img = img.replace('<img src', '<img no-lazy src');
el += '<div class="swiper-slide">' + img + '</div>';
});
}
}
el += '<div class="tag-plugin swiper-container" id="swiper-api"';
if (args.width && args.width.length > 0) {
el += ' ' + hexo.args.joinTags(args, 'width').join(' ');
}
el += '>';
el += '<div class="swiper-wrapper">';
slide();
el += '</div>';
el += '<div class="swiper-pagination"></div>';
el += '<div class="swiper-button-prev blur"></div>';
el += '<div class="swiper-button-next blur"></div>';
el += '</div>';
return el;
}, {ends: true});

View File

@ -1,81 +0,0 @@
/**
* timeline.js v2 | https://github.com/xaoxuu/hexo-theme-stellar/
*
* {% timeline %}
*
* <!-- node header1 -->
* what happened 1
*
* <!-- node header2 -->
* what happened 2
*
* {% endtimeline %}
*/
'use strict';
function layoutNodeTitle(content) {
var el = '';
el += '<div class="header">';
if (content && content.length > 0) {
el += hexo.render.renderSync({text: content, engine: 'markdown'}).split('\n').join('');
}
el += '</div>';
return el;
}
function layoutNodeContent(content) {
var el = '';
el += '<div class="body fs14">';
if (content && content.length > 0) {
el += hexo.render.renderSync({text: content, engine: 'markdown'}).split('\n').join('');
}
el += '</div>';
return el;
}
function postTimeline(args, content) {
args = hexo.args.map(args, ['api', 'user', 'type', 'limit', 'hide']);
var el = '';
if (!args.type) {
args.type = 'timeline';
}
if (args.api && args.api.length > 0) {
el += '<div class="tag-plugin timeline stellar-' + args.type + '-api"';
el += ' ' + hexo.args.joinTags(args, ['api', 'user', 'limit', 'hide']).join(' ');
el += '>';
} else {
el += '<div class="tag-plugin timeline">';
}
var arr = content.split(/<!--\s*node (.*?)\s*-->/g).filter(item => item.trim().length > 0)
if (arr.length > 0) {
var nodes = [];
arr.forEach((item, i) => {
if (i % 2 == 0) {
nodes.push({
header: item
});
} else if (nodes.length > 0) {
var node = nodes[nodes.length-1];
if (node.body == undefined) {
node.body = item;
} else {
node.body += '\n' + item;
}
}
});
nodes.forEach((node, i) => {
el += '<div class="timenode" index="' + (i) + '">';
el += layoutNodeTitle(node.header);
el += layoutNodeContent(node.body);
el += '</div>';
});
}
el += '</div>';
return el;
}
hexo.extend.tag.register('timeline', postTimeline, {ends: true});

View File

@ -1,72 +0,0 @@
/**
* toc.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% toc wiki:xxx [title] [open:true] [display:mobile] %}
*/
'use strict';
function layoutDocTree(pages) {
var el = '';
el += '<ul class="toc">';
pages.forEach((p, i) => {
el += '<li>';
el += '<a class="list-link" href="' + p.permalink + '">';
el += '<span>' + (p.title || p.seo_title) + '</span>';
el += '</a>';
el += '</li>';
});
el += '</ul>';
return el;
}
hexo.extend.tag.register('toc', function(args) {
args = hexo.args.map(args, ['wiki', 'open', 'display'], ['title']);
var el = '';
el += '<div class="tag-plugin toc"';
el += ' ' + hexo.args.joinTags(args, ['display']).join(' ');
if (args.display === 'mobile') {
el += ' style="display:none"';
}
el += '>';
el += '<details class="toc"';
if (args.open != 'false') {
el += ' open';
}
el += '>';
el += '<summary>';
el += args.title || 'TOC';
el += '</summary>';
if (args.wiki) {
const proj = hexo.theme.config.wiki.projects[args.wiki];
if (proj == undefined) {
return '';
}
if (proj.sections && proj.sections.length > 1) {
el += '<div class="body fs14 multi">';
proj.sections.forEach((sec, i) => {
el += '<section>';
el += '<div class="header">';
el += sec.title;
el += '</div>';
el += layoutDocTree(sec.pages);
el += '</section>';
});
el += '</div>';
} else {
el += '<div class="body fs14">';
el += '<div class="body">';
el += layoutDocTree(proj.pages);
el += '</div>';
el += '</div>';
}
}
el += '</details>';
// end
el += '</div>';
return el;
});