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