add users tag
This commit is contained in:
parent
841614f784
commit
d2ab959d87
|
@ -6,3 +6,6 @@ const postTabs = require('./lib/tabs')(hexo);
|
|||
hexo.extend.tag.register('tabs', postTabs, true);
|
||||
hexo.extend.tag.register('subtabs', postTabs, true);
|
||||
hexo.extend.tag.register('subsubtabs', postTabs, true);
|
||||
|
||||
const users = require('./lib/users')(hexo);
|
||||
hexo.extend.tag.register('users', users);
|
|
@ -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;
|
||||
};
|
|
@ -42,6 +42,8 @@ details.folding[open]
|
|||
&:after
|
||||
content: '-'
|
||||
>div.body
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 1rem
|
||||
margin: 0 - 1rem
|
||||
margin-top: 0
|
||||
|
|
|
@ -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>');
|
||||
friendsjs.requestAPI(cfg.api, function(data) {
|
||||
$(el).find('.loading-wrap').remove();
|
||||
const arr = data.content;
|
||||
const arr = data.content || data;
|
||||
console.log(data);
|
||||
arr.forEach((item, i) => {
|
||||
var user = '<div class="user-card">';
|
||||
user += '<a class="card-link" target="_blank" rel="external nofollow noopener noreferrer"';
|
||||
user += ' href="' + item.url + '">';
|
||||
user += '<img src="' + (item.avatar || cfg.avatar) + '" onerror="javascript:this.src=\'' + cfg.avatar + '\';">';
|
||||
user += '<div class="name"><span>' + item.title + '</span></div>';
|
||||
user += ' href="' + (item.html_url || item.url) + '">';
|
||||
user += '<img src="' + (item.avatar_url || item.avatar || cfg.avatar) + '" onerror="javascript:this.src=\'' + cfg.avatar + '\';">';
|
||||
user += '<div class="name"><span>' + (item.title || item.login) + '</span></div>';
|
||||
user += '</a>';
|
||||
user += '</div>';
|
||||
$(el).find('.group-body').append(user);
|
||||
|
|
Loading…
Reference in New Issue