diff --git a/history/histview/histview.go b/history/histview/histview.go
index 17635c1..00fdffa 100644
--- a/history/histview/histview.go
+++ b/history/histview/histview.go
@@ -10,6 +10,7 @@ import (
"github.com/bouncepaw/mycorrhiza/util"
"github.com/bouncepaw/mycorrhiza/viewutil"
"github.com/gorilla/mux"
+ "log"
"net/http"
"strconv"
"strings"
@@ -21,9 +22,11 @@ func InitHandlers(rtr *mux.Router) {
rtr.HandleFunc("/recent-changes/", func(w http.ResponseWriter, rq *http.Request) {
http.Redirect(w, rq, "/recent-changes/20", http.StatusSeeOther)
})
+ rtr.PathPrefix("/history/").HandlerFunc(handlerHistory)
chainPrimitiveDiff = viewutil.CopyEnRuWith(fs, "view_primitive_diff.html", ruTranslation)
chainRecentChanges = viewutil.CopyEnRuWith(fs, "view_recent_changes.html", ruTranslation)
+ chainHistory = viewutil.CopyEnRuWith(fs, "view_history.html", ruTranslation)
}
func handlerPrimitiveDiff(w http.ResponseWriter, rq *http.Request) {
@@ -65,6 +68,21 @@ func handlerRecentChanges(w http.ResponseWriter, rq *http.Request) {
recentChanges(viewutil.MetaFrom(w, rq), editCount, history.RecentChanges(editCount))
}
+// handlerHistory lists all revisions of a hypha.
+func handlerHistory(w http.ResponseWriter, rq *http.Request) {
+ hyphaName := util.HyphaNameFromRq(rq, "history")
+ var list string
+
+ // History can be found for files that do not exist anymore.
+ revs, err := history.Revisions(hyphaName)
+ if err == nil {
+ list = history.WithRevisions(hyphaName, revs)
+ }
+ log.Println("Found", len(revs), "revisions for", hyphaName)
+
+ historyView(viewutil.MetaFrom(w, rq), hyphaName, list)
+}
+
var (
//go:embed *.html
fs embed.FS
@@ -79,8 +97,7 @@ var (
{{define "n recent changes"}}{{.}} недавн{{if eq . 1}}ее изменение{{else if le . 4}}недавних изменения{{else}}недавних изменений{{end}}{{end}}
{{define "recent empty"}}Правки не найдены.{{end}}
`
- chainPrimitiveDiff viewutil.Chain
- chainRecentChanges viewutil.Chain
+ chainPrimitiveDiff, chainRecentChanges, chainHistory viewutil.Chain
)
type recentChangesData struct {
@@ -116,3 +133,19 @@ func primitiveDiff(meta viewutil.Meta, h hyphae.ExistingHypha, hash, text string
Text: text,
})
}
+
+type historyData struct {
+ *viewutil.BaseData
+ HyphaName string
+ Contents string
+}
+
+func historyView(meta viewutil.Meta, hyphaName, contents string) {
+ viewutil.ExecutePage(meta, chainHistory, historyData{
+ BaseData: &viewutil.BaseData{
+ Addr: "/history/" + util.CanonicalName(hyphaName),
+ },
+ HyphaName: hyphaName,
+ Contents: contents,
+ })
+}
diff --git a/history/histview/view_history.html b/history/histview/view_history.html
new file mode 100644
index 0000000..5d2db4d
--- /dev/null
+++ b/history/histview/view_history.html
@@ -0,0 +1,9 @@
+{{define "history of title"}}History of {{.}}{{end}}
+{{define "body"}}
+
+
+ {{block "history of heading" .HyphaName}}History of {{beautifulName .}}{{end}}
+ {{.Contents}}
+
+
+{{end}}
diff --git a/views/history.qtpl b/views/history.qtpl
deleted file mode 100644
index 9a922dd..0000000
--- a/views/history.qtpl
+++ /dev/null
@@ -1,13 +0,0 @@
-{% import "fmt" %}
-{% import "net/http" %}
-
-{% import "github.com/bouncepaw/mycorrhiza/l18n" %}
-
-{% func History(rq *http.Request, hyphaName, list string, lc *l18n.Localizer) %}
-
-
- {%s= fmt.Sprintf(lc.Get("ui.history_title"), beautifulLink(hyphaName)) %}
- {%s= list %}
-
-
-{% endfunc %}
diff --git a/views/history.qtpl.go b/views/history.qtpl.go
deleted file mode 100644
index 5188414..0000000
--- a/views/history.qtpl.go
+++ /dev/null
@@ -1,75 +0,0 @@
-// Code generated by qtc from "history.qtpl". DO NOT EDIT.
-// See https://github.com/valyala/quicktemplate for details.
-
-//line views/history.qtpl:1
-package views
-
-//line views/history.qtpl:1
-import "fmt"
-
-//line views/history.qtpl:2
-import "net/http"
-
-//line views/history.qtpl:4
-import "github.com/bouncepaw/mycorrhiza/l18n"
-
-//line views/history.qtpl:6
-import (
- qtio422016 "io"
-
- qt422016 "github.com/valyala/quicktemplate"
-)
-
-//line views/history.qtpl:6
-var (
- _ = qtio422016.Copy
- _ = qt422016.AcquireByteBuffer
-)
-
-//line views/history.qtpl:6
-func StreamHistory(qw422016 *qt422016.Writer, rq *http.Request, hyphaName, list string, lc *l18n.Localizer) {
-//line views/history.qtpl:6
- qw422016.N().S(`
-
-
- `)
-//line views/history.qtpl:9
- qw422016.N().S(fmt.Sprintf(lc.Get("ui.history_title"), beautifulLink(hyphaName)))
-//line views/history.qtpl:9
- qw422016.N().S(`
- `)
-//line views/history.qtpl:10
- qw422016.N().S(list)
-//line views/history.qtpl:10
- qw422016.N().S(`
-
-
-`)
-//line views/history.qtpl:13
-}
-
-//line views/history.qtpl:13
-func WriteHistory(qq422016 qtio422016.Writer, rq *http.Request, hyphaName, list string, lc *l18n.Localizer) {
-//line views/history.qtpl:13
- qw422016 := qt422016.AcquireWriter(qq422016)
-//line views/history.qtpl:13
- StreamHistory(qw422016, rq, hyphaName, list, lc)
-//line views/history.qtpl:13
- qt422016.ReleaseWriter(qw422016)
-//line views/history.qtpl:13
-}
-
-//line views/history.qtpl:13
-func History(rq *http.Request, hyphaName, list string, lc *l18n.Localizer) string {
-//line views/history.qtpl:13
- qb422016 := qt422016.AcquireByteBuffer()
-//line views/history.qtpl:13
- WriteHistory(qb422016, rq, hyphaName, list, lc)
-//line views/history.qtpl:13
- qs422016 := string(qb422016.B)
-//line views/history.qtpl:13
- qt422016.ReleaseByteBuffer(qb422016)
-//line views/history.qtpl:13
- return qs422016
-//line views/history.qtpl:13
-}
diff --git a/web/history.go b/web/history.go
index de5fc4b..4c109e2 100644
--- a/web/history.go
+++ b/web/history.go
@@ -2,45 +2,19 @@ package web
import (
"fmt"
- "github.com/bouncepaw/mycorrhiza/viewutil"
"github.com/gorilla/mux"
- "log"
"net/http"
"github.com/bouncepaw/mycorrhiza/history"
- "github.com/bouncepaw/mycorrhiza/l18n"
- "github.com/bouncepaw/mycorrhiza/util"
- "github.com/bouncepaw/mycorrhiza/views"
)
func initHistory(r *mux.Router) {
- r.PathPrefix("/history/").HandlerFunc(handlerHistory)
r.HandleFunc("/recent-changes-rss", handlerRecentChangesRSS)
r.HandleFunc("/recent-changes-atom", handlerRecentChangesAtom)
r.HandleFunc("/recent-changes-json", handlerRecentChangesJSON)
}
-// handlerHistory lists all revisions of a hypha.
-func handlerHistory(w http.ResponseWriter, rq *http.Request) {
- hyphaName := util.HyphaNameFromRq(rq, "history")
- var list string
-
- // History can be found for files that do not exist anymore.
- revs, err := history.Revisions(hyphaName)
- if err == nil {
- list = history.WithRevisions(hyphaName, revs)
- }
- log.Println("Found", len(revs), "revisions for", hyphaName)
-
- var lc = l18n.FromRequest(rq)
- util.HTTP200Page(w, views.Base(
- viewutil.MetaFrom(w, rq),
- fmt.Sprintf(lc.Get("ui.history_title"), util.BeautifulName(hyphaName)),
- views.History(rq, hyphaName, list, lc),
- ))
-}
-
// genericHandlerOfFeeds is a helper function for the web feed handlers.
func genericHandlerOfFeeds(w http.ResponseWriter, rq *http.Request, f func(history.FeedOptions) (string, error), name string, contentType string) {
opts, err := history.ParseFeedOptions(rq.URL.Query())