I wonder if you can help? I have a podcast and I have fallen out of love with Hugo (it’s such a confusing "£$%) and I’ve found Zola and made lots of progress in no time (sign of a good tool!). But really need to automate the creation of some file meta data. (I’ve currently got frontmatter [extra] size = 294884 … omg no please no for 250+ podcasts…)
I need to know the file size using a template function, of an MP3 asset on disk (and ideally the duration and a bunch of ID3 tag information there is a rust id3 lib for that here) but for now I would settle for just being able to get the file size in bytes of an asset on disk.
I had a quick look at GetImageMeta here to see if I could add a new global function to get file size myself…
I’ve never used Rust and its a bit beyond me.
But it looks like fs::meta on rust-lang org does exactly whats needed.
Looking at the structure of the code the lib.rs would need to be updated to link the function into the tera template.
With something like this in the docs:
get_file_metadata
Gets metadata for a file asset on disk. Today the only supported keys are size.
{% set meta = get_file_metadata(path="…") %} Our asset is {{ meta.size }} bytes.
I wonder if anyone could help me with this? or consider it for a future version release?
The get_file_metadata might make sense but I don’t think it will go as far as you will need with the MP3 information for example. I’m probably going to wait to see if there are more people needing that before implementing it.
Thank for getting back to me. The mp3 info is only likely to be necessary for music sites and people who host podcast rss feeds. I don’t know how many of those use zola. There are quite a few of us podcasters. As I said file size would be a huge help initially. Thanks for considering it.
I want to reopen this feature request. Recently I have needed this functionality, and I have a working implementation of a get_file_metadata built-in function which I think can be quite useful for other people.
In my case, I want to offer some data downloads from my website, but some of them are quite heavy so I want to display their size before people start downloading, without having to hardcode it into the downloads page.
The proposed implementation get_file_metadata takes a local path and returns a structure with the following fields:
file_size: the file size in bytes
creation_date: a ISO 8601 String representing the creation date in UTC
modification_date: a ISO 8601 String representing the latest modification date in UTC
It should be possible to add other fields without breaking the existing interface. When the file cannot be found, or it cannot be queried, the function aborts and returns the corresponding error.
If there is interest, I can contribute the implementation as a push request for Zola.