Skip to content

Commit 2819f9f

Browse files
committed
Generate a top-level /archives page grouping posts by year
1 parent 10c979a commit 2819f9f

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

cmd/plan/main.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,42 @@ func buildHistory(ctx *PlanContext) ([]Item, error) {
659659
}
660660
}
661661
}
662+
663+
// Generate Archives Page
664+
var archiveContent bytes.Buffer
665+
archiveContent.WriteString("# Archives\n\n")
666+
667+
// Get years and sort them descending
668+
var years []string
669+
for y := range tree {
670+
years = append(years, y)
671+
}
672+
sort.Sort(sort.Reverse(sort.StringSlice(years)))
673+
674+
for _, year := range years {
675+
archiveContent.WriteString(fmt.Sprintf("## %s\n\n", year))
676+
677+
// Collect all days for this year
678+
var yearDays []dayEntry
679+
for _, days := range tree[year] {
680+
yearDays = append(yearDays, days...)
681+
}
682+
683+
// Sort days descending
684+
sort.Slice(yearDays, func(i, j int) bool {
685+
return yearDays[i].DateStr > yearDays[j].DateStr
686+
})
687+
688+
for _, d := range yearDays {
689+
archiveContent.WriteString(fmt.Sprintf("- [%s](%s)\n", d.DateStr, d.Path))
690+
}
691+
archiveContent.WriteString("\n")
692+
}
693+
694+
if err := renderAndWrite(ctx, archiveContent.Bytes(), time.Now(), filepath.Join(ctx.OutputDir, "archives", "index.html")); err != nil {
695+
return nil, err
696+
}
697+
662698
return rssItems, nil
663699
}
664700

0 commit comments

Comments
 (0)