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
This commit is contained in:
Ming Di Leom 2022-03-05 08:06:43 +00:00
parent 2008cd202d
commit 2f22f1dfdf
No known key found for this signature in database
GPG Key ID: 32D3E28E96A695E8
2 changed files with 12 additions and 17 deletions

View File

@ -8,6 +8,8 @@
* Usage: ![alt](/path/to/img "title") * Usage: ![alt](/path/to/img "title")
*/ */
const { join } = require('path').posix
hexo.extend.filter.register('marked:renderer', (renderer) => { hexo.extend.filter.register('marked:renderer', (renderer) => {
renderer.image = (href, title, alt) => { renderer.image = (href, title, alt) => {
if (!alt) alt = '' if (!alt) alt = ''
@ -16,24 +18,17 @@ hexo.extend.filter.register('marked:renderer', (renderer) => {
if (href.endsWith('.svg')) return `<img class="svg" src="${href}" alt="${alt}" title="${title}">` if (href.endsWith('.svg')) return `<img class="svg" src="${href}" alt="${alt}" title="${title}">`
// embed external image // embed external image
if (!href.startsWith('20')) return `<img src="${href}" alt="${alt}" title="${title}">` if (!href.startsWith('20') && !href.startsWith('/20')) return `<img src="${href}" alt="${alt}" title="${title}">`
// Statically doesn't support WebP and GIF const fLink = (path, width) => {
if (href.endsWith('.webp')) { const query = new URLSearchParams('f=auto')
const gif = href.replace(/\.webp$/, '.gif') if (typeof width === 'number') query.set('width', width)
return `<a href="/files/${gif}"><picture>` + const url = new URL('http://example.com/' + join('img', path) + '?' + query)
`<source srcset="/files/${href}" type="image/webp">` +
`<img src="/files/${gif}" title="${title}" alt="${alt}" loading="lazy"></picture></a>` return url.pathname + url.search
} }
const fLink = (str, width) => { return `<a href="${join('http://curben.gitlab.io/blog', href)}">` +
if (typeof width === 'number') width = ',w=' + width.toString()
else width = ''
return '/img/gitlab.com/f=auto' + width + '/curben/blog/-/raw/site/' + str
}
return `<a href="${fLink(href)}">` +
`<img srcset="${fLink(href, 320)} 320w,` + `<img srcset="${fLink(href, 320)} 320w,` +
`${fLink(href, 468)} 468w,` + `${fLink(href, 468)} 468w,` +
`${fLink(href, 768)} 768w,` + `${fLink(href, 768)} 768w,` +

View File

@ -1,6 +1,6 @@
# Reverse proxy to cdn # Reverse proxy to cdn
/img/* https://cdn.statically.io/img/:splat 200 /img/* https://curben.gitlab.io/blog/:splat 200
/files/* https://curben.gitlab.io/blog/:splat 200
# https://statically.discourse.group/t/mobile-version-not-working-on-screenshot/225 # https://statically.discourse.group/t/mobile-version-not-working-on-screenshot/225
# /screenshot/* https://cdn.statically.io/screenshot/device=mobile/curben.netlify.app/:splat 200 # /screenshot/* https://cdn.statically.io/screenshot/device=mobile/curben.netlify.app/:splat 200
/screenshot/* https://cdn.statically.io/screenshot/curben.netlify.app/:splat 200 /screenshot/* https://cdn.statically.io/screenshot/curben.netlify.app/:splat 200
/files/* https://gitlab.com/curben/blog/-/raw/site/:splat 200