From 0bb52c68180e7f27f34e130cf4e16ae67c05eb35 Mon Sep 17 00:00:00 2001
From: itsfinniii <102350242+itsfinniii@users.noreply.github.com>
Date: Sat, 28 Mar 2026 13:00:12 +0100
Subject: [PATCH] Create last albums and fix filename_download in GraphQL
---
astro/src/components/web/LastAlbums.astro | 87 +++++++++++++++++++
astro/src/components/webpage/Webpage.astro | 2 +
astro/src/content/photos/albums.ts | 82 ++++++++++++++++-
astro/src/graphql/photos/getAlbum.graphql | 4 +-
astro/src/graphql/photos/getAlbums.graphql | 4 +-
.../src/graphql/photos/getCategories.graphql | 2 +-
.../src/graphql/photos/getLastAlbums.graphql | 51 +++++++++++
astro/src/graphql/photos/getPhotos.graphql | 4 +-
8 files changed, 228 insertions(+), 8 deletions(-)
create mode 100644 astro/src/components/web/LastAlbums.astro
create mode 100644 astro/src/graphql/photos/getLastAlbums.graphql
diff --git a/astro/src/components/web/LastAlbums.astro b/astro/src/components/web/LastAlbums.astro
new file mode 100644
index 0000000..44bbccb
--- /dev/null
+++ b/astro/src/components/web/LastAlbums.astro
@@ -0,0 +1,87 @@
+---
+import { getLastAlbums } from "@/content/photos/albums";
+import { getSettings } from "@/content/settings/settings";
+import CalendarIcon from "@/icons/CalendarIcon.astro";
+import { getImageUrl } from "@/lib/images";
+import { getAlbumRoute } from "@/lib/routing";
+import { Image } from "astro:assets";
+
+interface Props {
+ albums: LastGalleriesComponent;
+}
+
+function calculateSizeClasses(amount: number, length: number) {
+ if (amount === 2 || length <= 2) {
+ return "lg:w-[45%] w-full";
+ }
+ else {
+ return "lg:w-[31%] w-full";
+ }
+}
+const albums = Astro.props.albums;
+const settings = await getSettings();
+const lastAlbums = await getLastAlbums(albums.amount);
+const size = calculateSizeClasses(albums.amount, lastAlbums.length);
+
+const testAlbums = [...lastAlbums, ...lastAlbums, ...lastAlbums, ...lastAlbums];
+---
+
+{ settings.photo.enabled && (
+
+
+
+ { testAlbums.length >= 4 ? (
+
+
+ ) : (
+
+ ) }
+
+) }
\ No newline at end of file
diff --git a/astro/src/components/webpage/Webpage.astro b/astro/src/components/webpage/Webpage.astro
index dcdc7c4..6fe6472 100644
--- a/astro/src/components/webpage/Webpage.astro
+++ b/astro/src/components/webpage/Webpage.astro
@@ -8,6 +8,7 @@ import EquipmentTable from '../web/EquipmentTable.astro';
import Reviews from '../web/Reviews.astro';
import LastBlogs from '../web/LastBlogs.astro';
import LastProjects from '../web/LastProjects.astro';
+import LastAlbums from '../web/LastAlbums.astro';
interface Props {
webpage: WebpageComponent[];
@@ -30,6 +31,7 @@ console.log(Astro.props.webpage);
{ component.component === "Reviews" && }
{ component.component === "LastBlogs" && }
{ component.component === "LastProjects" && }
+ { component.component === "LastGalleries" && }
)) }
diff --git a/astro/src/content/photos/albums.ts b/astro/src/content/photos/albums.ts
index bd4296c..32cd799 100644
--- a/astro/src/content/photos/albums.ts
+++ b/astro/src/content/photos/albums.ts
@@ -2,6 +2,7 @@ import { createDirectusConnection } from "@/lib/directus";
import { print } from "graphql";
import getAlbums from '@/graphql/photos/getAlbums.graphql';
import getAlbumItem from '@/graphql/photos/getAlbum.graphql';
+import getLastAlbumsQuery from '@/graphql/photos/getLastAlbums.graphql';
import { formatDate } from "@/lib/dates";
export async function getAllAlbums(settings: GlobalSettings): Promise {
@@ -22,6 +23,7 @@ export async function getAllAlbums(settings: GlobalSettings): Promise {
+ let dates: string[] = [
+ albumRecord["date_created"],
+ albumRecord["date_updated"],
+ albumRecord["thumbnail"]["created_on"],
+ ];
+
+ const album: PhotoAlbum = {
+ exists: true,
+ type: "PhotoAlbum",
+ title: albumRecord["title"],
+ description: albumRecord["description"],
+ url: albumRecord["url"],
+ startDate: albumRecord["start_date"],
+ endDate: albumRecord["end_date"],
+ location: albumRecord["location"],
+ category: {
+ id: albumRecord["category"][0]["Photo_Categories_id"]["id"],
+ title: albumRecord["category"][0]["Photo_Categories_id"]["title"],
+ url: albumRecord["category"][0]["Photo_Categories_id"]["url"],
+ thumbnail: {
+ url: albumRecord["category"][0]["Photo_Categories_id"]["thumbnail"]["filename_disk"],
+ height: albumRecord["category"][0]["Photo_Categories_id"]["thumbnail"]["height"],
+ width: albumRecord["category"][0]["Photo_Categories_id"]["thumbnail"]["width"]
+ }
+ },
+ thumbnail: {
+ url: albumRecord["thumbnail"]["filename_disk"],
+ height: albumRecord["thumbnail"]["height"],
+ width: albumRecord["thumbnail"]["width"]
+ },
+ photos: [],
+ lastModified: new Date()
+ };
+
+ albumRecord["photos"].forEach((photoRecord: any) => {
+ album.photos.push({
+ id: photoRecord["id"],
+ photo: {
+ url: photoRecord["photo"]["filename_disk"],
+ width: photoRecord["photo"]["width"],
+ height: photoRecord["photo"]["height"]
+ },
+ text: photoRecord["text"]
+ });
+
+ dates.push(photoRecord["date_created"]);
+ dates.push(photoRecord["date_updated"]);
+ dates.push(photoRecord["photo"]["created_on"]);
+ });
+
+ if (dates.filter(e => e !== null).length === 0) {
+ album.lastModified = new Date();
+ }
+ else {
+ const sortedDates: string[] = dates.sort((a: string, b: string) => {
+ return new Date(b).getTime() - new Date(a).getTime();
+ });
+
+ album.lastModified = new Date(sortedDates[0]);
+ }
+
+ albums.push(album);
+ });
+
+ return albums;
+}
diff --git a/astro/src/graphql/photos/getAlbum.graphql b/astro/src/graphql/photos/getAlbum.graphql
index 3fd2a53..741e23e 100644
--- a/astro/src/graphql/photos/getAlbum.graphql
+++ b/astro/src/graphql/photos/getAlbum.graphql
@@ -9,7 +9,7 @@ query getAllAlbums($route: String!) {
thumbnail {
id,
created_on,
- filename_download,
+ filename_disk,
width,
height
},
@@ -27,7 +27,7 @@ query getAllAlbums($route: String!) {
thumbnail {
id,
created_on,
- filename_download,
+ filename_disk,
width,
height
}
diff --git a/astro/src/graphql/photos/getAlbums.graphql b/astro/src/graphql/photos/getAlbums.graphql
index 4a711fd..bc8d43b 100644
--- a/astro/src/graphql/photos/getAlbums.graphql
+++ b/astro/src/graphql/photos/getAlbums.graphql
@@ -9,7 +9,7 @@ query getAllAlbums($date: String!) {
thumbnail {
id,
created_on,
- filename_download,
+ filename_disk,
width,
height
},
@@ -27,7 +27,7 @@ query getAllAlbums($date: String!) {
thumbnail {
id,
created_on,
- filename_download,
+ filename_disk,
width,
height
}
diff --git a/astro/src/graphql/photos/getCategories.graphql b/astro/src/graphql/photos/getCategories.graphql
index df14b44..c97b505 100644
--- a/astro/src/graphql/photos/getCategories.graphql
+++ b/astro/src/graphql/photos/getCategories.graphql
@@ -9,7 +9,7 @@ query getAllCategories {
thumbnail {
id,
created_on,
- filename_download,
+ filename_disk,
width,
height
}
diff --git a/astro/src/graphql/photos/getLastAlbums.graphql b/astro/src/graphql/photos/getLastAlbums.graphql
new file mode 100644
index 0000000..d8ed36e
--- /dev/null
+++ b/astro/src/graphql/photos/getLastAlbums.graphql
@@ -0,0 +1,51 @@
+query getLastAlbums($date: String!, $limit: Int!) {
+ Photo_Albums(sort: ["-start_date", "-date_created"], filter: { status: { _eq: "published" }, start_date: { _lte: $date }, category: { Photo_Categories_id: { status: { _eq: "published" } } } }, limit: $limit) {
+ id,
+ date_created,
+ date_updated,
+ title,
+ description,
+ url,
+ thumbnail {
+ id,
+ created_on,
+ filename_disk,
+ width,
+ height
+ },
+ start_date,
+ end_date,
+ location,
+ category {
+ Photo_Categories_id {
+ id,
+ status,
+ date_created,
+ date_updated,
+ title,
+ url,
+ thumbnail {
+ id,
+ created_on,
+ filename_disk,
+ width,
+ height
+ }
+ }
+ },
+ photos(filter: { status: { _eq: "published" } }) {
+ id,
+ date_created,
+ date_updated,
+ photo {
+ id,
+ created_on,
+ filename_disk,
+ width,
+ height
+ },
+ text,
+ sort
+ }
+ }
+}
diff --git a/astro/src/graphql/photos/getPhotos.graphql b/astro/src/graphql/photos/getPhotos.graphql
index 456f8d6..966ea1f 100644
--- a/astro/src/graphql/photos/getPhotos.graphql
+++ b/astro/src/graphql/photos/getPhotos.graphql
@@ -9,7 +9,7 @@ query getPhotos($albumUrl: String!) {
thumbnail {
id,
created_on,
- filename_download,
+ filename_disk,
width,
height
},
@@ -27,7 +27,7 @@ query getPhotos($albumUrl: String!) {
thumbnail {
id,
created_on,
- filename_download,
+ filename_disk,
width,
height
}