Skip to content

Commit 4a0964a

Browse files
ekrishnachaitanya2004Xo-TheWeekndSandotech
committed
Enhance ImageMod Component to Support External URLs
Updated the `ImageMod.astro` component to handle both local image paths and external URLs. - Added support for external image URLs by checking if the `src` attribute starts with `http` or `https`. - Modified the image rendering logic to use a standard `img` tag for external URLs and continue using the `Image` component for local images. - Added validation and error logging for local images, ensuring proper handling for both local and external images. This update allows the blog card component to display images from external sources, enhancing flexibility in managing blog content. Co-Authored-By: Krishna Chaitanya Ethamukkala <[email protected]> Co-Authored-By: Diego Santos <[email protected]>
1 parent b882573 commit 4a0964a

File tree

3 files changed

+37
-19
lines changed

3 files changed

+37
-19
lines changed

src/content/blog/english/post-2.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
title: "Building an Image-to-Text Converter with Handwritten Text Recognition"
33
meta_title: ""
44
description: "Image to text"
5-
date: 2022-04-04T05:00:00Z
6-
image: "/images/image-placeholder.png"
5+
date: 2024-09-04T05:00:00Z
6+
image: "https://www.pdfgear.com/pdf-converter/img/how-to-convert-handwriting-to-text-1.png"
77
categories: ["Project","python", "Image text converter"]
88
author: "Krishna Chaitanya"
99
tags: ["Python", "image-to-text"]

src/content/blog/english/post-3.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: "Loan Eligibility Predective Analyser"
33
meta_title: ""
44
description: "This repository presents a comprehensive predictive analytics solution for determining loan eligibility, leveraging advanced machine learning techniques and data preprocessing methodologies. The project is implemented in Google Colab, utilizing a dataset from Kaggle's Loan Data repository, which encompasses a diverse range of attributes pertinent to creditworthiness assessment."
55
date: 2024-09-15T05:00:00Z
6-
image: "/images/image-placeholder.png"
6+
image: "https://cdn-images-1.medium.com/max/720/1*icDC8PUuu71tQCuDzl6zQg.png"
77
categories: ["Project","Python","Software"]
88
author: "Sanjeevan S"
99
tags: ["Machine Learning", "Python3", "Kaggle" , "Pandas" , "Numpy"]

src/layouts/components/ImageMod.astro

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,51 @@ let {
2828
style,
2929
} = Astro.props;
3030
31-
src = `/public${src}`;
31+
// Determine if the src is an external URL or a local path
32+
const isExternal = src.startsWith("http") || src.startsWith("https");
33+
34+
// Handle external and local image paths
35+
const imageSrc = isExternal ? src : `/public${src}`;
3236
3337
// Glob pattern to load images from the /public/images folder
3438
const images = import.meta.glob("/public/images/**/*.{jpeg,jpg,png,gif}");
3539
36-
// Check if the source path is valid
37-
const isValidPath = images[src] ? true : false;
40+
// Check if the source path is valid (only for local images)
41+
const isValidPath = isExternal || images[imageSrc] ? true : false;
3842
39-
// Log a warning message in red if the image is not found
43+
// Log a warning message in red if the image is not found (only for local images)
4044
!isValidPath &&
45+
!isExternal &&
4146
console.error(
42-
`\x1b[31mImage not found - ${src}.\x1b[0m Make sure the image is in the /public/images folder.`,
47+
`\x1b[31mImage not found - ${imageSrc}.\x1b[0m Make sure the image is in the /public/images folder.`,
4348
);
4449
---
4550

4651
{
4752
isValidPath && (
48-
<Image
49-
src={images[src]() as Promise<{ default: ImageMetadata }>}
50-
alt={alt}
51-
width={width}
52-
height={height}
53-
loading={loading}
54-
decoding={decoding}
55-
class={className}
56-
format={format}
57-
style={style}
58-
/>
53+
isExternal ? (
54+
<img
55+
src={imageSrc}
56+
alt={alt}
57+
width={width}
58+
height={height}
59+
loading={loading}
60+
decoding={decoding}
61+
class={className}
62+
style={style}
63+
/>
64+
) : (
65+
<Image
66+
src={images[imageSrc]() as Promise<{ default: ImageMetadata }>}
67+
alt={alt}
68+
width={width}
69+
height={height}
70+
loading={loading}
71+
decoding={decoding}
72+
class={className}
73+
format={format}
74+
style={style}
75+
/>
76+
)
5977
)
6078
}

0 commit comments

Comments
 (0)