Merge multiple changes to the same file

This commit is contained in:
Peter Stuifzand 2019-03-02 14:24:52 +01:00
parent 5d5f537df9
commit 66719c58fc
2 changed files with 27 additions and 3 deletions

29
main.go
View File

@ -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)

View File

@ -9,6 +9,7 @@
<tr>
<td>{{ $change.Date }}</td>
<td><a href="/{{ $change.Page }}">{{ $change.Page }}</a></td>
<td>{{ $change.Count }}</td>
<td>{{ $change.Body }}</td>
</tr>
{{ end }}