add users tag

This commit is contained in:
xaoxuu 2022-06-12 01:11:35 +08:00
parent 841614f784
commit d2ab959d87
4 changed files with 33 additions and 4 deletions

View File

@ -6,3 +6,6 @@ const postTabs = require('./lib/tabs')(hexo);
hexo.extend.tag.register('tabs', postTabs, true); hexo.extend.tag.register('tabs', postTabs, true);
hexo.extend.tag.register('subtabs', postTabs, true); hexo.extend.tag.register('subtabs', postTabs, true);
hexo.extend.tag.register('subsubtabs', postTabs, true); hexo.extend.tag.register('subsubtabs', postTabs, true);
const users = require('./lib/users')(hexo);
hexo.extend.tag.register('users', users);

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

@ -0,0 +1,23 @@
/**
* 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="friendsjs-wrap"';
el += ' id="friends-api"';
el += ' api="' + args.api + '"';
el += '>';
el += '<div class="group-body"></div>';
el += '</div>';
el += '</div>';
return el;
};

View File

@ -42,6 +42,8 @@ details.folding[open]
&:after &:after
content: '-' content: '-'
>div.body >div.body
display: flex;
flex-direction: column;
padding: 1rem padding: 1rem
margin: 0 - 1rem margin: 0 - 1rem
margin-top: 0 margin-top: 0

View File

@ -47,13 +47,14 @@ const friendsjs = {
$(el).append('<div class="loading-wrap"><svg class="loading" style="vertical-align: middle;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2709"><path d="M832 512c0-176-144-320-320-320V128c211.2 0 384 172.8 384 384h-64zM192 512c0 176 144 320 320 320v64C300.8 896 128 723.2 128 512h64z" p-id="2710"></path></svg><p></p></div>'); $(el).append('<div class="loading-wrap"><svg class="loading" style="vertical-align: middle;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2709"><path d="M832 512c0-176-144-320-320-320V128c211.2 0 384 172.8 384 384h-64zM192 512c0 176 144 320 320 320v64C300.8 896 128 723.2 128 512h64z" p-id="2710"></path></svg><p></p></div>');
friendsjs.requestAPI(cfg.api, function(data) { friendsjs.requestAPI(cfg.api, function(data) {
$(el).find('.loading-wrap').remove(); $(el).find('.loading-wrap').remove();
const arr = data.content; const arr = data.content || data;
console.log(data);
arr.forEach((item, i) => { arr.forEach((item, i) => {
var user = '<div class="user-card">'; var user = '<div class="user-card">';
user += '<a class="card-link" target="_blank" rel="external nofollow noopener noreferrer"'; user += '<a class="card-link" target="_blank" rel="external nofollow noopener noreferrer"';
user += ' href="' + item.url + '">'; user += ' href="' + (item.html_url || item.url) + '">';
user += '<img src="' + (item.avatar || cfg.avatar) + '" onerror="javascript:this.src=\'' + cfg.avatar + '\';">'; user += '<img src="' + (item.avatar_url || item.avatar || cfg.avatar) + '" onerror="javascript:this.src=\'' + cfg.avatar + '\';">';
user += '<div class="name"><span>' + item.title + '</span></div>'; user += '<div class="name"><span>' + (item.title || item.login) + '</span></div>';
user += '</a>'; user += '</a>';
user += '</div>'; user += '</div>';
$(el).find('.group-body').append(user); $(el).find('.group-body').append(user);