I host all my images on Cloudflare Images. While this has huge advantages for serving responsive content, it also means URLs quickly become a bit complicated to handle, and in particular makes any sort of dynamic content generation awkward to achieve: I’ve got stuck trying to dynamically generate URLs within front matter, and would need some help for the following.
1. In my site front matter, I have the following:
[params]
[...]
# Sets the URL for images
cloudflare_images = "https://[CLIENT_URL]/cdn-cgi/imagedelivery/[CLIENT_ID]/"
2. Then in each post, I have the following:
---
title: "Curabitur viverra, neque nec porttitor semper, sapien massa euismod erat, eget rutrum eros ligula sed nibh."
[...]
featured_image: "969a796-2fbc-451f-ba14-8f6e0276b000"
---
In posts, images are referenced (via shortcodes) by concatenating those two parameters, like so:
{{ .Site.Params.cloudflare_images }}{{ .Params.featured_image }}
What I would like to do is add the images
parameter to each post’s front matter, and have it dynamically generated by combining the two above variables, in such a way that I can then use the images
parameter in the Hugo Open Graph internal template.
So the post’s front matter would look like something similar to this (except this code doesn’t work!, obviously:
---
title: "Curabitur viverra, neque nec porttitor semper, sapien massa euismod erat, eget rutrum eros ligula sed nibh."
[...]
featured_image: "969a796-2fbc-451f-ba14-8f6e0276b000"
images : {{ .Site.Params.cloudflare_images }}{{ .Params.featured_image }}
---
Is it actually possible to define a front matter parameter dynamically in this way? I did try to see if I could do it with Pages Resources, but couldn’t find a way to make that work.