I have this project structure after running hugo new
and adding minimal working files:
project
│ config.yaml
│
└───layouts
│ │ index.html
│ │
│ └───_default
│ │ baseof.html
│
│ └───layouts
│ │ head.html
│ │ recent.html
│ │ recent-filter.html
│ │ script-footer.html
│
└───content
│ └───posts
│ │ └───2022-10-31
│ │ │ index.md
│ │ └───2023-05-28
│ │ │ index.md
│
md:title=layouts/partials/recent.html
<div>
{{ range sort (where site.RegularPages "Section" "posts") "Params.start" }}
{{ $dateTime := .Params.start | time.AsTime }}
{{ $title := .Params.title }}
<div>
<p style="font-size:12px">
<time datetime="{{ $dateTime }}">{{ $dateTime | time.Format ":date_long" }}</time>
<t/>
{{ $title }}
</p>
</div>
{{ end }}
</div>
md:title=layouts/partials/recent-filter.html
<div>
{{ range where (sort (where site.RegularPages "Section" "posts") "Params.start") "Params.start" "ge" now }}
{{ $dateTime := .Params.start | time.AsTime }}
{{ $title := .Params.title }}
<div>
<p style="font-size:12px">
<time datetime="{{ $dateTime }}">{{ $dateTime | time.Format ":date_long" }}</time>
<t/>
{{ $title }}
</p>
</div>
{{ end }}
</div>
This results in the following screenshot:
I expected the where clause to include only posts with start date greater equal to today. My use case is to only include ‘the most recent post’ so after i select only the posts after today i will use first 1
on the sorted list. I have unquoted dates in the front matter of markdown and they are all in same format.
I looked at this related post. Using {{ if (time .Params.start).After now }} ... {{ end }}
works but I can’t use first 1
with that and I see break is not implemented. I already received advice to code defensively around pages with the start
command so I’m looking into that now if that’s related (ty @jmooring).