diff --git a/http_history.go b/http_history.go new file mode 100644 index 0000000..8bec1ae --- /dev/null +++ b/http_history.go @@ -0,0 +1,48 @@ +package main + +import ( + "log" + "net/http" + "strconv" + "strings" + + "github.com/bouncepaw/mycorrhiza/history" + "github.com/bouncepaw/mycorrhiza/templates" + "github.com/bouncepaw/mycorrhiza/util" +) + +func init() { + http.HandleFunc("/history/", handlerHistory) + http.HandleFunc("/recent-changes/", handlerRecentChanges) +} + +// handlerHistory lists all revisions of a hypha +func handlerHistory(w http.ResponseWriter, rq *http.Request) { + log.Println(rq.URL) + hyphaName := 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.HistoryWithRevisions(hyphaName, revs) + } + log.Println("Found", len(revs), "revisions for", hyphaName) + + util.HTTP200Page(w, + base(hyphaName, templates.HistoryHTML(rq, hyphaName, list))) +} + +// Recent changes +func handlerRecentChanges(w http.ResponseWriter, rq *http.Request) { + log.Println(rq.URL) + var ( + noPrefix = strings.TrimPrefix(rq.URL.String(), "/recent-changes/") + n, err = strconv.Atoi(noPrefix) + ) + if err == nil && n < 101 { + util.HTTP200Page(w, base(strconv.Itoa(n)+" recent changes", history.RecentChanges(n))) + } else { + http.Redirect(w, rq, "/recent-changes/20", http.StatusSeeOther) + } +} diff --git a/http_readers.go b/http_readers.go index e9bf8dc..6f7c58e 100644 --- a/http_readers.go +++ b/http_readers.go @@ -20,7 +20,6 @@ func init() { http.HandleFunc("/page/", handlerPage) http.HandleFunc("/text/", handlerText) http.HandleFunc("/binary/", handlerBinary) - http.HandleFunc("/history/", handlerHistory) http.HandleFunc("/rev/", handlerRevision) } @@ -53,23 +52,6 @@ func handlerRevision(w http.ResponseWriter, rq *http.Request) { w.Write([]byte(base(hyphaName, page))) } -// handlerHistory lists all revisions of a hypha -func handlerHistory(w http.ResponseWriter, rq *http.Request) { - log.Println(rq.URL) - hyphaName := 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.HistoryWithRevisions(hyphaName, revs) - } - log.Println("Found", len(revs), "revisions for", hyphaName) - - util.HTTP200Page(w, - base(hyphaName, templates.HistoryHTML(rq, hyphaName, list))) -} - // handlerText serves raw source text of the hypha. func handlerText(w http.ResponseWriter, rq *http.Request) { log.Println(rq.URL) diff --git a/main.go b/main.go index 51d7610..1215861 100644 --- a/main.go +++ b/main.go @@ -10,8 +10,6 @@ import ( "os" "path/filepath" "regexp" - "strconv" - "strings" "github.com/bouncepaw/mycorrhiza/history" "github.com/bouncepaw/mycorrhiza/templates" @@ -91,20 +89,6 @@ func handlerRandom(w http.ResponseWriter, rq *http.Request) { http.Redirect(w, rq, "/page/"+randomHyphaName, http.StatusSeeOther) } -// Recent changes -func handlerRecentChanges(w http.ResponseWriter, rq *http.Request) { - log.Println(rq.URL) - var ( - noPrefix = strings.TrimPrefix(rq.URL.String(), "/recent-changes/") - n, err = strconv.Atoi(noPrefix) - ) - if err == nil && n < 101 { - util.HTTP200Page(w, base(strconv.Itoa(n)+" recent changes", history.RecentChanges(n))) - } else { - http.Redirect(w, rq, "/recent-changes/20", http.StatusSeeOther) - } -} - func handlerStyle(w http.ResponseWriter, rq *http.Request) { log.Println(rq.URL) if _, err := os.Stat(WikiDir + "/static/common.css"); err == nil { @@ -128,14 +112,14 @@ func main() { history.Start(WikiDir) - http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(WikiDir+"/static")))) - // See http_readers.go for /page/, /text/, /binary/, /history/. - // See http_mutators.go for /upload-binary/, /upload-text/, /edit/, /delete-ask/, /delete-confirm/, /rename-ask/, /rename-confirm/. + // See http_readers.go for /page/, /text/, /binary/ + // See http_mutators.go for /upload-binary/, /upload-text/, /edit/, /delete-ask/, /delete-confirm/, /rename-ask/, /rename-confirm/ // See http_auth.go for /login, /login-data, /logout, /logout-confirm + // See http_history.go for /history/, /recent-changes http.HandleFunc("/list", handlerList) http.HandleFunc("/reindex", handlerReindex) http.HandleFunc("/random", handlerRandom) - http.HandleFunc("/recent-changes/", handlerRecentChanges) + http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(WikiDir+"/static")))) http.HandleFunc("/favicon.ico", func(w http.ResponseWriter, rq *http.Request) { http.ServeFile(w, rq, WikiDir+"/static/favicon.ico") }) diff --git a/templates/asset.qtpl.go b/templates/asset.qtpl.go index 655f800..16def29 100644 --- a/templates/asset.qtpl.go +++ b/templates/asset.qtpl.go @@ -51,7 +51,7 @@ article pre.codeblock {background-color:#eee; padding:.5rem; white-space: pre-wr .transclusion code, .transclusion .codeblock {background-color:#ddd;} .transclusion {background-color:#eee; border-radius: .25rem; } .transclusion__content > *:not(.binary-container) {margin: 0.5rem; } -.transclusion__link {display: block; text-align: right; font-style: italic; margin-top: 0.5rem; color: black; text-decoration: none;} +.transclusion__link {display: block; text-align: right; font-style: italic; margin-top: .5rem; margin-right: .25rem; color: black; text-decoration: none;} .transclusion__link::before {content: "⇐ ";} .binary-container_with-img img,