Fork of Chiri for Astro for my blog
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Revert "Removing weird Netlify image optimizer that doesn't give RSS/Atom feeds access to images"

This reverts commit bd291bd3190c300cfb548eb060d783dfaaa2aa65.

+15 -6
+15 -6
src/utils/feed.ts
··· 1 1 import type { APIContext, ImageMetadata } from 'astro' 2 + import { getImage } from 'astro:assets' 2 3 import { getCollection, type CollectionEntry } from 'astro:content' 3 4 import { Feed } from 'feed' 4 5 import MarkdownIt from 'markdown-it' ··· 61 62 const imageUrl = new URL(relativePath, baseUrl).toString() 62 63 img.setAttribute('src', imageUrl) 63 64 } else { 64 - // Avoids Netlify image optimization URLs which are access-restricted 65 - const imageSrc = metadata.src 66 - const imageUrl = imageSrc.startsWith('http') 67 - ? imageSrc 68 - : `${baseUrl}${imageSrc.startsWith('/') ? '' : '/'}${imageSrc}` 69 - img.setAttribute('src', imageUrl) 65 + // Production environment: use getImage optimization 66 + const processedImage = await getImage({ 67 + src: metadata, 68 + format: 'webp', 69 + width: 800 70 + }) 71 + 72 + // Strip Netlify image optimization wrapper, use the raw _astro path 73 + let src = processedImage.src 74 + if (src.includes('/.netlify/images')) { 75 + const urlParam = new URL(src, baseUrl).searchParams.get('url') 76 + src = urlParam ? `/${decodeURIComponent(urlParam)}` : src 77 + } 78 + img.setAttribute('src', new URL(src, baseUrl).toString()) 70 79 } 71 80 } catch (error) { 72 81 console.error(`[Feed] Image processing failed: ${src} -> ${resolvedPath}`, error)