feat: thumbnail assets
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Damillora 2024-12-03 00:56:25 +07:00
parent f198ec4e40
commit 5686c93ba3

View File

@ -8,6 +8,14 @@ export const generateAssetUrl = (file: any) => {
return DIRECTUS_URL + "/assets/" + file.id + "/" + file.filename_download; 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) => { export const generateCategoryUrl = (slug: string) => {
return "/" + slug; return "/" + slug;
} }
@ -46,7 +54,7 @@ export const mapIndexPosts = (post: any) => {
return { return {
title: post.title, title: post.title,
feature_image: generateAssetUrl(post.feature_image), feature_image: generateThumbnailUrl(post.feature_image),
authors: [author], authors: [author],
category: category, category: category,
excerpt: post.excerpt, excerpt: post.excerpt,
@ -77,7 +85,7 @@ export const mapAuthor = (author: any) => {
return { return {
name: author.name, name: author.name,
profile_image: generateAssetUrl(author.profile_image), profile_image: generateAssetUrl(author.profile_image),
cover_image: generateAssetUrl(author.cover_image), cover_image: generateThumbnailUrl(author.cover_image),
bio: author.bio, bio: author.bio,
url: generateAuthorUrl(author.slug), url: generateAuthorUrl(author.slug),
website: author.website, website: author.website,
@ -96,7 +104,7 @@ export const mapCategory = (category: any) => {
url: generateCategoryUrl(category.slug), url: generateCategoryUrl(category.slug),
slug: category.slug, slug: category.slug,
description: category.description, 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, id: post.id,
title: post.title, title: post.title,
status: post.status, status: post.status,
feature_image: generateAssetUrl(post.feature_image), feature_image: generateThumbnailUrl(post.feature_image),
authors: [author], authors: [author],
primary_author: author, primary_author: author,
category: category, category: category,