Personal blog written from scratch using Node.js, Bootstrap, and MySQL. https://jrtechs.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.7 KiB

4 years ago
  1. var RSS = require('rss');
  2. const routes = require('express').Router();
  3. const pageBuilder = require('../utils/pageBuilder');
  4. const sql = require('../utils/sql');
  5. const generateRSSfeed = function()
  6. {
  7. var feed = new RSS({
  8. title: 'jrtechs',
  9. description: 'Jeffery\'s blog which has everything from data-science to cooking',
  10. feed_url: 'https://jrtechs.net/rss',
  11. site_url: 'https://jrtechs.net',
  12. image_url: 'https://jrtechs.net/includes/img/favicon/android-chrome-512x512.png',
  13. docs: 'https://github.com/jrtechs/NodeJSBlog',
  14. managingEditor: 'Jeffery Russell',
  15. webMaster: 'Jeffery Russell',
  16. copyright: 'Jeffery Russell',
  17. language: 'en',
  18. categories: ['other', 'hardware', 'open-source', 'programming', 'projects', 'web-development', 'data-science'],
  19. });
  20. return new Promise((resolve, reject)=>
  21. {
  22. sql.getRecentPosts(200).then((data)=>
  23. {
  24. for(var i = 0; i < data.length; i++)
  25. {
  26. feed.item({
  27. title: data[i].name,
  28. url: "https://jrtechs.net/" + data[i].category + "/" + data[i].url,
  29. date: data[i].published
  30. });
  31. }
  32. resolve(feed.xml());
  33. }).catch((err)=>
  34. {
  35. console.log(err);
  36. });
  37. })
  38. }
  39. routes.get('/', (request, result) =>
  40. {
  41. result.set('Content-Type', 'text/xml');
  42. generateRSSfeed().then((data)=>
  43. {
  44. result.send(data);
  45. }).catch((err)=>
  46. {
  47. pageBuilder.print404(result);
  48. })
  49. });
  50. routes.get('*', (request, result) =>
  51. {
  52. pageBuilder.print404(result);
  53. });
  54. module.exports = routes;