mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-12-12 05:20:26 +00:00
Move /history/ and /recent-changes handlers to their own file
This commit is contained in:
parent
c89b0702ab
commit
5269411ea2
48
http_history.go
Normal file
48
http_history.go
Normal file
@ -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)
|
||||||
|
}
|
||||||
|
}
|
@ -20,7 +20,6 @@ func init() {
|
|||||||
http.HandleFunc("/page/", handlerPage)
|
http.HandleFunc("/page/", handlerPage)
|
||||||
http.HandleFunc("/text/", handlerText)
|
http.HandleFunc("/text/", handlerText)
|
||||||
http.HandleFunc("/binary/", handlerBinary)
|
http.HandleFunc("/binary/", handlerBinary)
|
||||||
http.HandleFunc("/history/", handlerHistory)
|
|
||||||
http.HandleFunc("/rev/", handlerRevision)
|
http.HandleFunc("/rev/", handlerRevision)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,23 +52,6 @@ func handlerRevision(w http.ResponseWriter, rq *http.Request) {
|
|||||||
w.Write([]byte(base(hyphaName, page)))
|
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.
|
// handlerText serves raw source text of the hypha.
|
||||||
func handlerText(w http.ResponseWriter, rq *http.Request) {
|
func handlerText(w http.ResponseWriter, rq *http.Request) {
|
||||||
log.Println(rq.URL)
|
log.Println(rq.URL)
|
||||||
|
24
main.go
24
main.go
@ -10,8 +10,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/bouncepaw/mycorrhiza/history"
|
"github.com/bouncepaw/mycorrhiza/history"
|
||||||
"github.com/bouncepaw/mycorrhiza/templates"
|
"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)
|
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) {
|
func handlerStyle(w http.ResponseWriter, rq *http.Request) {
|
||||||
log.Println(rq.URL)
|
log.Println(rq.URL)
|
||||||
if _, err := os.Stat(WikiDir + "/static/common.css"); err == nil {
|
if _, err := os.Stat(WikiDir + "/static/common.css"); err == nil {
|
||||||
@ -128,14 +112,14 @@ func main() {
|
|||||||
|
|
||||||
history.Start(WikiDir)
|
history.Start(WikiDir)
|
||||||
|
|
||||||
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(WikiDir+"/static"))))
|
// See http_readers.go for /page/, /text/, /binary/
|
||||||
// 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_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_auth.go for /login, /login-data, /logout, /logout-confirm
|
||||||
|
// See http_history.go for /history/, /recent-changes
|
||||||
http.HandleFunc("/list", handlerList)
|
http.HandleFunc("/list", handlerList)
|
||||||
http.HandleFunc("/reindex", handlerReindex)
|
http.HandleFunc("/reindex", handlerReindex)
|
||||||
http.HandleFunc("/random", handlerRandom)
|
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.HandleFunc("/favicon.ico", func(w http.ResponseWriter, rq *http.Request) {
|
||||||
http.ServeFile(w, rq, WikiDir+"/static/favicon.ico")
|
http.ServeFile(w, rq, WikiDir+"/static/favicon.ico")
|
||||||
})
|
})
|
||||||
|
@ -51,7 +51,7 @@ article pre.codeblock {background-color:#eee; padding:.5rem; white-space: pre-wr
|
|||||||
.transclusion code, .transclusion .codeblock {background-color:#ddd;}
|
.transclusion code, .transclusion .codeblock {background-color:#ddd;}
|
||||||
.transclusion {background-color:#eee; border-radius: .25rem; }
|
.transclusion {background-color:#eee; border-radius: .25rem; }
|
||||||
.transclusion__content > *:not(.binary-container) {margin: 0.5rem; }
|
.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: "⇐ ";}
|
.transclusion__link::before {content: "⇐ ";}
|
||||||
|
|
||||||
.binary-container_with-img img,
|
.binary-container_with-img img,
|
||||||
|
Loading…
Reference in New Issue
Block a user