URL to most recent page?

Given a folder of files, is it possible to have a URL automatically redirect to the most recently published file in that folder?

(For example, in a folder containing 2020.md, 2021.md, 2022.md, and 2023.md, https://www.example.com/latest would point to 2023.md.)

I’ve checked out Routing | Grav Documentation, but nothing comes to mind.

I believe Login plugin does similar thing. IIRC, it has configurable route and if you navigate to that route, it shows the page. So instead of showing the page, you could grab the latest post and redirect.

Thank you.

I think I can do it by using Page Collections | Grav Documentation

Specifically, I created a page that will display the contents of the most recent page:

title: Most recent page
published: true
    items: '@self.children'
        by: date
        dir: desc
    limit: 1
    pagination: true
    default: /recent

{% for p in page.collection %}
<h2>{{ p.title|e }}</h2>
{{ p.content|raw }}
{% endfor %}

Great! If this solves your problem, don’t hesitate to mark your own answer as a solution :wink:

1 Like