[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 size:small/medium/large %}
* /xxx.png
* /xxx.png
* /xxx.png
* /xxx.png
* {% gallery %}
* ![title](/xxx.png)
* ![title](/xxx.png)
* ![title](/xxx.png)
* ![title](/xxx.png)
* {% endgallery %}
*/
@ -29,23 +29,17 @@ function img(src, alt) {
}
module.exports = ctx => function(args, content) {
args = ctx.args.map(args, ['size'])
var el = ''
el += '<div class="tag-plugin gallery"'
el += ' ' + ctx.args.joinTags(args, ['size']).join(' ')
el += '>'
const rows = content.split(/<!--\s*row(.*?)\s*-->/g).filter(item => item.trim().length > 0)
for (let row of rows) {
const img_mds = row.split('\n').filter(item => item.trim().length > 0)
for (let md of img_mds) {
const matches = md.match(/\!\[(.*?)\]\((.*?)\)/i)
if (matches?.length > 2) {
let alt = matches[1]
let src = matches[2]
el += `<div class="cell">${img(src, alt)}</div>`
}
el += `<div class="tag-plugin gallery">`
const img_mds = content.split('\n').filter(item => item.trim().length > 0)
for (let md of img_mds) {
const matches = md.match(/\!\[(.*?)\]\((.*?)\)/i)
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
}