From 66719c58fc8fd65bc8787129bb8cf5f38c4f121a Mon Sep 17 00:00:00 2001 From: Peter Stuifzand Date: Sat, 2 Mar 2019 14:24:52 +0100 Subject: [PATCH] Merge multiple changes to the same file --- main.go | 29 ++++++++++++++++++++++++++--- templates/recent.html | 1 + 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 1f78dcb..9d441bd 100644 --- a/main.go +++ b/main.go @@ -41,9 +41,10 @@ type Revision struct { } type Change struct { - Page string - Date time.Time - Body string + Page string + Date time.Time + Body string + Count int } type PagesRepository interface { @@ -422,6 +423,28 @@ func (h *recentHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } + // group recentchanges on Page + if len(changes) > 0 { + f := len(changes) - 1 + i := f + + for { + if changes[f].Page == changes[i].Page { + changes[f].Count++ + i-- + } else { + f-- + changes[f] = changes[i] + } + + if i <= 0 { + break + } + } + + changes = changes[f:] + } + 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 e38ed04..3d568c7 100644 --- a/templates/recent.html +++ b/templates/recent.html @@ -9,6 +9,7 @@ {{ $change.Date }} {{ $change.Page }} + {{ $change.Count }} {{ $change.Body }} {{ end }}