diff --git a/src/pages/rss.xml.js b/src/pages/rss.xml.js index 69a6cdc..6945df2 100644 --- a/src/pages/rss.xml.js +++ b/src/pages/rss.xml.js @@ -6,13 +6,37 @@ export async function GET(context) { const posts = await getCollection('blog'); const projects = await getCollection('projects'); - let unifiedItems = posts.map((post) => ({ - ...post.data, - link: `/blog/${post.id}/`, - })).concat(projects.map((project) => ({ - ...project.data, - link: `/projects/${project.id}/` - }))); + let unifiedItems = posts.map((post) => { + let item = { + ...post.data, + link: `/blog/${post.id}/`, + }; + + if (post.data.heroImage) { + item.enclosure = { + url: post.data.heroImage.src, + length: post.data.heroImage.width * post.data.heroImage.height, + type: `image/${post.data.heroImage.format}` + } + } + + return item; + }).concat(projects.map((project) => { + let item = { + ...project.data, + link: `/projects/${project.id}/`, + }; + + if (project.heroImage) { + item.enclosure = { + url: project.data.heroImage.src, + length: project.data.heroImage.width * project.data.heroImage.height, + type: `image/${project.data.heroImage.format}` + } + } + + return item; + })); unifiedItems = unifiedItems.sort((a, b) => b.pubDate - a.pubDate); return rss({