diff --git a/scripts/cloudinary.js b/scripts/cloudinary.js index 2098938..a369816 100644 --- a/scripts/cloudinary.js +++ b/scripts/cloudinary.js @@ -15,7 +15,7 @@ hexo.extend.tag.register('cloudinary', (args) => { let modern = '' let legacy = '' const cloudinary = 'https://res.cloudinary.com/' + user + - '/image/upload/f_auto,q_auto/c_limit,' + '/image/upload/f_auto,q_auto' if (fileName.endsWith('.png')) { modern = fileName.replace(/\.png$/, '.webp') @@ -23,57 +23,38 @@ hexo.extend.tag.register('cloudinary', (args) => { } 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 ` - ${alt} + srcset="${cloudinary}/c_limit,w_320/${modern} 320w, + ${cloudinary}/c_limit,w_468/${modern} 468w, + ${cloudinary}/c_limit,w_768/${modern} 768w, + ${cloudinary}/${modern} 800w" + sizes="(max-width: 320px) 320px, + (max-width: 468px) 468px, + (max-width: 768px) 768px, + 800px"> + ${img} ` } else { return ` - ${alt} - ` + ${img}` } })