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.

38 lines
886 B

  1. const fs = require('fs');
  2. const sql = require('../utils/sql');
  3. module.exports=
  4. {
  5. /**
  6. * Function which is responsible for writing the sitemap
  7. * to ../sitemap.txt
  8. */
  9. main: function()
  10. {
  11. sql.getSiteMap().then(function(result)
  12. {
  13. var buf = Buffer.from(result, 'utf8');
  14. var path = '../sitemap.txt';
  15. fs.open(path, 'w', function(error, fd)
  16. {
  17. if(error)
  18. throw 'could not open file: ' + error;
  19. fs.write(fd, buf, 0, buf.length, null, function(err)
  20. {
  21. if(err)
  22. throw "error writing file: " + err;
  23. fs.close(fd, function()
  24. {
  25. console.log("Updated Sitemap");
  26. })
  27. });
  28. });
  29. });
  30. }
  31. }