Dustin Lennon
05/16/2022, 5:53 PM/siteRepository
, if it does, update that to now point to an AWS S3 location where the image will be located at. as of right now, I know how to get the image tags, and I'm able to get the file name from the src because I'll need that. I just don't know how to go about handling the updating of all matches that get returned and then have the post updated with these changes. As of right now, this is all I've been able to come up with.
regexp = "<img\s[^>]*?src\s*=\s*['\""](\/siteRepository\/[^'\""]*?)['\""][^>]*?>";
fileRegexp = "\/userfiles\/(.+)";
contentPagePosts.each(
function(struct row, numeric rowNumber, query query) {
<!--- Take the body of the post and replace the img src to point to S3 bucket location --->
currentPostBody = row.body;
currentSchoolId = row.schoolid;
<!--- Find all image references in the post body --->
<!--- images is an array that has length (len), match, and position (pos) --->
images = reFindNoCase(regexp, currentPostBody, 1, true, "all");
<!--- Loop through images arrays --->
images.each(function(element, index) {
if (element.match[1] NEQ "") {
fileName = "";
<!--- Retrieve the file name --->
element.match[2].each(function(e, i) {
findFileName = reFindNoCase(fileRegexp, e, 1, true, "all");
fileName = findFileName[1].match[2];
writeDump(e);
writeDump(fileName);
});
writeDump(element);
}
});
<!--- Update the body value with the updated data --->
//writeDump(images);
//newPostBody = reReplaceNoCase(currentPostBody, regexp, "#s3LinkBase##currentSchoolId#/userfiles/", "ALL");
},
false,
500
);
An example post would be something like
<p style="text-align: center;"><img alt="" src="/siteRepository/203/userfiles/Hoodie.jpg" style="width: 100px; height: 133px;" /></p>
<p style="text-align: center;">Woodgrove Hoodie (Blue)<br />
$40<br />
S, M, XL</p>
<hr />
<p style="text-align: center;"><img alt="" src="/siteRepository/203/userfiles/hat.jpg" style="width: 100px; height: 133px;" /></p>
<p style="text-align: center;">Woodgrove Hats<br />
Adjustable (Blue)<br />
$20<br />
MD, XL</p>
<hr />
<p style="text-align: center;"><img alt="" src="/siteRepository/203/userfiles/greenhat.jpg" style="width: 100px; height: 133px;" /></p>
<p style="text-align: center;">Woodgrove Hats (Green)<br />
$20<br />
LG, XL</p>
<p> </p>
Dave Merrill
05/16/2022, 6:10 PM