Fork of Chiri for Astro for my blog
0
fork

Configure Feed

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

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

+6 -15
+6 -15
src/utils/feed.ts
··· 1 1 import type { APIContext, ImageMetadata } from 'astro' 2 - import { getImage } from 'astro:assets' 3 2 import { getCollection, type CollectionEntry } from 'astro:content' 4 3 import { Feed } from 'feed' 5 4 import MarkdownIt from 'markdown-it' ··· 62 61 const imageUrl = new URL(relativePath, baseUrl).toString() 63 62 img.setAttribute('src', imageUrl) 64 63 } else { 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()) 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) 79 70 } 80 71 } catch (error) { 81 72 console.error(`[Feed] Image processing failed: ${src} -> ${resolvedPath}`, error)