From cb57fe45a319914beb221ba14168d9fff19e1f3a Mon Sep 17 00:00:00 2001 From: Anuj Ahooja Date: Mon, 23 Feb 2026 17:04:03 -0800 Subject: [PATCH] Revert "Removing weird Netlify image optimizer that doesn't give RSS/Atom feeds access to images" This reverts commit bd291bd3190c300cfb548eb060d783dfaaa2aa65. --- src/utils/feed.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/utils/feed.ts b/src/utils/feed.ts index 30e95c4..ef06ee8 100644 --- a/src/utils/feed.ts +++ b/src/utils/feed.ts @@ -1,4 +1,5 @@ import type { APIContext, ImageMetadata } from 'astro' +import { getImage } from 'astro:assets' import { getCollection, type CollectionEntry } from 'astro:content' import { Feed } from 'feed' import MarkdownIt from 'markdown-it' @@ -61,12 +62,20 @@ async function fixRelativeImagePaths(htmlContent: string, baseUrl: string, postP const imageUrl = new URL(relativePath, baseUrl).toString() img.setAttribute('src', imageUrl) } else { - // Avoids Netlify image optimization URLs which are access-restricted - const imageSrc = metadata.src - const imageUrl = imageSrc.startsWith('http') - ? imageSrc - : `${baseUrl}${imageSrc.startsWith('/') ? '' : '/'}${imageSrc}` - img.setAttribute('src', imageUrl) + // Production environment: use getImage optimization + const processedImage = await getImage({ + src: metadata, + format: 'webp', + width: 800 + }) + + // Strip Netlify image optimization wrapper, use the raw _astro path + let src = processedImage.src + if (src.includes('/.netlify/images')) { + const urlParam = new URL(src, baseUrl).searchParams.get('url') + src = urlParam ? `/${decodeURIComponent(urlParam)}` : src + } + img.setAttribute('src', new URL(src, baseUrl).toString()) } } catch (error) { console.error(`[Feed] Image processing failed: ${src} -> ${resolvedPath}`, error) -- 2.51.2