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.

Shortcode

themes/YOUR_THEME/layouts/shortcodes/last-edited-pages.html

<h2>Recently Edited</h2>

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

<ul>
{{ range  $recent }}
  <li>
    <a href="{{ .Permalink }}">{{ .Title }}</a>
  </li>
{{ end }}
</ul>
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 *