Hi
I had the similar need. Here is the method I use :
- I commit with a message
- in my CI i call a schell script :
- make a directory data/commits
- find all the markdown files
- for each create a json file with all the commits of this file
- in my layouts, I read the file in data/commits corresponding to the markdown file and I display the information.
Hera are the codes as is.
Script
mkdir -p data/commits
find content -name "*.md" | while read line; do
contentline=${line#"content/"};
filename=$(echo -n $contentline | md5sum | cut -f 1 -d " ");
log=$(git log --pretty=format:'{%n "commit": "%H",%n "author": "%aN",%n "commit_date": "%ci",%n "message": "%s"%n},' "$line" | perl -pe 'BEGIN{print "["}; END{print "]\n"}' | perl -pe 's/},]/}]/');
echo $log > "data/commits/$filename.json";
done
Here the part of the template
{{ $currentPage := . }}
{{ $jsonFile := "" }}
{{ with $currentPage.File }}
{{ $currentPagemd5 := md5 $currentPage.File.Path }}
{{ $currentPagemd5ext := (print $currentPagemd5 ".json")}}
{{ $files := readDir "data/commits/" }}
{{if gt (len $files ) 0}}
<div class="bord-bas"></div>
<div>
<details>
<summary>Changements de la page</summary>
<div>
{{ range $files }}
{{ if eq .Name $currentPagemd5ext }}
{{ $jsonFile := $currentPagemd5 }}
{{ $data := index $.Site.Data.commits $jsonFile }}
<ul>
{{ range $data }}
<li>
{{ dateFormat "02/01/2006" .commit_date }} : {{ trim .message "\n" }} ({{ .author }})
</li>
{{ end }}
</ul>
{{ end }}
{{ end }}
</div>
</details>
</div>
{{ end }}
{{ end }}
Hope this helps