'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 (https://statically.io/)
*  Usage: 
*/
const { join } = require('path').posix
hexo.extend.filter.register('marked:renderer', (renderer) => {
  renderer.image = (href, title, alt) => {
    if (!alt) alt = ''
    if (!title) title = alt
    if (href.endsWith('.svg')) return `
`
    // embed external image
    if (href.startsWith('http')) return `
`
    const fLink = (path, width) => {
      const query = new URLSearchParams('f=auto')
      if (typeof width === 'number') query.set('width', width)
      const url = new URL('http://example.com/' + join('img', path) + '?' + query)
      return url.pathname + url.search
    }
    return `` +
      `
`
  }
})