Put latest git info in an HTML comment

Thank you. While this approach is probably no longer needed for content files, it works for grabbing git info from other files - in my case, images

see Display GitInfo for Files

I ran into a couple of glitches, I guess due to slight differences across 'nix. version

Using Ubuntu 17.04 I used:

  • > instead of :\>| to clear the manifest file
  • >> instead of \>\> to append output to the manifest file

Getting this to work for me, I also learned

  • the 2 ;s allow the for … in … do … done loop to be written on one line
  • that instead of finding slug within files, I used echo ${f##*/} to output the filename without the path
  • to add git date || author || commit message I used git log --date=format:"%e %b, %Y" --pretty="%ad || %an || %s" -1 $f ( when generating the page in hugo I replace the || with <br> )

This is what I am using in one line.
cd /dev/path/to/ && > data/imagesgitinfo.yaml && for f in /dev/path/to/static/img/*.*; do echo ${f##*/}: "$( git log --date=format:"%e %b, %Y" --pretty="%ad || %an || %s" -1 $f)" >> data/imagesgitinfo.yaml; done

Thank you so much

1 Like