Skip to content

Commit

Permalink
fix: medium images not working
Browse files Browse the repository at this point in the history
  • Loading branch information
suvnshr committed Dec 19, 2024
1 parent 6d23887 commit 0ef232b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion components/BlogCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { htmlToText } from "html-to-text";
import OuterLink from "./OuterLink";
import Margin from "./Margin";
import { OpenInNewOutlined } from "@material-ui/icons";
import { extractImagePaths } from "../utils/extractImagePaths";

const useStyles = makeStyles({
root: {
Expand Down Expand Up @@ -57,12 +58,14 @@ export default function BlogCard({
});
}, []);

const imagePaths = extractImagePaths(description)

return (
<Card className={classes.root}>
<CardMedia
component="img"
height="140"
image={thumbnail}
image={thumbnail || imagePaths?.[0]}
className={classes.media}
alt={title}
title={title}
Expand Down
6 changes: 6 additions & 0 deletions utils/extractImagePaths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function extractImagePaths(inputString) {
const regex =
/(?:https?:\/\/.*\.(?:jpg|jpeg|png|gif|bmp|svg))|(?:\/[^\s]*\.(?:jpg|jpeg|png|gif|bmp|svg))/gi;
const imagePaths = inputString.match(regex);
return imagePaths || [];
}

0 comments on commit 0ef232b

Please sign in to comment.