Browse Source

Added rss feed to website.

pull/84/head
jrtechs 4 years ago
parent
commit
1d5c696381
3 changed files with 22 additions and 4 deletions
  1. +0
    -3
      routes/index.js
  2. +20
    -0
      routes/rss.js
  3. +2
    -1
      utils/sql.js

+ 0
- 3
routes/index.js View File

@ -50,15 +50,12 @@ routes.get('/posts', (request, result) =>
const project = require('./projects'); const project = require('./projects');
routes.use('/steam', project); routes.use('/steam', project);
<<<<<<< Updated upstream
const api = require('./api'); const api = require('./api');
routes.use('/api', api); routes.use('/api', api);
=======
const feed = require('./rss'); const feed = require('./rss');
routes.use('/rss', feed); routes.use('/rss', feed);
>>>>>>> Stashed changes
//blog home page //blog home page
routes.get('/', (request, result) => routes.get('/', (request, result) =>

+ 20
- 0
routes/rss.js View File

@ -22,6 +22,26 @@ var feed = new RSS({
// var xml = require('xml'); // var xml = require('xml');
var xmlFeed = feed.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) => routes.get('/', (request, result) =>
{ {

+ 2
- 1
utils/sql.js View File

@ -135,6 +135,7 @@ const fetchWithCategoryInformation = function(sqlPosts)
var obj = new Object(); var obj = new Object();
obj.name = post.name; obj.name = post.name;
obj.url = post.url; obj.url = post.url;
obj.published = post.published;
obj.category = urls[0].url; obj.category = urls[0].url;
res(obj); res(obj);
}); });
@ -282,7 +283,7 @@ module.exports=
{ {
return new Promise(function(resolve, reject) 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"; "by post_id desc limit 10";
fetch(q).then(function(sqlPosts) fetch(q).then(function(sqlPosts)
{ {

Loading…
Cancel
Save