[Solved] Display .GitInfo for Files


#1

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?


Put latest git info in an HTML comment
#2

Have you enabled GitInfo in your config.toml?

enableGitInfo = "true"


#3

GitInfo is for content pages only, not templates.


#4

Yes, I have


#5

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


#6

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.


#7

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.

:clap:


#8

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