chore: shorten pagination

This commit is contained in:
Stefan Imhoff
2023-05-21 09:38:06 +02:00
parent 6ddae638ac
commit 11c497c6bd
2 changed files with 14 additions and 14 deletions

View File

@@ -17,14 +17,14 @@ export async function getStaticPaths() {
params: { slug: entry.slug }, params: { slug: entry.slug },
props: { props: {
entry, entry,
nextPost: next:
index + 1 === numberOfPages ? { slug: null, data: null } : haikuEntries[index + 1], index + 1 === numberOfPages ? { slug: null, data: null } : haikuEntries[index + 1],
prevPost: index === 0 ? {} : haikuEntries[index - 1], prev: index === 0 ? {} : haikuEntries[index - 1],
}, },
})); }));
} }
const { entry, prevPost, nextPost } = Astro.props; const { entry, prev, next } = Astro.props;
--- ---
<BaseLayout title={`Haiku ${entry.slug}`} header={false} footer={false}> <BaseLayout title={`Haiku ${entry.slug}`} header={false} footer={false}>
@@ -54,9 +54,9 @@ const { entry, prevPost, nextPost } = Astro.props;
</div> </div>
</div> </div>
<Pagination <Pagination
nextText={`Haiku ${nextPost.slug}`} nextText={`Haiku ${next.slug}`}
nextUrl={nextPost.slug && `/haiku/${nextPost.slug}`} nextUrl={next.slug && `/haiku/${next.slug}`}
previousText={`Haiku ${prevPost.slug}`} previousText={`Haiku ${prev.slug}`}
previousUrl={prevPost.slug && `/haiku/${prevPost.slug}`} previousUrl={prev.slug && `/haiku/${prev.slug}`}
/> />
</BaseLayout> </BaseLayout>

View File

@@ -20,16 +20,16 @@ export async function getStaticPaths() {
params: { slug: entry.slug }, params: { slug: entry.slug },
props: { props: {
entry, entry,
nextPost: next:
index + 1 === numberOfPages index + 1 === numberOfPages
? { slug: null, data: null } ? { slug: null, data: null }
: projectEntries[index + 1], : projectEntries[index + 1],
prevPost: index === 0 ? {} : projectEntries[index - 1], prev: index === 0 ? {} : projectEntries[index - 1],
}, },
})); }));
} }
const { entry, prevPost, nextPost } = Astro.props; const { entry, prev, next } = Astro.props;
const { Content } = await entry.render(); const { Content } = await entry.render();
--- ---
@@ -48,9 +48,9 @@ const { Content } = await entry.render();
</article> </article>
<Pagination <Pagination
nextText={nextPost.data?.title} nextText={next.data?.title}
nextUrl={nextPost.slug && `/projects/${nextPost.slug}`} nextUrl={next.slug && `/projects/${next.slug}`}
previousText={prevPost.data?.title} previousText={prev.data?.title}
previousUrl={prevPost.slug && `/projects/${prevPost.slug}`} previousUrl={prev.slug && `/projects/${prev.slug}`}
/> />
</GridLayout> </GridLayout>