diff --git a/http_readers.go b/http_readers.go index 9cd4c69..10676a8 100644 --- a/http_readers.go +++ b/http_readers.go @@ -19,7 +19,8 @@ import ( ) func init() { - http.HandleFunc("/page/", handlerPage) + http.HandleFunc("/page/", handlerHypha) + http.HandleFunc("/hypha/", handlerHypha) http.HandleFunc("/text/", handlerText) http.HandleFunc("/binary/", handlerBinary) http.HandleFunc("/rev/", handlerRevision) @@ -77,11 +78,11 @@ func handlerBinary(w http.ResponseWriter, rq *http.Request) { } } -// handlerPage is the main hypha action that displays the hypha and the binary upload form along with some navigation. -func handlerPage(w http.ResponseWriter, rq *http.Request) { +// handlerHypha is the main hypha action that displays the hypha and the binary upload form along with some navigation. +func handlerHypha(w http.ResponseWriter, rq *http.Request) { log.Println(rq.URL) var ( - hyphaName = HyphaNameFromRq(rq, "page") + hyphaName = HyphaNameFromRq(rq, "page", "hypha") data, hyphaExists = HyphaStorage[hyphaName] hasAmnt = hyphaExists && data.binaryPath != "" contents string diff --git a/main.go b/main.go index 97ce3c3..068f706 100644 --- a/main.go +++ b/main.go @@ -190,7 +190,7 @@ func main() { history.Start(WikiDir) setHeaderLinks() - // See http_readers.go for /page/, /text/, /binary/ + // See http_readers.go for /page/, /hypha/, /text/, /binary/ // See http_mutators.go for /upload-binary/, /upload-text/, /edit/, /delete-ask/, /delete-confirm/, /rename-ask/, /rename-confirm/, /unattach-ask/, /unattach-confirm/ // See http_auth.go for /login, /login-data, /logout, /logout-confirm // See http_history.go for /history/, /recent-changes diff --git a/name.go b/name.go index 2a859d8..57c860a 100644 --- a/name.go +++ b/name.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "log" "net/http" "strings" @@ -46,7 +47,14 @@ func naviTitle(canonicalName string) string { return html + "" } -// HyphaNameFromRq extracts hypha name from http request. You have to also pass the action which is embedded in the url. For url /page/hypha, the action would be "page". -func HyphaNameFromRq(rq *http.Request, action string) string { - return CanonicalName(strings.TrimPrefix(rq.URL.Path, "/"+action+"/")) +// HyphaNameFromRq extracts hypha name from http request. You have to also pass the action which is embedded in the url or several actions. For url /hypha/hypha, the action would be "hypha". +func HyphaNameFromRq(rq *http.Request, actions ...string) string { + p := rq.URL.Path + for _, action := range actions { + if strings.HasPrefix(p, "/"+action+"/") { + return util.CanonicalName(strings.TrimPrefix(p, "/"+action+"/")) + } + } + log.Fatal("HyphaNameFromRq: no matching action passed") + return "" }