@@ -51,7 +51,7 @@ export async function renderFeed(block) {
51
51
}
52
52
53
53
function isImgUrl ( url ) {
54
- return / \. ( j p g | j p e g | p n g | w e b p | a v i f | g i f | s v g ) $ / . test ( url )
54
+ return / \. ( j p g | j p e g | p n g | w e b p | a v i f | g i f | s v g ) $ / . test ( url ) ;
55
55
}
56
56
57
57
// logic to render blog list home page
@@ -69,11 +69,13 @@ export async function fetchBlogContent(url) {
69
69
} ) ;
70
70
// render images as img tags rather than linka
71
71
doc . querySelectorAll ( 'a' ) . forEach ( ( link ) => {
72
- const url = new URL ( link . href ) ;
73
- const pathname = url . pathname ;
74
- if ( isImgUrl ( url ) ) {
75
- const imgName = pathname ?. substring ( pathname ?. lastIndexOf ( "/" ) + 1 , pathname ?. lastIndexOf ( "." ) ) ;
76
- const img = createTag ( 'img' , { src : pathname , alt : imgName , width : '100%' , loading : 'eager' } ) ;
72
+ const linkSrc = new URL ( link . href ) ;
73
+ const { pathname } = linkSrc ;
74
+ if ( isImgUrl ( pathname ) ) {
75
+ const imgName = pathname . substring ( pathname . lastIndexOf ( '/' ) + 1 , pathname . lastIndexOf ( '.' ) ) ;
76
+ const img = createTag ( 'img' , {
77
+ src : pathname , alt : imgName , width : '100%' , loading : 'eager' ,
78
+ } ) ;
77
79
link . parentElement . classList . add ( 'image-wrapper' ) ;
78
80
link . replaceWith ( img ) ;
79
81
}
@@ -107,7 +109,6 @@ export async function renderBlog(block) {
107
109
// eslint-disable-next-line max-len
108
110
const truncatedContent = latestBlogContent . substring ( 0 , Math . floor ( latestBlogContent . length * 0.75 ) ) ;
109
111
latestBlogItem . innerHTML = truncatedContent ;
110
-
111
112
}
112
113
113
114
const readMoreButton = createTag ( 'a' , { href : latestBlog . path , class : 'read-more button primary large' } , 'Read More' ) ;
0 commit comments