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.

56 lines
1.3 KiB

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