Range over expired pages

I want to create Netlify redirects for expired content, something like this:

{{- $now := now.Format "2006-01-02T15:04:05-07:00" -}}
{{ range where (where .Site.Pages "Type" "in" (slice "events" "webinars")) ".Params.expiryDate" "lt" "$now" }}
{{ .RelPermalink }}  /expired-event/  301!
{{ end }}

Sadly, this doesn’t work. Is there a way to get range to return expired content?

Hi there,

Do you have your code in a repo somewhere we can have a look at?

In what way does your code not work? Does it return the wrong things? Or does it return nothing?

It returns nothing. If I remove the date check, it returns the unexpired events but I can’t get it to return the expired ones.

This is in a private repo that I can’t share.

Are you building the expired posts? https://gohugo.io/getting-started/usage/#draft-future-and-expired-content

By default Hugo will not build these.

No, I don’t want to build the expired posts. So that’s the issue, isn’t it?

Looks like it.

If you just want to see what these posts are, have a look at https://gohugo.io/commands/hugo_list_expired/

1 Like