This commit is contained in:
xaoxuu 2021-03-01 21:06:59 +08:00
parent a8649e04ff
commit 24ce3ed02c
19 changed files with 115 additions and 134 deletions

View File

@ -5,6 +5,7 @@
hexo.on('generateBefore', () => {
// Merge config.
require('./lib/config')(hexo);
require('./lib/utils')(hexo);
});
hexo.on('ready', () => {

View File

@ -6,7 +6,7 @@
'use strict';
module.exports = hexo => {
const { cache, language_switcher } = hexo.theme.config;
const warning = function(...args) {
hexo.log.warn(`Since ${args[0]} is turned on, the ${args[1]} is disabled to avoid potential hazards.`);

View File

@ -0,0 +1,73 @@
/**
* utils.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
*/
'use strict';
module.exports = hexo => {
hexo.args = {
map: (args, keys, others) => {
if (Array.isArray(args) == false) {
return args;
}
var map = {others: Array()};
args.forEach((arg, i) => {
let kv = arg.trim();
if (kv.includes('://') && kv.split(':').length == 2) {
// 纯 url
map.others.push(kv);
} else {
kv = kv.split(':');
if (kv.length > 1) {
if (keys.includes(kv[0]) == true) {
map[kv.shift()] = kv.join(':');
} else {
map.others.push(kv.join(':'));
}
} else if (kv.length == 1) {
map.others.push(kv[0]);
}
}
});
// 解析不带 key 的参数
if (others && others.length > 0 && map.others.length > 0) {
if (Array.isArray(others) == false) {
others = [others];
}
others.forEach((arg, i) => {
map[arg] = map.others.shift();
});
// 最后一段合并到最后一个参数中
if (map.others.length > 0) {
map[others[others.length-1]] += ' ' + map.others.join(' ');
map.others = [];
}
}
return map;
},
joinTags: (args, keys) => {
if (Array.isArray(keys) == false) {
keys = [keys];
}
var ret = [];
keys.forEach((key, i) => {
if (args[key] && args[key].length > 0) {
ret.push(key + '="' + args[key] + '"');
}
});
return ret;
},
joinURLParams: (args, keys) => {
if (Array.isArray(keys) == false) {
keys = [keys];
}
var ret = [];
keys.forEach((key, i) => {
if (args[key] && args[key].length > 0) {
ret.push(key + '=' + args[key]);
}
});
return ret.join('&');
}
};
};

View File

@ -1,7 +1,7 @@
/**
* about.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
*
* {% about [avatar:xxx] [height:80px] %}
* title / body
* {% endabout %}
@ -9,10 +9,8 @@
'use strict';
const { ArgsMap } = require('./utils');
hexo.extend.tag.register('about', function(args, content) {
args = ArgsMap(args, ['avatar', 'height']);
args = hexo.args.map(args, ['avatar', 'height']);
var rows = hexo.render.renderSync({text: content, engine: 'markdown'}).split('\n');
var el = '';
// wrapper
@ -33,14 +31,14 @@ hexo.extend.tag.register('about', function(args, content) {
el += rows.shift();
// el += '</div>';
}
el += '</div>';
// content
el += '<div class="about-body">';
el += rows.join('');
el += '</div>';
el += '</div>';
return el;
}, {ends: true});

View File

@ -2,21 +2,19 @@
* 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';
const { ArgsMap, ArgsJoinTags } = require('./utils');
function layoutDiv(args, type) {
args = ArgsMap(args, ['color', 'checked', 'symbol'], ['text']);
args = hexo.args.map(args, ['color', 'checked', 'symbol'], ['text']);
var el = '';
// div
el += '<div class="tag-plugin checkbox"';
el += ' ' + ArgsJoinTags(args, ['color', 'symbol']).join(' ');
el += ' ' + hexo.args.joinTags(args, ['color', 'symbol']).join(' ');
el += '>';
// input
el += '<input type="' + type + '"';

View File

@ -9,10 +9,8 @@
'use strict';
const { ArgsMap } = require('./utils');
hexo.extend.tag.register('copy', function(args) {
args = ArgsMap(args, ['width', 'git'], ['text']);
args = hexo.args.map(args, ['width', 'git'], ['text']);
if (args == undefined || args.text == undefined) {
return '';
}

View File

@ -1,7 +1,7 @@
/**
* folding.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
*
* {% folding [color:yellow] [codeblock:false] [open:false] title %}
* body
* {% endtable %}
@ -9,14 +9,12 @@
'use strict';
const { ArgsMap, ArgsJoinTags } = require('./utils');
hexo.extend.tag.register('folding', function(args, content) {
args = ArgsMap(args, ['color', 'codeblock', 'open'], ['title']);
args = hexo.args.map(args, ['color', 'codeblock', 'open'], ['title']);
var el = '';
// header
el += '<details class="tag-plugin"'
el += ' ' + ArgsJoinTags(args, ['color', 'codeblock']).join(' ');
el += ' ' + hexo.args.joinTags(args, ['color', 'codeblock']).join(' ');
if (args.open && args.open == 'true') {
el += ' open';
}

View File

@ -7,10 +7,8 @@
'use strict';
const { ArgsMap } = require('./utils');
hexo.extend.tag.register('frame', function(args) {
args = ArgsMap(args, ['focus', 'img', 'video'], ['device', 'alt']);
args = hexo.args.map(args, ['focus', 'img', 'video'], ['device', 'alt']);
const img = args.img || '';
const video = args.video || '';
const device = args.device || '';

View File

@ -1,16 +1,14 @@
/**
* friends.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
*
* {% friends [style:rect] [group:name] %}
*/
'use strict';
const { ArgsMap } = require('./utils');
hexo.extend.tag.register('friends', function(args) {
args = ArgsMap(args, ['style', 'group']);
args = hexo.args.map(args, ['style', 'group']);
var friends = hexo.locals.get('data').friends;
if (friends == undefined) {
return;

View File

@ -1,23 +1,21 @@
/**
* friends.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
*
* {% ghcard user/repo [theme:xxx] %} or {% ghcard user %}
*
*
* example:
* {% ghcard xaoxuu %}
* {% ghcard xaoxuu/hexo-theme-stellar %}
*
*
* API: https://github.com/anuraghazra/github-readme-stats
*/
'use strict';
const { ArgsMap, ArgsJoinURLParams } = require('./utils');
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 = ArgsMap(args, params, ['repo']);
args = hexo.args.map(args, params, ['repo']);
const path = args.repo;
var el = '';
el += '<div class="tag-plugin ghcard">';
@ -31,7 +29,7 @@ hexo.extend.tag.register('ghcard', function(args) {
// is user
url += 'https://github-readme-stats.vercel.app/api/?username=' + path;
}
url += '&' + ArgsJoinURLParams(args, params);
url += '&' + hexo.args.joinURLParams(args, params);
if (!url.includes('&show_owner=')) {
url += '&show_owner=true';
}

View File

@ -7,10 +7,8 @@
'use strict';
const { ArgsMap } = require('./utils');
hexo.extend.tag.register('image', function(args) {
args = ArgsMap(args, ['width', 'height', 'bg', 'download', 'padding'], ['src', 'alt']);
args = hexo.args.map(args, ['width', 'height', 'bg', 'download', 'padding'], ['src', 'alt']);
var style = '';
if (args.width) {
style += 'width:' + args.width + ';';

View File

@ -1,19 +1,17 @@
/**
* issues.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
*
* {% issues [sites/timeline/friends] api:xxx [group:key=value1,value2,value3] %}
*
*
* example:
* {% issues sites api:https://api.github.com/repos/volantis-x/examples/issues?sort=updated&state=open&page=1&per_page=100 group:version=版本:^4.0,版本:^3.0,版本:^2.0 %}
*/
'use strict';
const { ArgsMap } = require('./utils');
hexo.extend.tag.register('issues', function(args) {
args = ArgsMap(args, ['api', 'group'], ['type']);
args = hexo.args.map(args, ['api', 'group'], ['type']);
// 所有支持的参数
let type = args.type || '';
let api = args.api || '';

View File

@ -7,14 +7,16 @@
'use strict';
const { ArgsMap } = require('./utils');
hexo.extend.tag.register('link', function(args) {
args = ArgsMap(args, ['img'], ['url', 'title', 'description']);
args = hexo.args.map(args, ['img'], ['url', 'title', 'description']);
var el = '';
el += '<div class="tag-plugin tag link">';
el += '<a class="link-card" title="' + args.title + '" href="' + args.url + '">';
el += '<a class="link-card" title="' + args.title + '" href="' + args.url + '"';
if (args.url.includes('://')) {
el += ' target="_blank" rel="external nofollow noopener noreferrer"';
}
el += '>';
// left
el += '<div class="left">';
el += '<span class="title">' + args.title + '</span><span class="url">' + (args.description || args.url) + '</span>';

View File

@ -1,10 +1,10 @@
/**
* note.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
*
* note:
* {% note [color:color] [title] content %}
*
*
* noteblock:
* {% noteblock [color:color] title %}
* markdown content
@ -13,8 +13,6 @@
'use strict';
const { ArgsMap } = require('./utils');
function outputNoteBlock(color, title, content) {
var el = '';
const defaultColor = hexo.theme.config.tag_plugins.note.default_color;
@ -40,7 +38,7 @@ function outputNoteBlock(color, title, content) {
}
hexo.extend.tag.register('note', function(args) {
args = ArgsMap(args, ['color'], ['title', 'content']);
args = hexo.args.map(args, ['color'], ['title', 'content']);
if (args.content) {
return outputNoteBlock(args.color, args.title, args.content);
} else {
@ -49,6 +47,6 @@ hexo.extend.tag.register('note', function(args) {
});
hexo.extend.tag.register('noteblock', function(args, content) {
args = ArgsMap(args, ['color'], ['title']);
args = hexo.args.map(args, ['color'], ['title']);
return outputNoteBlock(args.color, args.title, content);
}, {ends: true});

View File

@ -9,10 +9,8 @@
'use strict';
const { ArgsMap, ArgsJoinTags } = require('./utils');
hexo.extend.tag.register('swiper', function(args, content) {
args = ArgsMap(args, ['width']);
args = hexo.args.map(args, ['width']);
var el = '';
function slide() {
let imgs = hexo.render.renderSync({text: content, engine: 'markdown'});
@ -26,7 +24,7 @@ hexo.extend.tag.register('swiper', function(args, content) {
}
el += '<div class="tag-plugin swiper-container" id="swiper-api"';
if (args.width && args.width.length > 0) {
el += ' ' + ArgsJoinTags(args, 'width').join(' ');
el += ' ' + hexo.args.joinTags(args, 'width').join(' ');
}
el += '>';
el += '<div class="swiper-wrapper">';

View File

@ -16,10 +16,8 @@
'use strict';
const { ArgsMap, ArgsJoinTags } = require('./utils');
function postTimeline(args, content) {
args = ArgsMap(args, ['order']);
args = hexo.args.map(args, ['order']);
const newerIcon = '<svg class="icon top" width="1em" height="1em" viewBox="0 0 14 14" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M7,0 C3.13425,0 0,3.13425 0,7 C0,10.86575 3.13425,14 7,14 C10.86575,14 14,10.86575 14,7 C14,3.13425 10.86575,0 7,0 Z M7,12.25 C4.104625,12.25 1.75,9.89449999 1.75,7 C1.75,4.10550001 4.104625,1.75 7,1.75 C9.895375,1.75 12.25,4.10550001 12.25,7 C12.25,9.89449999 9.895375,12.25 7,12.25 Z M8.75875001,7 L7.43750001,7 C7.19600001,7 7.00000002,6.804 7.00000002,6.56250001 L7.00000002,5.24125001 C7.00000002,4.76262501 6.61237501,4.37500001 6.13375002,4.37500001 L6.11625001,4.37500001 C5.63762502,4.37500001 5.25000001,4.76262501 5.25000001,5.24125001 L5.25000001,7.88375 C5.25000001,8.362375 5.63762502,8.75 6.11625001,8.75 L8.75875001,8.75 C9.237375,8.75 9.62500001,8.362375 9.62500001,7.88375 L9.62500001,7.86625 C9.62500001,7.387625 9.237375,7 8.75875001,7 L8.75875001,7 Z" id="top"></path></svg>';

View File

@ -1,72 +0,0 @@
/**
* folding.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
*/
'use strict';
module.exports = {
ArgsMap(args, keys, others) {
if (Array.isArray(args) == false) {
return args;
}
var map = {others: Array()};
args.forEach((arg, i) => {
let kv = arg.trim();
if (kv.includes('://') && kv.split(':').length == 2) {
// 纯 url
map.others.push(kv);
} else {
kv = kv.split(':');
if (kv.length > 1) {
if (keys.includes(kv[0]) == true) {
map[kv.shift()] = kv.join(':');
} else {
map.others.push(kv.join(':'));
}
} else if (kv.length == 1) {
map.others.push(kv[0]);
}
}
});
// 解析不带 key 的参数
if (others && others.length > 0 && map.others.length > 0) {
if (Array.isArray(others) == false) {
others = [others];
}
others.forEach((arg, i) => {
map[arg] = map.others.shift();
});
// 最后一段合并到最后一个参数中
if (map.others.length > 0) {
map[others[others.length-1]] += ' ' + map.others.join(' ');
map.others = [];
}
}
return map;
},
ArgsJoinTags(args, keys) {
if (Array.isArray(keys) == false) {
keys = [keys];
}
var ret = [];
keys.forEach((key, i) => {
if (args[key] && args[key].length > 0) {
ret.push(key + '="' + args[key] + '"');
}
});
return ret;
},
ArgsJoinURLParams(args, keys) {
if (Array.isArray(keys) == false) {
keys = [keys];
}
var ret = [];
keys.forEach((key, i) => {
if (args[key] && args[key].length > 0) {
ret.push(key + '=' + args[key]);
}
});
return ret.join('&');
}
};

View File

@ -33,8 +33,8 @@ $c-card-dark = #333
// font-weight: normal
// font-style: normal
$ff-body = Dosis, -apple-system, "Helvetica Neue", Helvetica, Arial, "WenQuanYi Micro Hei", "Microsoft Yahei", Menlo, Monaco, monospace, courier, sans-serif
$ff-code = Menlo, Monaco, monospace, courier, sans-serif
$ff-body = -apple-system, system-ui, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", Arial, "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif
$ff-code = Menlo, Monaco, Consolas, "Courier New", monospace, sans-serif
$ff-logo = $ff-body

View File

@ -18,6 +18,7 @@
width: 100%
color: var(--text-p2)
button.copy-btn
margin: 0
border-left: 1px solid var(--block-border)
display: inline-block
background: var(--hover-block)