'use strict'
/* global hexo */
/*
* Put {% cloudinary 'folder/filename.jpg' 'description' %} in your post.
* Change the username in 'user' variable
* More info:
* https://cloudinary.com/blog/responsive_images_with_srcset_sizes_and_cloudinary
*/
hexo.extend.tag.register('cloudinary', (args) => {
const user = 'curben'
const fileName = args[0]
const alt = args[1] || ''
let modern = ''
let legacy = ''
const cloudinary = 'https://res.cloudinary.com/' + user +
'/image/upload/f_auto,q_auto'
if (fileName.endsWith('.png')) {
modern = fileName.replace(/\.png$/, '.webp')
legacy = fileName
} else if (fileName.endsWith('.webp')) {
modern = fileName
legacy = fileName.replace(/\.webp$/, '.gif')
} else {
legacy = fileName
}
const img = `
src="${cloudinary}w_768/${legacy}"
alt="${alt}">`
if (fileName.endsWith('.png') || fileName.endsWith('.webp')) {
return `
`
} else {
return `
${img}`
}
})