diff --git a/main.go b/main.go index 9d441bd..3a95c2e 100644 --- a/main.go +++ b/main.go @@ -41,10 +41,14 @@ type Revision struct { } type Change struct { - Page string - Date time.Time - Body string - Count int + Page string + Date time.Time + EndDate time.Time + Body string + Count int + + DateSummary string + TimeSummary string } type PagesRepository interface { @@ -429,10 +433,11 @@ func (h *recentHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { i := f for { - if changes[f].Page == changes[i].Page { + if changes[f].Page == changes[i].Page && changes[f].Date.Truncate(24*time.Hour) == changes[i].Date.Truncate(24*time.Hour) { changes[f].Count++ i-- } else { + changes[f].EndDate = changes[i+1].Date f-- changes[f] = changes[i] } @@ -445,6 +450,16 @@ func (h *recentHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { changes = changes[f:] } + for i, c := range changes { + if c.Count == 1 { + changes[i].DateSummary = c.Date.Format("Mon, 2 Jan 2006") + changes[i].TimeSummary = c.Date.Format("15:04") + } else { + changes[i].DateSummary = c.Date.Format("Mon, 2 Jan 2006") + changes[i].TimeSummary = fmt.Sprintf("%s - %s", c.Date.Format("15:04"), c.EndDate.Format("15:04")) + } + } + t, err := template.New("layout.html").ParseFiles("templates/layout.html", "templates/recent.html") if err != nil { http.Error(w, err.Error(), 500) diff --git a/templates/recent.html b/templates/recent.html index 3d568c7..6f30362 100644 --- a/templates/recent.html +++ b/templates/recent.html @@ -7,9 +7,10 @@
{{ $change.Date }} | -{{ $change.Page }} | +{{ $change.DateSummary }} | +{{ $change.TimeSummary }} | {{ $change.Count }} | +{{ $change.Page }} | {{ $change.Body }} |