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.

37 lines
1.4 KiB

  1. const isValidPage = function(page, postsPerPage, totalPosts)
  2. {
  3. return (!(page === 0 || page -1 >= totalPosts/postsPerPage));
  4. };
  5. module.exports=
  6. {
  7. main: function(baseURL, currentPage, postsPerPage, totalPosts)
  8. {
  9. var nextPage = currentPage + 1;
  10. var previousPage = currentPage - 1;
  11. var olderPosts = "";
  12. var newerPosts = "";
  13. if (isValidPage(previousPage, postsPerPage, totalPosts))
  14. {
  15. newerPosts = "<button class=\"btn btn-secondary btn-lg " +
  16. "w3-padding-large w3-white w3-border\" onclick=\"location.href='" +
  17. baseURL + "?page=" + previousPage +
  18. "'\"><b>Newer Posts &raquo;</b></button>";
  19. }
  20. if (isValidPage(nextPage, postsPerPage, totalPosts))
  21. {
  22. olderPosts = "<button class=\"btn btn-secondary btn-lg " +
  23. "w3-padding-large w3-white w3-border\" onclick=\"location.href='" +
  24. baseURL + "?page=" + nextPage +
  25. "'\"><b>Older Posts &raquo;</b></button>";
  26. }
  27. return " <div class=\"row\">\n" +
  28. " <div class=\"col-6\">" + newerPosts + "</div>\n" +
  29. " <div class=\"col-6\"><span class=\"float-right\">" + olderPosts + "</span></div>\n" +
  30. " <br><br></div>";
  31. }
  32. };