How to list recently edited pages in Hugo

The following snippet will list your Hugo site pages ordered by last modification date. You simply have to reverse it and limit to your liking.



<h2>Recently Edited</h2>

{{ $byLastMod :=  .Site.Pages.ByLastmod  }}
{{ $recent := ($byLastMod | last 5).Reverse }}

{{ range  $recent }}
    <a href="{{ .Permalink }}">{{ .Title }}</a>
{{ end }}
Code language: HTML, XML (xml)

How to use?

{{< last-edited-pages >}}Code language: HTML, XML (xml)

Leave a Reply

Your email address will not be published. Required fields are marked *