fix: invalid page number after changing the pagination size.
This commit is contained in:
parent
2a4cb691e4
commit
7972966884
@ -89,7 +89,7 @@
|
||||
},
|
||||
"packageManager": "npm@11.0.0",
|
||||
"engines": {
|
||||
"node": "22.12.0"
|
||||
"node": "22.13.0"
|
||||
},
|
||||
"overrides": {
|
||||
"astro-uploader": {
|
||||
|
@ -20,7 +20,7 @@ const pageSize = options.settings.pagination.category;
|
||||
const total = Math.ceil(filteredPosts.length / pageSize);
|
||||
|
||||
if (pageNum > total) {
|
||||
return Astro.redirect('/404');
|
||||
return Astro.redirect(`${total}`, 302);
|
||||
}
|
||||
---
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
---
|
||||
import { posts, tags } from '@/helpers/schema';
|
||||
import PostsLayout from '@/layouts/posts/PostsLayout.astro';
|
||||
import options from '@/options';
|
||||
|
||||
const { num } = Astro.params;
|
||||
|
||||
@ -13,6 +14,11 @@ const pageNum = Number.parseInt(num);
|
||||
if (pageNum <= 1) {
|
||||
return Astro.redirect('/');
|
||||
}
|
||||
|
||||
const total = Math.ceil(posts.length / options.settings.pagination.posts);
|
||||
if (pageNum > total) {
|
||||
return Astro.redirect(`${total}`, 302);
|
||||
}
|
||||
---
|
||||
|
||||
<PostsLayout {posts} {pageNum} {tags} />
|
||||
|
@ -21,11 +21,10 @@ const searchResults = searchPosts(query)
|
||||
.map((slug) => posts.find((post) => post.slug === slug))
|
||||
.filter((post) => post !== undefined);
|
||||
|
||||
const pageSize = options.settings.pagination.tags;
|
||||
const total = Math.ceil(searchResults.length / pageSize);
|
||||
const total = Math.ceil(searchResults.length / options.settings.pagination.tags);
|
||||
|
||||
if (pageNum > total) {
|
||||
return Astro.redirect('/404');
|
||||
return Astro.redirect(`${total}`, 302);
|
||||
}
|
||||
---
|
||||
|
||||
|
@ -20,7 +20,7 @@ const pageSize = options.settings.pagination.tags;
|
||||
const total = Math.ceil(filteredPosts.length / pageSize);
|
||||
|
||||
if (pageNum > total) {
|
||||
return Astro.redirect('/404');
|
||||
return Astro.redirect(`${total}`, 302);
|
||||
}
|
||||
---
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user