From 83d73f67a3fb242dd9b9979a7da10cc6c6d03f35 Mon Sep 17 00:00:00 2001 From: xaoxuu Date: Thu, 4 Mar 2021 13:16:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=89=E5=88=86=E7=BB=84=E7=AD=9B=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/tags/friends.js | 17 +++++++++++++---- scripts/tags/site.js | 17 +++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/scripts/tags/friends.js b/scripts/tags/friends.js index 86f4ebc..f751634 100644 --- a/scripts/tags/friends.js +++ b/scripts/tags/friends.js @@ -2,13 +2,19 @@ * friends.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/ * 格式与官方标签插件一致使用空格分隔,中括号内的是可选参数(中括号不需要写出来) * - * {% friends [group:name] %} + * {% friends [only:group1] [not:group2] %} */ 'use strict'; hexo.extend.tag.register('friends', function(args) { - args = hexo.args.map(args, ['group']); + args = hexo.args.map(args, ['only', 'not']); + if (args.only) { + args.only = args.only.split(','); + } + if (args.not) { + args.not = args.not.split(','); + } var friends = hexo.locals.get('data').friends; if (friends == undefined) { friends = {}; @@ -39,6 +45,9 @@ hexo.extend.tag.register('friends', function(args) { } for (let groupId of Object.keys(friends)) { function f() { + if (args.not && args.not.includes(groupId)) { + return; + } if (groupId in friends) { let group = friends[groupId]; if (group.title || group.description) { @@ -60,8 +69,8 @@ hexo.extend.tag.register('friends', function(args) { } } } - if (args.group && args.group.length > 0) { - if (args.group == groupId) { + if (args.only) { + if (args.only.includes(groupId)) { f(); } } else { diff --git a/scripts/tags/site.js b/scripts/tags/site.js index 4da120c..a30f9fe 100644 --- a/scripts/tags/site.js +++ b/scripts/tags/site.js @@ -2,13 +2,19 @@ * sites.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/ * 格式与官方标签插件一致使用空格分隔,中括号内的是可选参数(中括号不需要写出来) * - * {% site [group:name] %} + * {% sites [only:group1] [not:group2] %} */ 'use strict'; hexo.extend.tag.register('sites', function(args) { - args = hexo.args.map(args, ['group']); + args = hexo.args.map(args, ['only', 'not']); + if (args.only) { + args.only = args.only.split(','); + } + if (args.not) { + args.not = args.not.split(','); + } var sites = hexo.locals.get('data').sites; if (sites == undefined) { sites = {}; @@ -43,6 +49,9 @@ hexo.extend.tag.register('sites', function(args) { } for (let groupId of Object.keys(sites)) { function f() { + if (args.not && args.not.includes(groupId)) { + return; + } if (groupId in sites) { let group = sites[groupId]; if (group.title || group.description) { @@ -64,8 +73,8 @@ hexo.extend.tag.register('sites', function(args) { } } } - if (args.group && args.group.length > 0) { - if (args.group == groupId) { + if (args.only) { + if (args.only.includes(groupId)) { f(); } } else {