Groupbydate with month and year

Hi guys, let said i have an collection posts group by date with below:

{{ range (where .Site.RegularPages "Type" "in" (slice "posts")).GroupByDate "2006" }}
        <h2>{{ .Key }}</h2>
        {{ range .Pages }} -         {{ .PublishDate }}

{{.Title}} - {{
{{end}}

So result will look like this

2021

  • 25-Nov-2021 - Hello World

The thing is. i also want to add month in GroupByDate "2006" either.
So the result i want:

2021

Nov

  • Hello World from Nov

June

  • Hello World from June

Are there anyway to achive it?

Just do it again.

{{ range (where .Site.RegularPages "Type" "posts").GroupByDate "2006" }}
  <h2>Year: {{ .Key }}</h2>
  {{ range .Pages.GroupByDate "Jan" }}
    <h3>Month: {{ .Key }}</h3>
    {{ range .Pages }}
      <h4><a href="{{ .RelPermalink }}">{{ .Title }}</a></h4>
    {{end}}
  {{end}}
{{end}}
2 Likes

Thanks you so much about the idea.
Just one small thing.
I’m also using this

  {{ index $.Site.Data.weekday (printf "%d" .Date.Weekday) }} {{ .Date.Format
  "02" }} {{ index .Site.Data.month (.Date.Format "1")}} năm {{ .Date.Format
  "2006"}}

to display my date a date in Vietnamese like
Thứ năm ngày 25 tháng mười một năm (English version is Thursday 25 November 2021).
It work great with my weekday.yml and month.yml. So can i combine with groupbydate method to show like this?:

2021

Tháng mười một

  • Hello from Nov

My month.yml

1: "tháng giêng"
2: "tháng hai"
3: "tháng ba"
4: "tháng tư"
5: "tháng năm"
6: "tháng sáu"
7: "tháng bảy"
8: "tháng tám"
9: "tháng chín"
10: "tháng mười"
11: "tháng mười một"
12: "tháng mười hai"

Sorry if it bother you

{{ range (where .Site.RegularPages "Type" "posts").GroupByDate "2006" }}
  <h2>{{ .Key }}</h2>
  {{ range .Pages.GroupByDate "1" }}
    <h3>{{ index site.Data.month .Key | strings.FirstUpper }}</h3>
    {{ range .Pages }}
      <h4><a href="{{ .RelPermalink }}">{{ .Title }}</a></h4>
    {{end}}
  {{end}}
{{end}}
1 Like

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