'use strict'
/* global hexo */
/*
* Embed an image with responsive images in a post
* https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images
* Image is resized on-the-fly using Statically Imgpx
* https://statically.io/imgpx
* Usage: ![alt](/path/to/img "title")
*/
hexo.extend.filter.register('marked:renderer', (renderer) => {
renderer.image = (href, title, alt) => {
if (!alt) alt = ''
if (!title) title = alt
let modern = href
let legacy = href
// /img/ is a reverse proxy to Statically CDN
// See source/_redirects
const link = '/img/'
if (href.endsWith('.png') || href.endsWith('.jpg')) {
modern = href.concat('?format=webp')
} else if (href.endsWith('.webp')) {
// Statically has yet to support animated webp
// https://github.com/marsble/statically/issues/36
// modern = href.concat('?auto_format=false')
modern = href.replace(/\.webp$/, '.gif')
legacy = href.replace(/\.webp$/, '.gif')
}
const modernLink = link + modern
const legacyLink = link + legacy
const img = ``
if (href.endsWith('.png') || href.endsWith('.webp')) {
return `` +
''
} else {
return `${img}`
}
}
})