Merge pull request 'feat: redirect if page is below 1' (#1) from Cyber/ravenscott-blog:main into main

Reviewed-on: snxraven/ravenscott-blog#1
This commit is contained in:
snxraven 2024-09-16 16:03:46 -04:00
commit 0c9279805e

5
app.js
View File

@ -103,6 +103,11 @@ function getAllBlogPosts(page = 1, postsPerPage = 5) {
// Home Route (Blog Home with Pagination)
app.get('/', (req, res) => {
const page = parseInt(req.query.page) || 1;
if (page < 1) {
return res.redirect(req.hostname);
}
const postsPerPage = 5; // Set how many posts to display per page
const { blogPosts, totalPages } = getAllBlogPosts(page, postsPerPage);