[Solved] Display .GitInfo for Files

I can display .GitInfo information for content pages e.g.
{{ range .Site.Pages }} {{ .GitInfo.AuthorName }} {{ end }}

I can display .FileInfo information for files as in directoryindex.html

I tried to access .GitInfo information for those files
{{ range $files }} {{ .GitInfo.AuthorName }} {{ end }}

but I get an error

can’t evaluate field GitInfo in type os.FileInfo

My reason for wanting to do this is to display a list of images used on a documentation site in date order to see if older screenshots need refreshing. Showing Git info alongside the image would be useful.

It looks like .GitInfo can only be used for content pages. Is there another way to achieve this?

Have you enabled GitInfo in your config.toml?

enableGitInfo = "true"

GitInfo is for content pages only, not templates.

1 Like

Yes, I have

Thanks, I thought so - but I was hoping there might be another way

Haven’t tried it but you might be able to make a manifest for those images in data, and then parse that. Before we had the GitInfo we had to do it manually. You might be able to adapt something like this, which uses a one liner script to grab git info from the git repo log.

1 Like

Rick that is perfect. Thank you so much.

I had to make a couple of tweaks to work for me - I left a comment on your topic in case it helps anyone else.


1 Like

Glad it was helpful @Giles, and thanks for pasting the solution in the other thread too. :slight_smile: