[feat] tag-plugin: posters

This commit is contained in:
xaoxuu 2024-01-05 10:09:33 +08:00
parent 3b300104af
commit 53d499fe9d
3 changed files with 51 additions and 0 deletions

View File

@ -17,6 +17,7 @@ hexo.extend.tag.register('banner', require('./lib/banner')(hexo), true)
hexo.extend.tag.register('users', require('./lib/friends')(hexo))
hexo.extend.tag.register('friends', require('./lib/friends')(hexo))
hexo.extend.tag.register('albums', require('./lib/albums')(hexo))
hexo.extend.tag.register('posters', require('./lib/posters')(hexo))
hexo.extend.tag.register('sites', require('./lib/sites')(hexo))
hexo.extend.tag.register('ghcard', require('./lib/ghcard')(hexo))
hexo.extend.tag.register('toc', require('./lib/toc')(hexo))

View File

@ -0,0 +1,47 @@
/**
* posters.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% posters [group] [repo:owner/repo] [api:http] [size:s/m/l/xl/mix] %}
*/
'use strict'
module.exports = ctx => function(args) {
var args = ctx.args.map(args, ['repo', 'api', 'size'], ['group'])
if (args.size == null) {
args.size = 'm'
}
var api
if (args.api) {
api = args.api
} else if (args.repo) {
api = 'https://api.vlts.cc/output_data/v2/' + args.repo
}
var el = ''
el += `<div class="tag-plugin posters-wrap">`
if (api) {
el += `<div class="stellar-friends-api" api="${api}"><div class="tag-plugin gallery grid-box" layout="grid" ratio="square" ${ctx.args.joinTags(args, ['size']).join(' ')}></div></div>`
} else if (args.group) {
const links = ctx.theme.config.links || {}
el += `<div class="tag-plugin gallery grid-box" layout="grid" ratio="portrait" ${ctx.args.joinTags(args, ['size']).join(' ')}>`
for (let item of (links[args.group] || [])) {
if (item?.url) {
el += `<div class="grid-cell poster-card">`
el += `<a class="card-link" target="_blank" rel="external nofollow noopener noreferrer" href="${item.url}">`
el += `<img src="${item.icon || item.avatar || ctx.theme.config.default.cover}" onerror="javascript:this.removeAttribute(&quot;data-src&quot;);this.src=&quot;${ctx.theme.config.default.cover}&quot;;"/>`
el += `<div class="image-meta">`
if (item.title) {
el += `<span class="image-caption">${item.title}</span>`
}
el += `</div>`
el += `</a>`
el += `</div>`
}
}
el += `</div>`
}
el += `</div>`
return el
}

View File

@ -88,6 +88,9 @@
&[ratio='square']
.grid-cell
aspect-ratio: 1
&[ratio='portrait']
.grid-cell
aspect-ratio: 4 / 5
.grid-cell
background: var(--block)
img