const feedPath = "/var/www/html/blog/feed.xml";
const fs = require("fs");
const blogs = require("/var/www/html/blog/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]);
const content = escapeQuotes(blog[1]);
const date = escapeQuotes(blog[2]);
const imagesHtml = blogs[index][3] ? `${blogs[index][3].map(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.');
}
});