/** * Butterfly * galleryGroup and gallery * {% galleryGroup [name] [descr] [url] [img] %} * * {% gallery [button],[limit],[firstLimit] %} * {% gallery url,[url],[button] %} */ 'use strict' const urlFor = require('hexo-util').url_for.bind(hexo) const DEFAULT_LIMIT = 10 const DEFAULT_FIRST_LIMIT = 10 const IMAGE_REGEX = /!\[(.*?)\]\(([^\s]*)\s*(?:["'](.*?)["']?)?\s*\)/g // Helper functions const parseGalleryArgs = args => { const [type, ...rest] = args.join(' ').split(',').map(arg => arg.trim()) return { isUrl: type === 'url', params: type === 'url' ? rest : [type, ...rest] } } const parseImageContent = content => { const images = [] let match while ((match = IMAGE_REGEX.exec(content)) !== null) { images.push({ url: match[2], alt: match[1] || '', title: match[3] || '' }) } return images } const createGalleryHTML = (type, dataStr, button, limit, firstLimit) => { return `
${descr}