@@ -22,17 +22,20 @@ type Day struct {
2222 Commits []Commit
2323 }
2424
25-// ActivityPage is one year of my commits: the year list, its months, and its commits by day.
25+// ActivityPage is one page of a year of my commits: the year list, its months, and a page of its commits by day.
2626 type ActivityPage struct {
27- Year string
28- Total int
29- Years []YearCount
30- Months []Cell
31- Days []Day
27+ Year string
28+ Total, Page, Pages int
29+ Years []YearCount
30+ Months []Cell
31+ Days []Day
3232 }
3333
34-// writeActivity writes /activity/<year>/ for every year from the first to the last commit,
35-// and /activity/ as the latest year. feed is my commits across the shown projects.
34+// perPage is how many commits an activity page shows.
35+const perPage = 100
36+
37+// writeActivity writes /activity/<year>/ and /activity/<year>/<page>/ for every year from the first to the last commit,
38+// and /activity/ as the latest year's first page. feed is my commits across the shown projects.
3639 func writeActivity(out string, shown []project.Project, feed []Commit) error {
3740 all, years := map[string]int{}, map[string]int{}
3841 first, last := "9999", "0000"
@@ -52,28 +55,44 @@ func writeActivity(out string, shown []project.Project, feed []Commit) error {
5255 }
5356 slices.SortStableFunc(feed, func(a, b Commit) int { return strings.Compare(b.Date, a.Date) })
5457 for _, y := range list {
55- page := ActivityPage{Year: y.Year, Total: y.Count, Years: list, Months: months(y.Year, all)}
56- day := ""
58+ var mine []Commit
5759 for _, c := range feed {
58- if !strings.HasPrefix(c.Date, y.Year) {
59- continue
60- }
61- if c.Date != day {
62- t, _ := time.Parse(time.DateOnly, c.Date)
63- page.Days, day = append(page.Days, Day{Label: t.Format("Mon 2 Jan")}), c.Date
60+ if strings.HasPrefix(c.Date, y.Year) {
61+ mine = append(mine, c)
6462 }
65- c.Date = "" // the day's heading says it
66- page.Days[len(page.Days)-1].Commits = append(page.Days[len(page.Days)-1].Commits, c)
67- }
68- paths := []string{filepath.Join(out, "activity", y.Year, "index.html")}
69- if y.Year == last {
70- paths = append(paths, filepath.Join(out, "activity", "index.html"))
7163 }
72- for _, path := range paths {
73- if err := render(path, "activity.html", page); err != nil {
74- return err
64+ pages := max(1, (len(mine)+perPage-1)/perPage)
65+ for n := 1; n <= pages; n++ {
66+ page := ActivityPage{y.Year, y.Count, n, pages, list, months(y.Year, all), days(mine[(n-1)*perPage : min(n*perPage, len(mine))])}
67+ dir := filepath.Join(out, "activity", y.Year)
68+ if n > 1 {
69+ dir = filepath.Join(dir, strconv.Itoa(n))
70+ }
71+ paths := []string{filepath.Join(dir, "index.html")}
72+ if y.Year == last && n == 1 {
73+ paths = append(paths, filepath.Join(out, "activity", "index.html"))
74+ }
75+ for _, path := range paths {
76+ if err := render(path, "activity.html", page); err != nil {
77+ return err
78+ }
7579 }
7680 }
7781 }
7882 return nil
7983 }
84+
85+// days groups commits, newest first, by the day they were made.
86+func days(commits []Commit) []Day {
87+ var out []Day
88+ day := ""
89+ for _, c := range commits {
90+ if c.Date != day {
91+ t, _ := time.Parse(time.DateOnly, c.Date)
92+ out, day = append(out, Day{Label: t.Format("Mon 2 Jan")}), c.Date
93+ }
94+ c.Date = "" // the day's heading says it
95+ out[len(out)-1].Commits = append(out[len(out)-1].Commits, c)
96+ }
97+ return out
98+}