This commit is contained in:
parent
66719c58fc
commit
e80383911d
17
main.go
17
main.go
|
@ -43,8 +43,12 @@ type Revision struct {
|
|||
type Change struct {
|
||||
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)
|
||||
|
|
|
@ -7,9 +7,10 @@
|
|||
<table class="table">
|
||||
{{ range $index, $change := .Recent }}
|
||||
<tr>
|
||||
<td>{{ $change.Date }}</td>
|
||||
<td><a href="/{{ $change.Page }}">{{ $change.Page }}</a></td>
|
||||
<td>{{ $change.DateSummary }}</td>
|
||||
<td>{{ $change.TimeSummary }}</td>
|
||||
<td>{{ $change.Count }}</td>
|
||||
<td><a href="/{{ $change.Page }}">{{ $change.Page }}</a></td>
|
||||
<td>{{ $change.Body }}</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
|
|
Loading…
Reference in New Issue
Block a user