fix: invalid page number after changing the pagination size.

This commit is contained in:
Yufan Sheng 2025-01-08 19:10:57 +08:00
parent 2a4cb691e4
commit f3fba8e74f
Signed by: syhily
GPG Key ID: 9D18A22A7DCD5A9B
6 changed files with 17 additions and 12 deletions

10
package-lock.json generated
View File

@ -36,7 +36,7 @@
"@types/pg": "^8.11.10",
"@types/qrcode-svg": "^1.1.5",
"@types/unist": "^3.0.3",
"astro-netease-player": "^1.0.1",
"astro-netease-player": "^1.0.2",
"astro-uploader": "^1.2.3",
"bootstrap": "^5.3.3",
"photoswipe": "^5.4.4",
@ -55,7 +55,7 @@
"unist-util-select": "^5.1.0"
},
"engines": {
"node": "22.12.0"
"node": "22.13.0"
}
},
"node_modules/@astrojs/check": {
@ -2596,9 +2596,9 @@
}
},
"node_modules/astro-netease-player": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/astro-netease-player/-/astro-netease-player-1.0.1.tgz",
"integrity": "sha512-k+5erGNLHyy/GRKLqUOuKiN7d2HeX6KHzbPKEa/oL0tda4s09Eu4Zzt29P05bO/QNs5EGJbsz9UGiUGeVevVmA==",
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/astro-netease-player/-/astro-netease-player-1.0.2.tgz",
"integrity": "sha512-LIY747btm4iZUUjGQ/k/khUHnTyoFsGUdboIfLt3LTqIEs5cJctBPM945Ikjyg5inAw77QKqa8a9VyB58tOiUQ==",
"dev": true,
"license": "MIT",
"dependencies": {

View File

@ -69,7 +69,7 @@
"@types/pg": "^8.11.10",
"@types/qrcode-svg": "^1.1.5",
"@types/unist": "^3.0.3",
"astro-netease-player": "^1.0.1",
"astro-netease-player": "^1.0.2",
"astro-uploader": "^1.2.3",
"bootstrap": "^5.3.3",
"photoswipe": "^5.4.4",
@ -89,7 +89,7 @@
},
"packageManager": "npm@11.0.0",
"engines": {
"node": "22.12.0"
"node": "22.13.0"
},
"overrides": {
"astro-uploader": {

View File

@ -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);
}
---

View File

@ -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} />

View File

@ -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);
}
---

View File

@ -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);
}
---