const fs = require("fs"); const serverRoot = require("./serverPath.js") const feedPath = `${serverRoot}/blogs/feed.xml`; const blogs = require(`${serverRoot}/blogs/blogs.js`); console.log(blogs); function escapeQuotes(value) { return value.replace(/["'&<>]/g, function (char) { switch (char) { case '"': return """; case "'": return "'"; case "&": return "&"; case "<": return "<"; case ">": return ">"; default: return char; } }); } // Function to create RSS feed as a string function createRSSFeed(blogs) { let rssFeed = ` DeaDvey https://deadvey.com Just talking about life and stuff I guess ${blogs[blogs.length - 1][2]} +0000 ${blogs[blogs.length - 1][2]} +0000`; // Add items to the feed for (let index = blogs.length - 1; index >= 0; index--) { const blog = blogs[index] const title = escapeQuotes(blog[0]); let content = escapeQuotes(blog[1]); const date = escapeQuotes(blog[2]); const imagesHtml = blogs[index][3] ? `${blogs[index][3].map(image => `Blog Image`).join('')}` : ''; const totalContent = content + escapeQuotes(imagesHtml) const category = blog[4] ? blog[4].map(category => `${escapeQuotes(category)}`).join('') : ''; rssFeed += ` ${title} https://deadvey.com/blog/blogs/${index}.html ${totalContent} ${date} +0000 ${category} `; } // Close the RSS feed rssFeed += ` `; return rssFeed; } feed = createRSSFeed(blogs) fs.writeFile(feedPath, feed, (err) => { if (err) { console.error('Error writing to the file:', err); } else { console.log('Data has been written to the file successfully.'); } });