@@ -937,6 +937,7 @@ module.exports = {
937937 // Quickly replaces inline image placeholder URLs with
938938 // actual, SEO-friendly URLs based on `widget._relatedDocs`.
939939 linkImages ( widget , content ) {
940+ console . log ( '----' ) ;
940941 console . log ( 'content' , content ) ;
941942 // "Why no regexps?" We need to do this as quickly as we can.
942943 // indexOf and lastIndexOf are much faster.
@@ -945,52 +946,53 @@ module.exports = {
945946 let offset = 0 ;
946947 while ( true ) {
947948 const target = `${ self . apos . modules [ '@apostrophecms/image' ] . action } /${ doc . aposDocId } /src` ;
948- console . log ( 'target' , target ) ;
949949 i = content . indexOf ( target , offset ) ;
950950 console . log ( 'i' , i ) ;
951951 if ( i === - 1 ) {
952- console . log ( '---' ) ;
953952 break ;
954953 }
955954 offset = i + target . length ;
956- console . log ( 'offset' , offset ) ;
957955 // If you can edit the widget, you don't want the link replaced,
958956 // as that would lose the image if you edit the widget
959957 const left = content . lastIndexOf ( '<' , i ) ;
960- console . log ( 'left' , left ) ;
961958 const src = content . indexOf ( ' src="' , left ) ;
962- console . log ( 'src' , src ) ;
963959 const close = content . indexOf ( '"' , src + 6 ) ;
964- console . log ( 'close' , close ) ;
965960 if ( ( left !== - 1 ) && ( src !== - 1 ) && ( close !== - 1 ) ) {
966961 content = content . substring ( 0 , src + 5 ) + doc . attachment . _urls [ self . apos . modules [ '@apostrophecms/image' ] . getLargestSize ( ) ] + content . substring ( close + 1 ) ;
967- console . log ( 'content' , content ) ;
968- console . log ( '---' ) ;
969962
970- // update or insert alt attribute
963+ // Update or insert alt attribute
971964 const tagEnd = content . indexOf ( '>' , left ) ;
965+ console . log ( 'tagEnd' , tagEnd ) ;
972966 if ( tagEnd !== - 1 ) {
973967 let imgTag = content . substring ( left , tagEnd + 1 ) ;
974- // Look for alt attribute in the tag
968+ console . log ( 'imgTag' , imgTag ) ;
975969 const altAttr = ' alt="' ;
976970 const altIndex = imgTag . indexOf ( altAttr ) ;
971+ console . log ( 'altIndex' , altIndex ) ;
977972 if ( altIndex !== - 1 ) {
978973 // Replace the existing alt value
979974 const altValueStart = altIndex + altAttr . length ;
975+ console . log ( 'altValueStart' , altValueStart ) ;
980976 const altValueEnd = imgTag . indexOf ( '"' , altValueStart ) ;
977+ console . log ( 'altValueEnd' , altValueEnd ) ;
981978 imgTag = imgTag . substring ( 0 , altValueStart ) +
982979 self . apos . util . escapeHtml ( doc . alt || '' ) +
983980 imgTag . substring ( altValueEnd ) ;
981+ console . log ( 'updated imgTag' , imgTag ) ;
984982 } else {
985983 // Insert alt attribute before closing >
986984 imgTag = imgTag . replace (
987985 / \/ ? > $ / ,
988986 ` alt="${ self . apos . util . escapeHtml ( doc . alt || '' ) } "$&`
989987 ) ;
988+ console . log ( 'inserted imgTag' , imgTag ) ;
990989 }
991990 // Replace the tag in content
992991 content = content . substring ( 0 , left ) +
993992 imgTag + content . substring ( tagEnd + 1 ) ;
993+
994+ console . log ( 'updated content' , content ) ;
995+ console . log ( '---' ) ;
994996 }
995997
996998 } else {
0 commit comments