/** * Butterfly * galleryGroup and gallery * {% galleryGroup [name] [descr] [url] [img] %} * * {% gallery [button],%} * {% gallery url,[url],[button]%} */ 'use strict' const urlFor = require('hexo-util').url_for.bind(hexo) const gallery = (args, content) => { args = args.join(' ').split(',') let button = false let type = 'data' let dataStr = '' if (args[0] === 'url') { [type, dataStr, button] = args // url,[link],[lazyload] } else { [button] = args // [lazyload] const regex = /!\[(.*?)\]\(([^\s]*)\s*(?:["'](.*?)["']?)?\s*\)/g let m const arr = [] while ((m = regex.exec(content)) !== null) { if (m.index === regex.lastIndex) { regex.lastIndex++ } arr.push({ url: m[2], alt: m[1], title: m[3] }) } dataStr = JSON.stringify(arr) } return `
${descr}