List recently edited files

Hi, I searched for an answer to this one but maybe I’m not searching right… coulnd’t find it. But this request must have come up before…

I would like to be able to list on my front page (it’s a technical documentation site) the articles/pages recently edited, so people can get a sense of “what’s new” in the site.

Better yet if this could be weighted not just by date, but also by commit counts, or commit sizes, so that we could get a sense of “heavily edited” files versus simple typo fixes. The cherry on top of the cake would be to have links to git diffs showing exactly what was edited.

Can anybody point to me in the right direction to achieve this? At least, the simplest version, which is a list of recently edited articles by modified date. At this point I am not very learned in Hugo, so I would prefer copy-paste bits of code, but if that’s not available, then more complex stuff is also appreciated. Thanks.

Hugo has lastmod now, so, you might use that.

Also, you might be able to adapt this concept:

… for stuff it does not have like, getting commit counts.

1 Like


1 Like

You can order content by last modified date.
And maybe just link to GitHub (or whatever platform) comparison diffs.

edit: previous answers are better.

1 Like

I just want to say thank you for all the interesting answers here, I think I can manage with these. I’ll be aiming for a launch next week, fingers crossed, let’s hope I can get everything up and running by then :slight_smile:

I’m pretty satisfied with this solution now, it’s based on @bep’s suggestion above:

layouts/partials/recently-edited.html

<h2>Recently Edited documentation pages</h2>

    {{ $byLastMod :=  .Site.RegularPages.ByLastmod  }}
    {{ $recent := ($byLastMod | last 5).Reverse }}
    {{ partial "recently-edited-item" $recent }}

layouts/partials/recently-edited-item.html

<ul>
{{ range  . }}
    <li>
        <h4 class="">
                <a href="{{ .Permalink }}">{{ .Title }}</a>
        </h4>
        <p class="">
           Edited on the {{ .Lastmod.Format "2 January" }} in commit <b>"{{ with .GitInfo }}{{ .Subject }}{{ else }}[Commit description]{{ end }}"</b>, see 
             <a href="https://github.com/organization/repo/commit/{{.GitInfo.Hash}}" target="_blank">changes</a>
        </p>
    </li>
{{ end }}
</ul>

That see changes takes the user to a diff of the entire commit. It doesn’t separate files, so the commit might have changes to lots of other files apart from the one I’m listing here. So it’s not a perfect solution, but is good enough in most cases. I can always try to keep the commits small and focused.

Note: Hugo must have the enableGitInfo flag turned on for this to work.

Thanks for all the help.

1 Like

Hhmm strangely enough the Commit info doesn’t seem to be updating… well, not consistently.

This is the repo and this is the rendered site. That section the Homepage, lower right, is where the Recent Edits appear.

I see a commit there from today, but not others like these. I can’t figure out why some are picked up and others aren’t…?

We exlude merge commits.

That makes sense, but apart from merge commits, I see 3 newer commits after the ones the Hugo code is picking up…

Blog post final details
@pgorod pgorod committed an hour ago

blog pst tweaks
@pgorod pgorod committed an hour ago

Add Themes documentation
@CBeechey CBeechey committed an hour ago

You should check your build logic/setup. This works perfectly for the Hugo site.

I’ve been working through this and I believe I am seeing some inconsistency in the way .Lastmod is populated.

Note: throughout all my tests, I always use full Hugo renders, with --enableGitInfo --disableFastRender

I built a partial to dump a range of pages like this:

<div class="">
<h2>ByLastMod</h2>
    {{ $byLastMod :=  .Site.RegularPages.ByLastmod  }}
    {{ $recent := ($byLastMod | last 5).Reverse }}


    <ol>
    {{ range $byLastMod }}
      <li>
        <p class="" style="margin:0 0;">
           File <b>{{ .Title  }}</b> Lastmod date is <b>{{ .Lastmod }}</b>
        </p>
      </li>
    {{ end }}
    </ol>
</div>

This gives me the following list:

