Merge multiple changes to the same file
This commit is contained in:
parent
5d5f537df9
commit
66719c58fc
29
main.go
29
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)
|
||||
|
|
|
@ -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 }}
|
||||
|
|
Loading…
Reference in New Issue
Block a user