Post cook for images?

I have a very simple plugin (server-side) I was playing around with.

For this part of the call:

on(:post_created) do |post, params|

I use the post.raw to put some content in:

post.raw = "@#{post.user.username} says hello!\n\n"
post.save

…and it works great. Cool.

My question is how to embed an image, as in the same result as when the post cooks in the preview editor?

If I change it to something like this:

post.raw = "https://assets-meta-cdck-prod-meta.s3.dualstack.us-west-1.amazonaws.com/optimized/3X/9/d/9d543e92b15b06924249654667a81441a55867eb_1_690x184.png\n\n"
post.save

…then the post shows the plain image address text and not the preview image. If I open edit on the post manually in the UI it works ok (shows the image preview), just not on my post save.

Looking through the code, am I meant to call ‘post.cook’ after the save to trigger this?

Thanks for any help or pointers to examples.

I solved this by putting the image into an IMG tag within the raw format, i.e.

post.raw = "<img src='https://assets-meta-cdck-prod-meta.s3.dualstack.us-west-1.amazonaws.com/optimized/3X/9/d/9d543e92b15b06924249654667a81441a55867eb_1_690x184.png'/>\n\n"

post.save

…means that it cooks on the save fine now.

4 Likes