ByLastMod
1.	File 18. Best Practices Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
2.	File 17.API-8 Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
3.	File 19. Performance Tweaks Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
4.	File 20. Further Resources Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
5.	File 21. Appendix A - Code Examples Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
6.	File Downloading & Installing Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
7.	File Getting Started Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
8.	File Opening an Issue about a page Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
9.	File Raising Issues Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
10.	File Troubleshooting and Support Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
11.	File 22. Appendix B - API Methods Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
12.	File Forking SuiteCRM Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
13.	File Licensing Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
14.	File Upgrading Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
15.	File User Wizard Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
16.	File Local Setup for Documentation Work Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
17.	File Managing User Accounts Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
18.	File Using the Upgrade Wizard Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
19.	File Coding Standards Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
20.	File Releases Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
21.	File Uninstalling Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
22.	File User Interface Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
23.	File Bug Fixes Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
24.	File Compatibility Matrix Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
25.	File Accounts Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
26.	File Contacts Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
27.	File Providing a Feature Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
28.	File Opportunities Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
29.	File Leads Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
30.	File Calendar Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
31.	File Calls Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
32.	File Meetings Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
33.	File Email Settings Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
34.	File Email Templates Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
35.	File Emails Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
36.	File Emails - LTS Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
37.	File Themes Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
38.	File Confirmed Opt-In Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
39.	File Tasks Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
40.	File Notes Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
41.	File Documents Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
42.	File Targets Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
43.	File Target Lists Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
44.	File Campaigns Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
45.	File Surveys Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
46.	File Cases Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
47.	File Projects Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
48.	File Sales Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
49.	File Workflow Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
50.	File Cases with Portal Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
51.	File Events Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
52.	File Reports Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
53.	File Reschedule Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
54.	File Security Suite (Groups) Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
55.	File JJW Maps Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
56.	File Appendix A Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
57.	File Code of Conduct Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
58.	File Contributor Agreement Lastmod date is 0001-01-01 00:00:00 +0000 UTC 
59.	File Creating an Alert in SuiteCRM Lastmod date is 2015-08-25 12:00:00 +0100 WEST 
60.	File ListView Conditional Formatting Lastmod date is 2016-03-04 12:00:00 +0100 +0100 
61.	File Scheduler Jobs in SuiteCRM in Linux - the Definitive Guide Lastmod date is 2017-04-14 12:00:00 +0100 WEST 
62.	File 1. Introduction Lastmod date is 2018-01-12 17:04:03 +0000 WET 
63.	File 2. SuiteCRM Directory Structure Lastmod date is 2018-01-12 17:04:03 +0000 WET 
64.	File 3. Working with Beans Lastmod date is 2018-01-12 17:04:03 +0000 WET 
65.	File 4. Vardefs Lastmod date is 2018-01-12 17:04:03 +0000 WET 
66.	File 5. Views Lastmod date is 2018-01-12 17:04:03 +0000 WET 
67.	File 6. Metadata Lastmod date is 2018-01-12 17:04:03 +0000 WET 
68.	File 7. Controllers Lastmod date is 2018-01-12 17:04:03 +0000 WET 
69.	File 8. Entry Points Lastmod date is 2018-01-12 17:04:03 +0000 WET 
70.	File 9. Language Strings Lastmod date is 2018-01-12 17:04:03 +0000 WET 
71.	File 10. Config Lastmod date is 2018-01-12 17:04:03 +0000 WET 
72.	File 11. Logging Lastmod date is 2018-01-12 17:04:03 +0000 WET 
73.	File 12. Logic Hooks Lastmod date is 2018-01-12 17:04:03 +0000 WET 
74.	File 13. Scheduled Tasks Lastmod date is 2018-01-12 17:04:03 +0000 WET 
75.	File 14. Extension Framework Lastmod date is 2018-01-12 17:04:03 +0000 WET 
76.	File 15. Module Installer Lastmod date is 2018-01-12 17:04:03 +0000 WET 
77.	File Editing a page Lastmod date is 2018-02-21 23:39:10 +0000 WET 
78.	File 16. API-4_1 Lastmod date is 2018-02-22 00:33:52 +0000 WET 
79.	File Test page Lastmod date is 2018-02-22 14:22:04 +0000 WET 

