Skip to content

Commit 7ba8388

Browse files
committed
feat: add pagination to projects
1 parent 8dab17c commit 7ba8388

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/components/Navbar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const Navbar: Component = () => {
4040
<TablerHomeFilled />
4141
</NavItem>
4242
<HStack gap="4">
43-
<a href="/projects">Projects</a>
43+
<a href="/projects/1">Projects</a>
4444
<a href="/blog">Blog</a>
4545
<Divider orientation="vertical" thickness="2" height="1em" />
4646
<NavItem

src/pages/projects.astro renamed to src/pages/projects/[page].astro

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
---
2-
import { getCollection } from "astro:content";
2+
import type { GetStaticPaths, Page } from "astro";
3+
import { CollectionEntry, getCollection } from "astro:content";
34
import { css } from "styled-system/css";
45
import MDContainer from "~/components/MDContainer.astro";
56
import ProjectCard from "~/components/ProjectCard.astro";
67
import BaseLayout from "~/layouts/BaseLayout.astro";
78
8-
const projects = await getCollection("projects");
9+
export const getStaticPaths = (async ({ paginate }) => {
10+
const projects = (await getCollection("projects")).sort(
11+
(a, b) => b.data.priority - a.data.priority,
12+
);
13+
14+
return paginate(projects, { pageSize: 4 });
15+
}) satisfies GetStaticPaths;
16+
17+
interface Props {
18+
page: Page<CollectionEntry<"projects">>;
19+
}
20+
21+
const { page } = Astro.props;
922
---
1023

1124
<BaseLayout title="Projects | TheComputerM">
@@ -15,11 +28,7 @@ const projects = await getCollection("projects");
1528
Some of my most cherished and meticulously developed projects.
1629
</p>
1730
<hr />
18-
{
19-
projects
20-
.sort((a, b) => b.data.priority - a.data.priority)
21-
.map((project) => <ProjectCard project={project} />)
22-
}
31+
{page.data.map((project) => <ProjectCard project={project} />)}
2332
<hr />
2433
<p>
2534
See more of my work and other open-source contributions over on my

src/pages/projects/index.astro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
return Astro.redirect("/projects/1");
3+
---

0 commit comments

Comments
 (0)