-
-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for blogpost from generic platforms (#2555)
Co-authored-by: BekahHW <34313413+BekahHW@users.noreply.github.com>
- Loading branch information
Showing
10 changed files
with
829 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
components/molecules/GenericBlogOpenGraphImg/generic-blog-open-graph-img.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { useEffect, useState } from "react"; | ||
import InvalidImage from "img/icons/fallback-image-disabled-square.svg"; | ||
|
||
interface GenericBlogOpenGraphImgProps { | ||
blogLink: string; | ||
className?: string; | ||
} | ||
|
||
const GenericBlogOpenGraphImg = ({ blogLink, className }: GenericBlogOpenGraphImgProps): JSX.Element => { | ||
const [socialImage, setSocialImage] = useState(""); | ||
const [isValid, setIsValid] = useState(false); | ||
|
||
useEffect(() => { | ||
const fetchBlogOGImage = async () => { | ||
const response = await fetch(`/api/fetchOGData/?url=${blogLink}`); | ||
const data = await response.json(); | ||
return data; | ||
}; | ||
|
||
fetchBlogOGImage().then(({ response }) => { | ||
if (response) { | ||
setSocialImage(response?.image?.url || response?.image?.url[response?.image?.url.length - 1]); | ||
setIsValid(true); | ||
} else { | ||
setSocialImage(""); | ||
setIsValid(false); | ||
} | ||
}); | ||
}, [blogLink]); | ||
|
||
return ( | ||
<> | ||
{socialImage && ( | ||
<picture className={className}> | ||
<img | ||
src={isValid ? socialImage : InvalidImage} | ||
alt={isValid ? "blog og image" : "invalid url image"} | ||
className={"border border-slate-100 rounded-lg"} | ||
/> | ||
</picture> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default GenericBlogOpenGraphImg; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.