按分组筛选

This commit is contained in:
xaoxuu 2021-03-04 13:16:38 +08:00
parent d7a78bdce0
commit 83d73f67a3
2 changed files with 26 additions and 8 deletions

View File

@ -2,13 +2,19 @@
* friends.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/ * friends.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来 * 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
* *
* {% friends [group:name] %} * {% friends [only:group1] [not:group2] %}
*/ */
'use strict'; 'use strict';
hexo.extend.tag.register('friends', function(args) { 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; var friends = hexo.locals.get('data').friends;
if (friends == undefined) { if (friends == undefined) {
friends = {}; friends = {};
@ -39,6 +45,9 @@ hexo.extend.tag.register('friends', function(args) {
} }
for (let groupId of Object.keys(friends)) { for (let groupId of Object.keys(friends)) {
function f() { function f() {
if (args.not && args.not.includes(groupId)) {
return;
}
if (groupId in friends) { if (groupId in friends) {
let group = friends[groupId]; let group = friends[groupId];
if (group.title || group.description) { 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.only) {
if (args.group == groupId) { if (args.only.includes(groupId)) {
f(); f();
} }
} else { } else {

View File

@ -2,13 +2,19 @@
* sites.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/ * sites.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来 * 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
* *
* {% site [group:name] %} * {% sites [only:group1] [not:group2] %}
*/ */
'use strict'; 'use strict';
hexo.extend.tag.register('sites', function(args) { 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; var sites = hexo.locals.get('data').sites;
if (sites == undefined) { if (sites == undefined) {
sites = {}; sites = {};
@ -43,6 +49,9 @@ hexo.extend.tag.register('sites', function(args) {
} }
for (let groupId of Object.keys(sites)) { for (let groupId of Object.keys(sites)) {
function f() { function f() {
if (args.not && args.not.includes(groupId)) {
return;
}
if (groupId in sites) { if (groupId in sites) {
let group = sites[groupId]; let group = sites[groupId];
if (group.title || group.description) { 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.only) {
if (args.group == groupId) { if (args.only.includes(groupId)) {
f(); f();
} }
} else { } else {