Updating markdown image references to Hugo figure shortcodes

A short post which might be of use to some, as it took me a while to figure it out.

I’ve been making a few changes to this site lately, one of which was to move from having the images remotely hosted in AWS S3 to having them locally in the repo. This was prompted by the availability of the Hugo page bundles feature, which I think was introduced several years ago without me noticing.

The existing posts used markdown image references of the form:

![image alt text](https://my-bucket.s3-eu-west-1.amazonaws.com/post-folder/blah.png)

Going forward, I wanted to use the Hugo figure shortcode to render the images, which looks like:

{{< figure src="blah.png" caption="my caption" >}}

(figure copies the caption to the alt-text if the latter is missing)

The first step was to convert each post from a markdown file my-post-title.md to a folder my-post-title/index.md. I used s3cmd to copy down all the images for each post.

Finally, for each post folder, or bundle, I used this sed script to rewrite the references, with the basename of the file in the src attribute and the old alt-text in the caption.