@@ -0,0 +1,79 @@
1+package site
2+
3+import (
4+ "path/filepath"
5+ "slices"
6+ "strconv"
7+ "strings"
8+ "time"
9+
10+ "xonecas.io/site/internal/project"
11+)
12+
13+// YearCount is one row of the activity page's year list.
14+type YearCount struct {
15+ Year string
16+ Count, Heat int
17+}
18+
19+// Day is one day of the activity feed, newest commit first.
20+type Day struct {
21+ Label string
22+ Commits []Commit
23+}
24+
25+// ActivityPage is one year of my commits: the year list, its months, and its commits by day.
26+type ActivityPage struct {
27+ Year string
28+ Total int
29+ Years []YearCount
30+ Months []Cell
31+ Days []Day
32+}
33+
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.
36+func writeActivity(out string, shown []project.Project, feed []Commit) error {
37+ all, years := map[string]int{}, map[string]int{}
38+ first, last := "9999", "0000"
39+ for _, p := range shown {
40+ for m, n := range p.Months {
41+ all[m] += n
42+ years[m[:4]] += n
43+ }
44+ first, last = min(first, p.First[:4]), max(last, p.Last[:4])
45+ }
46+ var list []YearCount
47+ lo, _ := strconv.Atoi(first)
48+ hi, _ := strconv.Atoi(last)
49+ for n := hi; n >= lo; n-- {
50+ y := strconv.Itoa(n)
51+ list = append(list, YearCount{y, years[y], level(years[y])})
52+ }
53+ slices.SortStableFunc(feed, func(a, b Commit) int { return strings.Compare(b.Date, a.Date) })
54+ for _, y := range list {
55+ page := ActivityPage{Year: y.Year, Total: y.Count, Years: list, Months: months(y.Year, all)}
56+ day := ""
57+ 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
64+ }
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"))
71+ }
72+ for _, path := range paths {
73+ if err := render(path, "activity.html", page); err != nil {
74+ return err
75+ }
76+ }
77+ }
78+ return nil
79+}