mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-01-31 11:29:09 +00:00
Make /hypha/ a synonym for /page/
This commit is contained in:
parent
e3b4c75f79
commit
92dd19316c
@ -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
|
||||
|
2
main.go
2
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
|
||||
|
14
name.go
14
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 + "</h1>"
|
||||
}
|
||||
|
||||
// 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 ""
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user