From bc11be5669ef51bfd44fa6b347fea5f15fb20b95 Mon Sep 17 00:00:00 2001 From: itsfinniii <102350242+itsfinniii@users.noreply.github.com> Date: Sun, 15 Mar 2026 13:06:30 +0100 Subject: [PATCH] Fix some more routing related things --- astro/src/content/photos/albums.ts | 1 + astro/src/content/photos/categories.ts | 25 +++++++++++++ .../src/graphql/photos/getCategories.graphql | 17 +++++++++ astro/src/lib/routing.ts | 35 ++++++++++++++++++- astro/src/types/photos/album.d.ts | 1 + 5 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 astro/src/content/photos/categories.ts create mode 100644 astro/src/graphql/photos/getCategories.graphql diff --git a/astro/src/content/photos/albums.ts b/astro/src/content/photos/albums.ts index 6794408..2137357 100644 --- a/astro/src/content/photos/albums.ts +++ b/astro/src/content/photos/albums.ts @@ -28,6 +28,7 @@ export async function getAllAlbums(settings: GlobalSettings): Promise { + const client = await createDirectusConnection(); + const result = await client.query(print(getCategories)); + + let categories: PhotoAlbumCategory[] = []; + + result["Photo_Categories"].forEach((photoCategoryRecord: any) => { + categories.push({ + id: photoCategoryRecord["id"], + title: photoCategoryRecord["title"], + url: photoCategoryRecord["url"], + thumbnail: { + url: photoCategoryRecord["thumbnail"]["filename_disk"], + width: photoCategoryRecord["thumbnail"]["width"], + height: photoCategoryRecord["thumbnail"]["height"] + } + }); + }); + + return categories; +} \ No newline at end of file diff --git a/astro/src/graphql/photos/getCategories.graphql b/astro/src/graphql/photos/getCategories.graphql new file mode 100644 index 0000000..df14b44 --- /dev/null +++ b/astro/src/graphql/photos/getCategories.graphql @@ -0,0 +1,17 @@ +query getAllCategories { + Photo_Categories(filter: { status: { _eq: "published" } }) { + id, + date_created, + date_updated, + status, + title, + url, + thumbnail { + id, + created_on, + filename_download, + width, + height + } + } +} diff --git a/astro/src/lib/routing.ts b/astro/src/lib/routing.ts index 9d33d80..9cfd101 100644 --- a/astro/src/lib/routing.ts +++ b/astro/src/lib/routing.ts @@ -3,6 +3,7 @@ import { getAllWebpages } from "@/content/pages/pages"; import { getAllAlbums } from "@/content/photos/albums"; import { getAllProjects } from "@/content/projects/projects"; import { getPhotoHash } from "./hash"; +import { getAllCategories } from "@/content/photos/categories"; export async function getAllRoutesList(settings: GlobalSettings): Promise { let routes: string[] = []; @@ -28,10 +29,36 @@ export async function getAllRoutesList(settings: GlobalSettings): Promise { + let albums = galleries.filter(g => g.category.id === category.id); + const pages = Math.ceil(albums.length / settings.photo.category.perPage); + const categoryRoute = getCategoryRoute(settings.photo, category); + + for (let i = 0; i < pages; i++) { + if (i !== 0) { + routes.push(`${categoryRoute}/${i + 1}`); + } + else { + routes.push(`${categoryRoute}`); + } + } + }); + galleries.forEach((gallery) => { - routes.push(getAlbumRoute(settings.photo, gallery)); + const pages = Math.ceil(gallery.photos.length / settings.photo.album.perPage); + const galleryRoute = getAlbumRoute(settings.photo, gallery); + + for (let i = 0; i < pages; i++) { + if (i !== 0) { + routes.push(`${galleryRoute}/${i + 1}`); + } + else { + routes.push(`${galleryRoute}`); + } + } gallery.photos.forEach((photo) => { routes.push(getPhotoRoute(settings.photo, gallery, photo)); @@ -64,6 +91,12 @@ export function getProjectRoute(projectSettings: ProjectSettings, project: Proje .replace(/\/+/g, '/'); } +export function getCategoryRoute(photoSettings: WebsitePhotoSettings, category: PhotoAlbumCategory) { + return photoSettings.category.routeTemplate + .replaceAll("%C", category.url) + .replace(/\/+/g, '/'); +} + export function getAlbumRoute(photoSettings: WebsitePhotoSettings, album: PhotoAlbum) { const date = new Date(album.startDate); diff --git a/astro/src/types/photos/album.d.ts b/astro/src/types/photos/album.d.ts index 14e1f44..d432c5b 100644 --- a/astro/src/types/photos/album.d.ts +++ b/astro/src/types/photos/album.d.ts @@ -16,6 +16,7 @@ type PhotoAlbum = { } type PhotoAlbumCategory = { + id: string; title: string; url: string; thumbnail: PhotoProps;