Fix category index thumbnail

This commit is contained in:
itsfinniii
2026-04-27 16:40:53 +02:00
parent 4a9d0fb273
commit c112a69f0e
3 changed files with 20 additions and 5 deletions

View File

@@ -23,7 +23,7 @@ const categories = await getAllCategories(settings);
<a href={getCategoryRoute(settings.photo, category)} class="group relative block w-[70%] overflow-hidden rounded-2xl shadow-md"> <a href={getCategoryRoute(settings.photo, category)} class="group relative block w-[70%] overflow-hidden rounded-2xl shadow-md">
<div> <div>
<Image <Image
src={getImageUrl(category.thumbnail.url)} src={category.thumbnail.url}
alt={category.title} alt={category.title}
width={category.thumbnail.width} width={category.thumbnail.width}
height={category.thumbnail.height} height={category.thumbnail.height}

View File

@@ -2,7 +2,7 @@ import { createDirectusConnection } from "@/lib/directus";
import { print } from "graphql"; import { print } from "graphql";
import getCategories from '@/graphql/photos/getCategories.graphql'; import getCategories from '@/graphql/photos/getCategories.graphql';
import getCategory from '@/graphql/photos/getCategory.graphql'; import getCategory from '@/graphql/photos/getCategory.graphql';
import { getImageSize } from "@/lib/images"; import { getImageSize, getImageUrl } from "@/lib/images";
export async function getAllCategories(settings: GlobalSettings): Promise<PhotoAlbumCategory[]> { export async function getAllCategories(settings: GlobalSettings): Promise<PhotoAlbumCategory[]> {
const client = await createDirectusConnection(); const client = await createDirectusConnection();
@@ -11,15 +11,15 @@ export async function getAllCategories(settings: GlobalSettings): Promise<PhotoA
let categories: PhotoAlbumCategory[] = []; let categories: PhotoAlbumCategory[] = [];
result["Photo_Categories"].forEach((photoCategoryRecord: any) => { result["Photo_Categories"].forEach((photoCategoryRecord: any) => {
const imageSize = const imageSize = getImageSize(photoCategoryRecord["thumbnail"]["width"],
getImageSize(photoCategoryRecord["thumbnail"]["width"], photoCategoryRecord["thumbnail"]["height"], 1.5); photoCategoryRecord["thumbnail"]["height"], 1.5);
categories.push({ categories.push({
id: photoCategoryRecord["id"], id: photoCategoryRecord["id"],
title: photoCategoryRecord["title"], title: photoCategoryRecord["title"],
url: photoCategoryRecord["url"], url: photoCategoryRecord["url"],
thumbnail: { thumbnail: {
url: photoCategoryRecord["thumbnail"]["filename_disk"], url: getImageUrl(photoCategoryRecord["thumbnail"]["filename_disk"]),
width: imageSize.width, width: imageSize.width,
height: imageSize.height height: imageSize.height
} }

View File

@@ -97,6 +97,21 @@ export async function getPage(settings: GlobalSettings, route: string): Promise<
const allCategories = await getAllCategories(settings); const allCategories = await getAllCategories(settings);
const lastCategory = allCategories[0]; const lastCategory = allCategories[0];
const resizedThumbnail = getImageSize(lastCategory.thumbnail.width, lastCategory.thumbnail.height, 0.756);
const thumbnail = await getImage({
src: lastCategory.thumbnail.url,
width: resizedThumbnail.width,
height: resizedThumbnail.height,
format: "jpeg"
});
lastCategory.thumbnail = {
url: `${settings.website.domainName}${thumbnail.src}`,
width: resizedThumbnail.width,
height: resizedThumbnail.height
}
return { return {
route: route, route: route,
pageType: "PhotoCategoryIndex", pageType: "PhotoCategoryIndex",