diff --git a/routes/index.js b/routes/index.js index 4787e77..48c813c 100644 --- a/routes/index.js +++ b/routes/index.js @@ -50,15 +50,12 @@ routes.get('/posts', (request, result) => const project = require('./projects'); routes.use('/steam', project); -<<<<<<< Updated upstream const api = require('./api'); routes.use('/api', api); -======= const feed = require('./rss'); routes.use('/rss', feed); ->>>>>>> Stashed changes //blog home page routes.get('/', (request, result) => diff --git a/routes/rss.js b/routes/rss.js index 572a117..9b4edd7 100644 --- a/routes/rss.js +++ b/routes/rss.js @@ -22,6 +22,26 @@ var feed = new RSS({ // var xml = require('xml'); var xmlFeed = feed.xml(); +const sql = require('../utils/sql'); + +sql.getRecentPosts().then((data)=> +{ + for(var i = 0; i < data.length; i++) + { + feed.item({ + title: data[i].name, + url: "https://jrtechs.net/" + data[i].category + "/" + data[i].url, + date: data[i].published + }); + } + xmlFeed = feed.xml(); +}).catch((err)=> +{ + console.log(err); +}); + + + routes.get('/', (request, result) => { diff --git a/utils/sql.js b/utils/sql.js index ad85a1a..5af915e 100644 --- a/utils/sql.js +++ b/utils/sql.js @@ -135,6 +135,7 @@ const fetchWithCategoryInformation = function(sqlPosts) var obj = new Object(); obj.name = post.name; obj.url = post.url; + obj.published = post.published; obj.category = urls[0].url; res(obj); }); @@ -282,7 +283,7 @@ module.exports= { return new Promise(function(resolve, reject) { - var q = "select name,url, category_id from posts order " + + var q = "select name,url, published, category_id from posts order " + "by post_id desc limit 10"; fetch(q).then(function(sqlPosts) {