From be02d749ddeba866673ecf3f41b5f7533a092e60 Mon Sep 17 00:00:00 2001 From: itsfinniii <102350242+itsfinniii@users.noreply.github.com> Date: Sun, 26 Apr 2026 16:12:57 +0200 Subject: [PATCH] Add pagination to album page --- astro/src/components/common/Pagination.astro | 24 ++++++++++++++++++++ astro/src/components/photos/Album.astro | 18 +++++++++++---- 2 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 astro/src/components/common/Pagination.astro diff --git a/astro/src/components/common/Pagination.astro b/astro/src/components/common/Pagination.astro new file mode 100644 index 0000000..36624a8 --- /dev/null +++ b/astro/src/components/common/Pagination.astro @@ -0,0 +1,24 @@ +--- +interface Props { + page: number; + totalPages: number; + urlTemplate: string; +} + +const { page, totalPages, urlTemplate } = Astro.props; +--- + +
+ { totalPages < 7 && ( + <> + { [...Array(totalPages)].map((_: number, i: number) => ( + + {i + 1} + + )) } + + ) } +
diff --git a/astro/src/components/photos/Album.astro b/astro/src/components/photos/Album.astro index e2865b9..66e4b25 100644 --- a/astro/src/components/photos/Album.astro +++ b/astro/src/components/photos/Album.astro @@ -1,8 +1,9 @@ --- -import { getPhotoRoute } from '@/lib/routing'; +import { getAlbumRoute, getPhotoRoute } from '@/lib/routing'; import { AlbumPhotos } from './Album.tsx'; import { getImageSize, getImageUrl } from '@/lib/images'; import { getSettings } from '@/content/settings/settings'; +import Pagination from '../common/Pagination.astro'; interface Props { page: PhotoAlbumPage; @@ -12,12 +13,13 @@ const settings = await getSettings(); const album = Astro.props.page; const pageNumber = Astro.props.page.pageNumber; -const startNumber = (pageNumber - 1) * settings.photo.album.perPage; -const endNumber = pageNumber * settings.photo.album.perPage; +const totalAlbumPages = Math.ceil(album.photos.length / settings.photo.album.perPage); +const sliceStartNumber = (pageNumber - 1) * settings.photo.album.perPage; +const sliceEndNumber = pageNumber * settings.photo.album.perPage; const remappedPhotos: PhotoAlbumGalleryItem[] = []; -album.photos.slice(startNumber, endNumber).forEach((photo) => { +album.photos.slice(sliceStartNumber, sliceEndNumber).forEach((photo) => { const resizedImage = getImageSize(photo.photo.width, photo.photo.height, 0.67); remappedPhotos.push({ @@ -41,5 +43,13 @@ album.photos.slice(startNumber, endNumber).forEach((photo) => {

{album.title}

+ + { totalAlbumPages > 1 && ( + + ) }