diff --git a/scripts/events/index.js b/scripts/events/index.js index 9ca8fb6..8a49106 100644 --- a/scripts/events/index.js +++ b/scripts/events/index.js @@ -5,6 +5,7 @@ hexo.on('generateBefore', () => { // Merge config. require('./lib/config')(hexo); + require('./lib/utils')(hexo); }); hexo.on('ready', () => { diff --git a/scripts/events/lib/config.js b/scripts/events/lib/config.js index ee52362..0de8f90 100644 --- a/scripts/events/lib/config.js +++ b/scripts/events/lib/config.js @@ -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.`); diff --git a/scripts/events/lib/utils.js b/scripts/events/lib/utils.js new file mode 100644 index 0000000..6714d04 --- /dev/null +++ b/scripts/events/lib/utils.js @@ -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('&'); + } + }; +}; diff --git a/scripts/tags/about.js b/scripts/tags/about.js index bb63cd9..497b598 100644 --- a/scripts/tags/about.js +++ b/scripts/tags/about.js @@ -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 += ''; } - + el += ''; // content el += '
'; el += rows.join(''); el += '
'; - + el += ''; return el; }, {ends: true}); diff --git a/scripts/tags/checkbox.js b/scripts/tags/checkbox.js index 662af11..ba9bab5 100644 --- a/scripts/tags/checkbox.js +++ b/scripts/tags/checkbox.js @@ -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 += '
'; - + el += '' + (args.description || args.url) + ''; diff --git a/scripts/tags/note.js b/scripts/tags/note.js index a7258b0..4460c2d 100644 --- a/scripts/tags/note.js +++ b/scripts/tags/note.js @@ -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}); diff --git a/scripts/tags/swiper.js b/scripts/tags/swiper.js index 710f2a4..036697a 100644 --- a/scripts/tags/swiper.js +++ b/scripts/tags/swiper.js @@ -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 += '
0) { - el += ' ' + ArgsJoinTags(args, 'width').join(' '); + el += ' ' + hexo.args.joinTags(args, 'width').join(' '); } el += '>'; el += '
'; diff --git a/scripts/tags/timeline.js b/scripts/tags/timeline.js index 7f77da5..3a6572f 100644 --- a/scripts/tags/timeline.js +++ b/scripts/tags/timeline.js @@ -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 = ''; diff --git a/scripts/tags/utils.js b/scripts/tags/utils.js deleted file mode 100644 index 91015db..0000000 --- a/scripts/tags/utils.js +++ /dev/null @@ -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('&'); - } -}; diff --git a/source/css/_custom.styl b/source/css/_custom.styl index 7353f4c..0ad7096 100644 --- a/source/css/_custom.styl +++ b/source/css/_custom.styl @@ -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 diff --git a/source/css/_layout/tag-plugins/copy.styl b/source/css/_layout/tag-plugins/copy.styl index ee82afd..a9b3533 100644 --- a/source/css/_layout/tag-plugins/copy.styl +++ b/source/css/_layout/tag-plugins/copy.styl @@ -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)