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 {
|
type Change struct {
|
||||||
Page string
|
Page string
|
||||||
Date time.Time
|
Date time.Time
|
||||||
Body string
|
Body string
|
||||||
|
Count int
|
||||||
}
|
}
|
||||||
|
|
||||||
type PagesRepository interface {
|
type PagesRepository interface {
|
||||||
|
@ -422,6 +423,28 @@ func (h *recentHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
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")
|
t, err := template.New("layout.html").ParseFiles("templates/layout.html", "templates/recent.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), 500)
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ $change.Date }}</td>
|
<td>{{ $change.Date }}</td>
|
||||||
<td><a href="/{{ $change.Page }}">{{ $change.Page }}</a></td>
|
<td><a href="/{{ $change.Page }}">{{ $change.Page }}</a></td>
|
||||||
|
<td>{{ $change.Count }}</td>
|
||||||
<td>{{ $change.Body }}</td>
|
<td>{{ $change.Body }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user