Featured image of post Hugo Website - Automatic Image Generator

Hugo Website - Automatic Image Generator

Generate cover images for new posts in a pull request. The images are automatically uploaded and the post is updated with the link.

When it comes to making cover images for my posts, I usually use an image that is already in the post or don’t use one at all.

I don’t really like to spend the time with images. I thought it would be fun to let AI generate an image for me, upload to the CDN, and automatically commit the changes to the pull request for review.

This is the workflow of the image generator (running on my local machine):

sequenceDiagram Lambda-->>GitHub: Get the list of files
changed in the pull request GitHub-->>Lambda: Filter any file that's
not a post Lambda-->>GitHub: Get the file contents
of each post GitHub-->>Lambda: Filter only files that
have `thumbnail = ""` Lambda-->>Bedrock: Send prompt with
post title and description Bedrock-->>Lambda: Save images locally Lambda-->>S3: Upload images to S3 CDN S3-->>Lambda: Update `thumbnail = ""` with
the path to the image
generated for that post Lambda-->>GitHub: Update the pull request
with a commit that
has the updated `thumbnail`

I didn’t really log my steps during development on this one, but one new thing I tried that my friend showed me recently, was using ChatGPT to generate the code.

I incrementally added features, and it was a fun way to develop.

ChatGPT Writing Code

Code organization got a bit messy as I added more features, I tried to clean it up a bit.

hugo_site_automations GitHub Repo

Future plans include:

  • generating more than one image and letting the user choose which image to use
  • automatically updating the post with the date and time, so I don’t have to remember
  • automatically updating the categories (with pre-defined list) and tags (with a limit)
  • automatically generate a description based on the post content (with a length limit)

I’m excited to finally use the image generation for something other than just testing. 😄

I still don’t have the auto deploy setup yet, but I’ll get there.

Licensed under CC BY-NC-SA 4.0
Built with Hugo
Theme Stack designed by Jimmy