import { allPosts, Post } from "content-collections"; import { compareDesc, parseISO, setHours } from "date-fns"; import { Feed } from "feed"; const baseUrl = "https://techaro.lol"; const createPostUrl = (url: string) => { return url + "?utm_campaign=feed&utm_source=blog.rss"; }; const createContent = (post: Post, url: string) => `

${post.summary}

Read the full article on techaro.lol

`; const createFeed = () => { const feed = new Feed({ title: "Techaro Blog", description: "Insights and updates from the Techaro team.", id: baseUrl, link: baseUrl, language: "en", favicon: `${baseUrl}/favicon.ico`, copyright: `All rights reserved ${new Date().getFullYear()}, Techaro Computing Canada`, generator: "Techaro.lol www", author: { name: "Techaro Staff", email: "staff@techaro.lol", link: baseUrl, }, }); allPosts .sort((a, b) => compareDesc(new Date(a.date), new Date(b.date))) .forEach((post) => { const id = `${baseUrl}/${post.urlPath}`; const url = createPostUrl(id); feed.addItem({ title: post.title, id: id, link: url, description: post.summary, content: createContent(post, url), author: [ { name: post.author!.displayName!, email: `${post.author?.name}@techaro.lol`, link: baseUrl, } ], date: setHours(parseISO(post.date), 13), image: post.imageURL, }); }); return feed.rss2(); }; export const GET = async () => { const feed = await createFeed(); return new Response(feed, { status: 200, headers: { "Content-Type": "application/xml", }, }); };