[opt] gallery

This commit is contained in:
xaoxuu 2023-12-23 01:16:29 +08:00
parent 45de6641bd
commit ed4be939cb
1 changed files with 14 additions and 20 deletions

View File

@ -2,11 +2,11 @@
* gallery.js v1.0 | https://github.com/xaoxuu/hexo-theme-stellar/ * gallery.js v1.0 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来 * 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
* *
* {% gallery size:small/medium/large %} * {% gallery %}
* /xxx.png * ![title](/xxx.png)
* /xxx.png * ![title](/xxx.png)
* /xxx.png * ![title](/xxx.png)
* /xxx.png * ![title](/xxx.png)
* {% endgallery %} * {% endgallery %}
*/ */
@ -29,23 +29,17 @@ function img(src, alt) {
} }
module.exports = ctx => function(args, content) { module.exports = ctx => function(args, content) {
args = ctx.args.map(args, ['size'])
var el = '' var el = ''
el += '<div class="tag-plugin gallery"' el += `<div class="tag-plugin gallery">`
el += ' ' + ctx.args.joinTags(args, ['size']).join(' ') const img_mds = content.split('\n').filter(item => item.trim().length > 0)
el += '>' for (let md of img_mds) {
const rows = content.split(/<!--\s*row(.*?)\s*-->/g).filter(item => item.trim().length > 0) const matches = md.match(/\!\[(.*?)\]\((.*?)\)/i)
for (let row of rows) { if (matches?.length > 2) {
const img_mds = row.split('\n').filter(item => item.trim().length > 0) let alt = matches[1]
for (let md of img_mds) { let src = matches[2]
const matches = md.match(/\!\[(.*?)\]\((.*?)\)/i) el += `<div class="cell">${img(src, alt)}</div>`
if (matches?.length > 2) {
let alt = matches[1]
let src = matches[2]
el += `<div class="cell">${img(src, alt)}</div>`
}
} }
} }
el += '</div>' el += `</div>`
return el return el
} }