From 2f22f1dfdf7fe0d20e96434c2b3a85d35a221d90 Mon Sep 17 00:00:00 2001 From: Ming Di Leom <2809763-curben@users.noreply.gitlab.com> Date: Sat, 5 Mar 2022 08:06:43 +0000 Subject: [PATCH] fix(assets): proxy to gitlab pages - statically image-resizing is down * https://github.com/staticallyio/statically/issues/98 - may self-host https://github.com/staticallyio/image-resizing * requires CF Images subscription --- scripts/image.js | 25 ++++++++++--------------- source/_redirects | 4 ++-- 2 files changed, 12 insertions(+), 17 deletions(-) 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 `` + `