File tree Expand file tree Collapse file tree 1 file changed +16
-6
lines changed
Expand file tree Collapse file tree 1 file changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -25,14 +25,24 @@ const App: FC = () => {
2525 const imageRef = useRef < HTMLImageElement > ( null ) ;
2626
2727 const fetchImage = async ( url : string ) => {
28- const res = await fetch ( `https://cors-anywhere.herokuapp.com/${ url } ` ) ;
29- const html = await res . text ( ) ;
28+ try {
29+ const res = await fetch ( `https://cors-anywhere.herokuapp.com/${ url } ` ) ;
30+ const html = await res . text ( ) ;
3031
31- const parser = new DOMParser ( ) ;
32- const doc = parser . parseFromString ( html , "text/html" ) ;
33- const node = doc . head . querySelector ( "meta[property='og:image']" ) ;
32+ const parser = new DOMParser ( ) ;
33+ const doc = parser . parseFromString ( html , "text/html" ) ;
34+ const node = doc . head . querySelector ( "meta[property='og:image']" ) ;
3435
35- loadImage ( node ?. getAttribute ( "content" ) ?? url ) ;
36+ if ( node ) {
37+ const content = node . getAttribute ( "content" ) ;
38+
39+ if ( content ) {
40+ url = content ;
41+ }
42+ }
43+ } catch { } // eslint-disable-line no-empty
44+
45+ loadImage ( url ) ;
3646 } ;
3747
3848 const loadImage = async ( src : string ) => {
You can’t perform that action at this time.
0 commit comments