Open kaboomdigital opened 4 years ago
The documentation for Tera has a section for Rust functions. Would it be possible to write a function that fetches some images? Or is this template-functionality meant for other logic?
Using a function is definitely the right way to go about implementing this.
I suspect what you'd want to do is check whether the path
argument looks like a URL, and if so download the file to some temp location (temp deterministic, so it could be reused on rebuilds), then pass the downloaded path back into the resize_image
method as a path.
The source for resize_image
is https://github.com/getzola/zola/blob/master/components/templates/src/global_fns/mod.rs#L149
The source for the load_data
zola function might also be of useful reference: https://github.com/getzola/zola/blob/master/components/templates/src/global_fns/load_data.rs, as that also downloads remote data
@RealOrangeOne Thanks for the input! :-)
I started implementing everything in a separate script because I also want to dynamically generate pages based on content from the same data-source as the images. I think it would be definitely useful to have an implementation of the resize_images
that can process external URLs, so I'll leave this issue open for now. (example use case: images stored in a CMS)
Would it be possible to somehow process an external image with the
resize_image
function?The resize image function uses a local path for the image to process. But I would like to process an image from an Airtable base. (So Airtable can be used as a sort of CMS). I'm trying to figure out a way how to get the image from the URL and how to add it to Zola so it can be processed.
Just pointing the
path
argument to an external URL and Zola downloading and processing it would be a nice feature to add maybe. But for now; perhaps someone can point me in the direction to look for a sexy solution?Running a separate process which downloads everything before starting Zola would be an option. But perhaps there is a way which is more integrated into the build process?
Thanks for helping out. :-)