I’m a fan of the Git Info Variables, very useful for showing Git information for a website generate with Hugo (and manage with Git). Perhaps I miss something but is it possible to display all the commits for a file/page with Hugo (and not just the last)? If someone have some examples of what we can do with GitInfo I would appreciate it very much!
I don’t think Hugo has that functionality. It might also lead to longer build times if it has to look for more than the current version info for every single page on build.
I would solve that feature with a javascript that works with the Github API to retrieve that information and display it after page load.
Or by loading the GitHub JSON response with the function getJSON
in Hugo’s templates, especially since the Git commits info is immutable.
The less JavaScript the better.
Yeah, but doing 100 posts requires 100 API requests which might/will lead into throttling from Github and usage limitation => timeouts, blocking, worlds end
getJSON
caches the JSON responses. So provided that these requests happen gradually there shouldn’t be a problem.
I know so first hand because I am already doing the above for a project (not for the GitHub API but the Instagram one).
I like that. Is it cached in the resources
folder? And what happens if I have to add lots of pages, maybe the first time, is Hugo “gentle” or does it “pounce” on the API to get it done? I wonder if it’s possible to load those initial loads maybe via a simple curl shell script within the limits of the API and then just check on changes.
And: we talk about API, I wonder if git log
might be able to be forced to output something that looks like JSON.
I am afraid I have to dig into that, just for my playtime.
The Hugo maintainer can enlighten you further. You can try asking him.
EDIT
I just remembered that the ignoreCache
CLI flag will clear the getJSON
cache.
Already one step further Shell scripts to the rescue. Probably if you deploy to netlify it will also clear the cache if you “clear cache and try deploy”. I’ll retrieve them via shell script pre-build and save to the data directory (based on “last retrieval”). Then build and use the data files instead of internal git variables.
I’ll write a tipps and tricks notice once I have it running. No need to spam this thread thanks for the kick.
Thanks @alexandros @davidsneighbour for these ideas! My initial question focused on the Git Info Variables, but I think i’m going to have to look at other solutions (I already play with git log
for example).