So, a bunch of files don’t get a proper .Lastmod date. Note that these pages don’t generally contain lastmod in the front-matter, nor date, so I’m expecting this to come from GitInfo.AuthorDate as defined here (in the .Lastmod section). The exception to this are those 3 files showing dates from 2015-2017, that’s coming from front-matter.

Now, sometimes it seems to pick up my commit date. But it’s very irregular. I’ve even seen the same file get a .Lastmod date from a commit, but then not from a subsequent commit done afterwards.

I attempted several things trying to look for a pattern of when it fails:

  • is it when I commit several files in one commit, versus single-file commits?
  • is it merge commits versus other commits?
  • is it when I commit files with spaces in their names?

None of these were conclusive, it must be something else…

Although I don’t know any Go, I’ve even looked at Hugo code to try and figure out how GitInfo grabs information from Git. I’ve tracked it down to this and this. I got stuck on this line, it’s not the kind of thing one can figure out easily without actually running it and testing it :slight_smile:

If you can just tell me exactly what git command that produces I think I can continue debugging on my own, trying to see how the git log output is coming from my git repo.

Ok, nevermind, I got that command, the escaped % were throwing me off.

So here’s an excerpt from my git log:

^^56576f4c634df8b947c67f9d24aa69f933f4f9aa^_56576f4^_single file, same file^_root^_pgorod@users.noreply.github.com^_2018-02-22 14:45:13 +0000
content/user/Security Suite (Groups).adoc

^^751023806853397579fcd01a3d8bc58f449612f8^_7510238^_two files in one commit, again^_root^_pgorod@users.noreply.github.com^_2018-02-22 14:25:20 +0000
content/user/JJW Maps.adoc
content/user/Security Suite (Groups).adoc

^^359a64243167b7e19fe15b3913ad4e64e3052a5e^_359a642^_two files in one commit^_root^_pgorod@users.noreply.github.com^_2018-02-22 14:23:44 +0000
content/user/JJW Maps.adoc
content/user/Security Suite (Groups).adoc

^^e46cdf743a73b2fe7f933b0665e4b30e3bae0a75^_e46cdf7^_test page^_root^_pgorod@users.noreply.github.com^_2018-02-22 14:22:04 +0000
content/another.md
layouts/partials/footer.html

This last one gets its Lastmod recognized, the others don’t… this is mysterious…

I have looked at my own code, and adjusted it slightly:

You can confirm if this is your problem by running hugo -v and look for WARNING of type “Failed to find GitInfo…”.

I assumed that was a FATAL error, but I may have been wrong in that assumption (maybe something that happens with shallow cloning --depth 1?

Anyway, Hugo 0.37 is scheduled for Monday.

No, I don’t have those errors (or anything else suspicious) when running hugo -v

I have tested your site and can confirm that the above patch fixes your case.

Or, it does not fix it entirely, ref. the log:

Failed to find GitInfo for "content/developer/API/_index.en.adoc"
Failed to find GitInfo for "content/developer/18. Best Practices.adoc"
Failed to find GitInfo for "content/developer/19. Performance Tweaks.adoc"
Failed to find GitInfo for "content/developer/20. Further Resources.adoc"
Failed to find GitInfo for "content/developer/21. Appendix A - Code Examples.adoc"
Failed to find GitInfo for "content/developer/22. Appendix B - API Methods.adoc"

But that is https://github.com/gohugoio/hugo/issues/4444

With a known workaround (rename). At least, with Hugo 0.37 it will not break everything.

Thanks @bep, I’m very grateful for all this help. We launched the site today and it’s looking great, this is just a detail and with this information I know I can get this feature operational next week, which is great.

1 Like

I confirm that with 0.37 this problem with the missing Lastmod is fixed for most files.

I do get the problem in those 6 files you listed. But I have plenty of other files with spaces in their names, apart from those, so spaces in names doesn’t seem to be the reason it’s failing…

Thanks

That was the “obvious pattern”, but I also notice one other file with that issue … So probably some Git history issue, not sure.