/** * Butterfly * galleryGroup and gallery * {% galleryGroup [name] [descr] [url] [img] %} * {% gallery [lazyload],[rowHeight],[limit] %} * {% gallery url,[url],[lazyload],[rowHeight],[limit] %} */ 'use strict' const urlFor = require('hexo-util').url_for.bind(hexo) function gallery (args, content) { const { data, languages } = hexo.theme.i18n args = args.join(' ').split(',') let rowHeight, limit, lazyload, type, dataStr // url,[link],[lazyload],[rowHeight],[limit] if (args[0] === 'url') { dataStr = args[1] lazyload = args[2] === 'true' rowHeight = args[3] || 220 limit = args[4] || 10 type = ' url' } else { rowHeight = args[1] || 220 limit = args[2] || 10 lazyload = args[0] === 'true' type = ' data' 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) } const lazyloadClass = lazyload ? 'lazyload' : '' return `
${descr}