'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'
let [fileName, alt] = args
if (!alt) alt = ''
let modern = ''
let legacy = ''
const link = 'https://cdn.statically.io/img/res.cloudinary.com/' + user
if (fileName.endsWith('.png')) {
modern = fileName.replace(/\.png$/, '.webp')
legacy = fileName
} else if (fileName.endsWith('.webp')) {
// Statically doesn't support animated webp
// https://github.com/marsble/statically/issues/36
// modern = fileName
modern = fileName.replace(/\.webp$/, '.gif')
legacy = fileName.replace(/\.webp$/, '.gif')
} else {
legacy = fileName
}
const modernLink = link + '/' + modern + '?auto_format=false'
const legacyLink = link + '/' + legacy + '?auto_format=false'
const img = ``
if (fileName.endsWith('.png') || fileName.endsWith('.webp')) {
return `
`
} else {
return `${img}`
}
})