diff --git a/src/components/PageNavigator.astro b/src/components/PageNavigator.astro new file mode 100644 index 00000000..21740780 --- /dev/null +++ b/src/components/PageNavigator.astro @@ -0,0 +1,13 @@ +--- +import type { Page } from 'astro'; + +type Props = Pick + +const { currentPage, lastPage, url: { prev, next } } = Astro.props; +--- + +
+ Prev + {currentPage} of {lastPage} + Next +
diff --git a/src/pages/index.astro b/src/pages/index.astro index 50a52657..168a26e7 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -1,20 +1,4 @@ --- -import BaseLayout from '../layouts/BaseLayout.astro'; -import Hero from '../components/Hero.astro'; -import CardList from '../components/CardList.astro'; -import Modal from '../components/Modal.astro'; - -import { getCollection } from 'astro:content'; - -const terms = await getCollection("terms"); +// Homepage. Not yet implemented so just redirect to the main content +return Astro.redirect("/terms/1"); --- - - - - - - - - - - diff --git a/src/pages/terms/[page].astro b/src/pages/terms/[page].astro new file mode 100644 index 00000000..787d5e31 --- /dev/null +++ b/src/pages/terms/[page].astro @@ -0,0 +1,34 @@ +--- +import BaseLayout from '@/layouts/BaseLayout.astro'; +import Hero from '@/components/Hero.astro'; +import CardList from '@/components/CardList.astro'; +import Modal from '@/components/Modal.astro'; +import PageNavigator from '@/components/PageNavigator.astro'; + +import { getCollection } from 'astro:content'; +import type { CollectionEntry } from 'astro:content'; +import type { GetStaticPathsOptions, GetStaticPathsResult, Page } from 'astro'; + +// This type is automatically picked up by astro for Astro.props +type Props = { + page: Page>; +} + +export async function getStaticPaths({ paginate }: GetStaticPathsOptions): Promise { + const terms = await getCollection("terms"); + return paginate(terms, { pageSize: 20 }); +} + +const { page: { data: terms, ...page } } = Astro.props; +--- + + + + + + + + + + + diff --git a/src/styles/global.css b/src/styles/global.css index 3816abda..dc8c2b46 100644 --- a/src/styles/global.css +++ b/src/styles/global.css @@ -506,3 +506,24 @@ body.modal-open { #modal-link:hover { color: deeppink; } + +/* ======= Pagination ======= */ +.container__pagination { + gap: 2rem; + display: flex; + align-items: center; + justify-content: center; + padding-bottom: 1rem; + padding-inline: 1rem; +} + +/* Simulates the `disabled` attribute on `a` tags as they do not support `disabled` */ +.container__pagination > a:not([href]) { + pointer-events: none; + cursor: default; + opacity: 0.5; +} + +.no-decoration { + text-decoration: none; +} diff --git a/tsconfig.json b/tsconfig.json index 42b60ea0..d4214247 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,8 +7,12 @@ "noUnusedParameters": false, "allowJs": true, "strictNullChecks": true, - "noImplicitReturns": false + "noImplicitReturns": false, + "baseUrl": ".", + "paths": { + "@/*": ["src/*"] + } }, - "include": ["src/**/*", "public/card-actions.js"], + "include": ["src"], "extends": ["astro/tsconfigs/strictest"] }