fix: the 404 page for search result.
This commit is contained in:
parent
d003aaccb0
commit
dfc2a55356
@ -13,7 +13,7 @@ interface Props {
|
||||
|
||||
const { pageNum, posts } = Astro.props;
|
||||
const results = slicePosts(posts, pageNum, options.settings.pagination.posts);
|
||||
if (!results) {
|
||||
if (results.totalPage === 0) {
|
||||
return Astro.redirect('/404');
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ export const slicePosts = (
|
||||
posts: Post[],
|
||||
pageNum: number,
|
||||
pageSize: number,
|
||||
): { currentPosts: Post[]; totalPage: number } | undefined => {
|
||||
): { currentPosts: Post[]; totalPage: number } => {
|
||||
const totalPage = Math.ceil(posts.length / pageSize);
|
||||
if (totalPage >= pageNum) {
|
||||
return {
|
||||
@ -17,6 +17,7 @@ export const slicePosts = (
|
||||
totalPage,
|
||||
};
|
||||
}
|
||||
return { currentPosts: [], totalPage: 0 };
|
||||
};
|
||||
|
||||
export const formatShowDate = (date: Date) => {
|
||||
|
@ -13,12 +13,10 @@ interface Props {
|
||||
}
|
||||
|
||||
const { category, posts, pageNum } = Astro.props;
|
||||
const results = slicePosts(posts, pageNum, options.settings.pagination.category);
|
||||
if (!results) {
|
||||
const { currentPosts, totalPage } = slicePosts(posts, pageNum, options.settings.pagination.category);
|
||||
if (totalPage === 0) {
|
||||
return Astro.redirect('/404');
|
||||
}
|
||||
|
||||
const { currentPosts, totalPage } = results;
|
||||
---
|
||||
|
||||
<BaseLayout title={category.name}>
|
||||
|
@ -20,12 +20,7 @@ if (pageNum < 1) {
|
||||
return Astro.redirect('/');
|
||||
}
|
||||
|
||||
const results = slicePosts(posts, pageNum, options.settings.pagination.search);
|
||||
if (!results) {
|
||||
return Astro.redirect('/404');
|
||||
}
|
||||
|
||||
const { currentPosts, totalPage } = results;
|
||||
const { currentPosts, totalPage } = slicePosts(posts, pageNum, options.settings.pagination.search);
|
||||
---
|
||||
|
||||
<BaseLayout {title}>
|
||||
|
@ -13,12 +13,10 @@ interface Props {
|
||||
}
|
||||
|
||||
const { tag, posts, pageNum } = Astro.props;
|
||||
const results = slicePosts(posts, pageNum, options.settings.pagination.tags);
|
||||
if (!results) {
|
||||
const { currentPosts, totalPage } = slicePosts(posts, pageNum, options.settings.pagination.tags);
|
||||
if (totalPage === 0) {
|
||||
return Astro.redirect('/404');
|
||||
}
|
||||
|
||||
const { currentPosts, totalPage } = results;
|
||||
---
|
||||
|
||||
<BaseLayout title={`标签 “${tag.name}”`}>
|
||||
|
Loading…
Reference in New Issue
Block a user