fix: invalid page number after changing the pagination size.
This commit is contained in:
parent
2a4cb691e4
commit
f3fba8e74f
10
package-lock.json
generated
10
package-lock.json
generated
@ -36,7 +36,7 @@
|
|||||||
"@types/pg": "^8.11.10",
|
"@types/pg": "^8.11.10",
|
||||||
"@types/qrcode-svg": "^1.1.5",
|
"@types/qrcode-svg": "^1.1.5",
|
||||||
"@types/unist": "^3.0.3",
|
"@types/unist": "^3.0.3",
|
||||||
"astro-netease-player": "^1.0.1",
|
"astro-netease-player": "^1.0.2",
|
||||||
"astro-uploader": "^1.2.3",
|
"astro-uploader": "^1.2.3",
|
||||||
"bootstrap": "^5.3.3",
|
"bootstrap": "^5.3.3",
|
||||||
"photoswipe": "^5.4.4",
|
"photoswipe": "^5.4.4",
|
||||||
@ -55,7 +55,7 @@
|
|||||||
"unist-util-select": "^5.1.0"
|
"unist-util-select": "^5.1.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "22.12.0"
|
"node": "22.13.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@astrojs/check": {
|
"node_modules/@astrojs/check": {
|
||||||
@ -2596,9 +2596,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/astro-netease-player": {
|
"node_modules/astro-netease-player": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/astro-netease-player/-/astro-netease-player-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/astro-netease-player/-/astro-netease-player-1.0.2.tgz",
|
||||||
"integrity": "sha512-k+5erGNLHyy/GRKLqUOuKiN7d2HeX6KHzbPKEa/oL0tda4s09Eu4Zzt29P05bO/QNs5EGJbsz9UGiUGeVevVmA==",
|
"integrity": "sha512-LIY747btm4iZUUjGQ/k/khUHnTyoFsGUdboIfLt3LTqIEs5cJctBPM945Ikjyg5inAw77QKqa8a9VyB58tOiUQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -69,7 +69,7 @@
|
|||||||
"@types/pg": "^8.11.10",
|
"@types/pg": "^8.11.10",
|
||||||
"@types/qrcode-svg": "^1.1.5",
|
"@types/qrcode-svg": "^1.1.5",
|
||||||
"@types/unist": "^3.0.3",
|
"@types/unist": "^3.0.3",
|
||||||
"astro-netease-player": "^1.0.1",
|
"astro-netease-player": "^1.0.2",
|
||||||
"astro-uploader": "^1.2.3",
|
"astro-uploader": "^1.2.3",
|
||||||
"bootstrap": "^5.3.3",
|
"bootstrap": "^5.3.3",
|
||||||
"photoswipe": "^5.4.4",
|
"photoswipe": "^5.4.4",
|
||||||
@ -89,7 +89,7 @@
|
|||||||
},
|
},
|
||||||
"packageManager": "npm@11.0.0",
|
"packageManager": "npm@11.0.0",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "22.12.0"
|
"node": "22.13.0"
|
||||||
},
|
},
|
||||||
"overrides": {
|
"overrides": {
|
||||||
"astro-uploader": {
|
"astro-uploader": {
|
||||||
|
@ -20,7 +20,7 @@ const pageSize = options.settings.pagination.category;
|
|||||||
const total = Math.ceil(filteredPosts.length / pageSize);
|
const total = Math.ceil(filteredPosts.length / pageSize);
|
||||||
|
|
||||||
if (pageNum > total) {
|
if (pageNum > total) {
|
||||||
return Astro.redirect('/404');
|
return Astro.redirect(`${total}`, 302);
|
||||||
}
|
}
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
---
|
---
|
||||||
import { posts, tags } from '@/helpers/schema';
|
import { posts, tags } from '@/helpers/schema';
|
||||||
import PostsLayout from '@/layouts/posts/PostsLayout.astro';
|
import PostsLayout from '@/layouts/posts/PostsLayout.astro';
|
||||||
|
import options from '@/options';
|
||||||
|
|
||||||
const { num } = Astro.params;
|
const { num } = Astro.params;
|
||||||
|
|
||||||
@ -13,6 +14,11 @@ const pageNum = Number.parseInt(num);
|
|||||||
if (pageNum <= 1) {
|
if (pageNum <= 1) {
|
||||||
return Astro.redirect('/');
|
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} />
|
<PostsLayout {posts} {pageNum} {tags} />
|
||||||
|
@ -21,11 +21,10 @@ const searchResults = searchPosts(query)
|
|||||||
.map((slug) => posts.find((post) => post.slug === slug))
|
.map((slug) => posts.find((post) => post.slug === slug))
|
||||||
.filter((post) => post !== undefined);
|
.filter((post) => post !== undefined);
|
||||||
|
|
||||||
const pageSize = options.settings.pagination.tags;
|
const total = Math.ceil(searchResults.length / options.settings.pagination.tags);
|
||||||
const total = Math.ceil(searchResults.length / pageSize);
|
|
||||||
|
|
||||||
if (pageNum > total) {
|
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);
|
const total = Math.ceil(filteredPosts.length / pageSize);
|
||||||
|
|
||||||
if (pageNum > total) {
|
if (pageNum > total) {
|
||||||
return Astro.redirect('/404');
|
return Astro.redirect(`${total}`, 302);
|
||||||
}
|
}
|
||||||
---
|
---
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user