-
Notifications
You must be signed in to change notification settings - Fork 0
/
history_handler.go
48 lines (40 loc) · 1.05 KB
/
history_handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"fmt"
"github.com/gorilla/mux"
"gopkg.in/src-d/go-git.v4/plumbing"
"net/http"
"path"
)
func (b *Bilbo) HandleHistory(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
normalizedLink := normalizePageLink(vars["page"], false)
if normalizedLink != vars["page"] {
redirectUrl, err := b.mux.Get("pages#history").URL("page", normalizedLink)
if err != nil {
panic(err)
}
http.Redirect(w, r, redirectUrl.String(), http.StatusMovedPermanently)
}
commit := r.Context().Value("GitHead").(plumbing.Hash)
pageHistory, err := b.getPageHistoryFromCommit(vars["page"]+".md", false, commit)
if err != nil {
panic(err)
}
page, _, err := b.getRequestedPage(r)
if err != nil {
panic(err)
}
pageFolder := path.Dir(page.Linkpath)
if pageFolder == "/" {
pageFolder = ""
}
b.renderTemplate(w, r, "history.html", hash{
"isPage": true,
"page": page,
"pageFolder": pageFolder,
"pageHistory": pageHistory,
"pageLayout": "commits",
"pageTitle": fmt.Sprintf("History for %s", page.Title),
})
}