diff --git a/scripts/image.js b/scripts/image.js index ad731a6..0039e88 100644 --- a/scripts/image.js +++ b/scripts/image.js @@ -8,6 +8,8 @@ * Usage: ![alt](/path/to/img "title") */ +const { join } = require('path').posix + hexo.extend.filter.register('marked:renderer', (renderer) => { renderer.image = (href, title, alt) => { if (!alt) alt = '' @@ -16,24 +18,17 @@ hexo.extend.filter.register('marked:renderer', (renderer) => { if (href.endsWith('.svg')) return `${alt}` // embed external image - if (!href.startsWith('20')) return `${alt}` + if (!href.startsWith('20') && !href.startsWith('/20')) return `${alt}` - // Statically doesn't support WebP and GIF - if (href.endsWith('.webp')) { - const gif = href.replace(/\.webp$/, '.gif') - return `` + - `` + - `${alt}` + 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 } - const fLink = (str, width) => { - if (typeof width === 'number') width = ',w=' + width.toString() - else width = '' - - return '/img/gitlab.com/f=auto' + width + '/curben/blog/-/raw/site/' + str - } - - return `` + + return `` + `