Our great sponsors
-
In the above code, I've used the process.env.VERCEL_URL as the siteURL. You might be wondering why I used that. In my case, I am using vercel to host my website. So we need to pass the siteURL to the RSS. In the production or Preview in Vercel, it provides us the environment variable called VERCEL_URL which is nothing but your site root URL. For example https://google.com. We need the root URL for the production as well as the development phase because we need to check if our RSS is working or not. That's why I've chosen VERCEL_URL as the environment variable. My .env.local looks like this-
-
// lib/generateRssFeed.js import fs from "fs"; import { Feed } from "feed"; import { getAllPosts } from "./posts"; export default async function generateRssFeed() { const posts = getAllPosts(); const siteURL = process.env.VERCEL_URL; const date = new Date(); const author = { name: "John Doe", email: "[email protected]", link: "https://twitter.com/", }; // Creating feed const feed = new Feed({ title: "Your Blog name", description: "Your Blog description", id: siteURL, link: siteURL, image: `${siteURL}/favicon.ico`, favicon: `${siteURL}/favicon.ico`, copyright: `All rights reserved ${date.getFullYear()}, Jatin Sharma`, updated: date, // today's date generator: "Feed for Node.js", feedLinks: { rss2: `${siteURL}/rss/feed.xml`, // xml format json: `${siteURL}/rss/feed.json`, // json fromat }, author, }); // Adding blogs to the rss feed posts.forEach((post) => { const url = `${siteURL}/blog/${post.slug}`; feed.addItem({ title: post.title, id: url, link: url, description: post.excerpt, content: post.excerpt, author: [author], contributor: [author], date: new Date(post.date), }); }); // generating the xml and json for rss fs.mkdirSync("./public/rss", { recursive: true }); fs.writeFileSync("./public/rss/feed.xml", feed.rss2()); fs.writeFileSync("./public/rss/feed.json", feed.json1()); }
-
SurveyJS
Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.
-
I am assuming you already have your blog page where all the blogs are listed. I am using MDX for managing the blog content. You might be using the same or anything else that doesn't matter. The main thing is you need to have an array containing all the blogs.