Refactor Pagination component to update page size in getStaticPaths
All checks were successful
Test / test (push) Successful in 39s
Test / test (pull_request) Successful in 36s

This commit is contained in:
Valentin Popov 2024-09-13 00:26:08 +00:00
parent 4a821edd50
commit 5217bcb24c
Signed by: Valentin Popov
GPG Key ID: AE3CE523DAAA8401
4 changed files with 20 additions and 45 deletions

View File

@ -1,7 +1,4 @@
--- ---
import Next from "./Pagination/Next.astro";
import Prev from "./Pagination/Prev.astro";
type Props = { type Props = {
readonly nextUrl?: string; readonly nextUrl?: string;
readonly prevUrl?: string; readonly prevUrl?: string;
@ -12,13 +9,27 @@ const { nextUrl, prevUrl } = Astro.props;
<style lang="scss"> <style lang="scss">
div { div {
overflow: hidden; text-align: center;
padding: 3rem 0; }
width: 100%;
span {
margin: 0 2em;
} }
</style> </style>
<div> <div>
{prevUrl && <Prev url={prevUrl} />} {
{nextUrl && <Next url={nextUrl} />} prevUrl && (
<span>
<a href={prevUrl}>&lt; Prev</a>
</span>
)
}
{
nextUrl && (
<span>
<a href={nextUrl}>Next &gt;</a>
</span>
)
}
</div> </div>

View File

@ -1,18 +0,0 @@
---
type Props = {
readonly url: string;
};
const { url } = Astro.props;
---
<style lang="scss">
span {
float: right;
max-width: 40%;
}
</style>
<span>
<a href={url}>Next &gt;</a>
</span>

View File

@ -1,18 +0,0 @@
---
type Props = {
readonly url: string;
};
const { url } = Astro.props;
---
<style lang="scss">
span {
float: left;
max-width: 40%;
}
</style>
<span>
<a href={url}>&lt; Prev</a>
</span>

View File

@ -12,7 +12,7 @@ export const getStaticPaths = (async ({ paginate }) => {
posts.sort((a, b) => b.data.pubDate.getTime() - a.data.pubDate.getTime()); posts.sort((a, b) => b.data.pubDate.getTime() - a.data.pubDate.getTime());
return paginate(posts, { return paginate(posts, {
pageSize: 5, pageSize: 10,
}); });
}) satisfies GetStaticPaths; }) satisfies GetStaticPaths;