From 5686c93ba3280e9ae235ce8d6fd24a6f2ad98386 Mon Sep 17 00:00:00 2001 From: Damillora Date: Tue, 3 Dec 2024 00:56:25 +0700 Subject: [PATCH] feat: thumbnail assets --- src/lib/content/directusUtils.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/lib/content/directusUtils.ts b/src/lib/content/directusUtils.ts index 131910f..b8fb7f1 100644 --- a/src/lib/content/directusUtils.ts +++ b/src/lib/content/directusUtils.ts @@ -8,6 +8,14 @@ export const generateAssetUrl = (file: any) => { return DIRECTUS_URL + "/assets/" + file.id + "/" + file.filename_download; }; +export const generateThumbnailUrl = (file: any) => { + if (!file) { + return null; + } + return DIRECTUS_URL + "/assets/" + file.id + "/" + file.filename_download + "?key=thumbnail"; +}; + + export const generateCategoryUrl = (slug: string) => { return "/" + slug; } @@ -46,7 +54,7 @@ export const mapIndexPosts = (post: any) => { return { title: post.title, - feature_image: generateAssetUrl(post.feature_image), + feature_image: generateThumbnailUrl(post.feature_image), authors: [author], category: category, excerpt: post.excerpt, @@ -77,7 +85,7 @@ export const mapAuthor = (author: any) => { return { name: author.name, profile_image: generateAssetUrl(author.profile_image), - cover_image: generateAssetUrl(author.cover_image), + cover_image: generateThumbnailUrl(author.cover_image), bio: author.bio, url: generateAuthorUrl(author.slug), website: author.website, @@ -96,7 +104,7 @@ export const mapCategory = (category: any) => { url: generateCategoryUrl(category.slug), slug: category.slug, description: category.description, - cover_image: generateAssetUrl(category.cover_image), + cover_image: generateThumbnailUrl(category.cover_image), } }; @@ -109,7 +117,7 @@ export const mapPost = (post: any) => { id: post.id, title: post.title, status: post.status, - feature_image: generateAssetUrl(post.feature_image), + feature_image: generateThumbnailUrl(post.feature_image), authors: [author], primary_author: author, category: category,