Order of the rss feed

My code runs the following “where” statement:

{{ range first 10 (where (where .Site.RegularPages ".Params.options" "!=" nil) ".Params.options.unlisted" "!=" true)  }}

But then, the order of the items doesn’t look right:

<pubDate>Thu, 15 Apr 2021 23:10:41 +0100</pubDate>

<pubDate>Sun, 18 Apr 2021 12:07:03 +0100</pubDate>

<pubDate>Sun, 18 Apr 2021 22:20:25 +0100</pubDate>

<pubDate>Tue, 20 Apr 2021 20:23:09 +0100</pubDate>

<pubDate>Tue, 20 Apr 2021 21:19:26 +0100</pubDate>

<pubDate>Fri, 07 May 2021 21:41:31 +0100</pubDate>

<pubDate>Sun, 02 May 2021 22:56:17 +0100</pubDate>

<pubDate>Tue, 02 Mar 2021 18:50:34 +0000</pubDate>

<pubDate>Tue, 02 Mar 2021 18:49:06 +0000</pubDate>

<pubDate>Tue, 02 Mar 2021 18:48:35 +0000</pubDate>

What I am trying to do is show a full feed on the homepage, with pages and posts as they are published.

Hugo’s default sort order is by weight (ascending), then date (descending), then title (ascending), then file path (ascending). See https://gohugo.io/templates/lists/#default-weight--date--linktitle--filepath.

I wasn’t fully aware that weight was the default for cases like this. The following now works, thank you @jmooring !

{{ range first 10 (where (where .Site.RegularPages ".Params.options" "!=" nil) ".Params.options.unlisted" "!=" true).ByPublishDate.Reverse  }}

Also, not sure about your nested where. It will return pages with:

[options]
[options]
foo="bar"
[options]
unlisted = false

If you just want to return the last one:

 {{ range where .Pages "Params.options.unlisted" "eq" false }}

There is a lot of legacy in that unlisted option. Some of the posts don’t include it, hence “nil”, and I was afraid to accidentally show unlisted content, hence “not equal to true”.

I think you are right when you say it needs work, because the following would be more focused and descriptive:

{{ range first 10 (where (where .Site.RegularPages “.Params.options.unlisted” “!=” nil) “.Params.options.unlisted” “!=” true).ByPublishDate.Reverse }}

Or will the code you suggest also take nil into account?

Only “Post 1” is returned by {{ range where .Pages "Params.options.unlisted" "eq" false }}.

+++
title = "Post 1"
date = 2021-05-08T06:24:50-07:00
draft = false
[options]
unlisted = false
+++

+++
title = "Post 2"
date = 2021-05-08T06:24:51-07:00
draft = false
[options]
unlisted = true
+++

+++
title = "Post 3"
date = 2021-05-08T06:24:52-07:00
draft = false
[options]
unlisted = "foo"
+++

+++
title = "Post 4"
date = 2021-05-08T06:24:53-07:00
draft = false
[options]
unlisted = ""
+++

+++
title = "Post 5"
date = 2021-05-08T06:24:54-07:00
draft = false
[options]
unlisted = 0
+++

+++
title = "Post 6"
date = 2021-05-08T06:24:55-07:00
draft = false
[options]
foo = "bar"
+++

+++
title = "Post 7"
date = 2021-05-08T06:24:56-07:00
draft = false
[options]
+++

+++
title = "Post 8"
date = 2021-05-08T06:24:57-07:00
draft = false
+++

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.