GNXSOFT.COM
This commit is contained in:
36
gnx-react/lib/imageUtils.ts
Normal file
36
gnx-react/lib/imageUtils.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
// Image utility functions
|
||||
|
||||
export const FALLBACK_IMAGES = {
|
||||
BLOG: '/images/blog/blog-poster.png',
|
||||
CASE_STUDY: '/images/case/poster.png',
|
||||
SERVICE: '/images/service/thumb-one.png',
|
||||
GALLERY: '/images/masonry/one.png',
|
||||
BANNER: '/images/banner/banner-bg.png',
|
||||
DEFAULT: '/images/logo.png'
|
||||
};
|
||||
|
||||
export function getValidImageUrl(imageUrl?: string, fallback?: string): string {
|
||||
if (!imageUrl || imageUrl.trim() === '') {
|
||||
return fallback || FALLBACK_IMAGES.DEFAULT;
|
||||
}
|
||||
|
||||
// If it's already a full URL, return as is
|
||||
if (imageUrl.startsWith('http://') || imageUrl.startsWith('https://')) {
|
||||
return imageUrl;
|
||||
}
|
||||
|
||||
// If it starts with /, it's already a public path
|
||||
if (imageUrl.startsWith('/')) {
|
||||
return imageUrl;
|
||||
}
|
||||
|
||||
// Otherwise, assume it's a public path and add /
|
||||
return `/${imageUrl}`;
|
||||
}
|
||||
|
||||
export function getImageAlt(title?: string, fallback: string = 'Image'): string {
|
||||
return title ? `${title} - Image` : fallback;
|
||||
}
|
||||
|
||||
// Export getValidImageAlt as an alias for getImageAlt for backward compatibility
|
||||
export const getValidImageAlt = getImageAlt;
|
||||
Reference in New Issue
Block a user