mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-02-07 14:40:16 +00:00
Make /hypha/ a synonym for /page/
This commit is contained in:
parent
e3b4c75f79
commit
92dd19316c
@ -19,7 +19,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
http.HandleFunc("/page/", handlerPage)
|
http.HandleFunc("/page/", handlerHypha)
|
||||||
|
http.HandleFunc("/hypha/", handlerHypha)
|
||||||
http.HandleFunc("/text/", handlerText)
|
http.HandleFunc("/text/", handlerText)
|
||||||
http.HandleFunc("/binary/", handlerBinary)
|
http.HandleFunc("/binary/", handlerBinary)
|
||||||
http.HandleFunc("/rev/", handlerRevision)
|
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.
|
// handlerHypha 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) {
|
func handlerHypha(w http.ResponseWriter, rq *http.Request) {
|
||||||
log.Println(rq.URL)
|
log.Println(rq.URL)
|
||||||
var (
|
var (
|
||||||
hyphaName = HyphaNameFromRq(rq, "page")
|
hyphaName = HyphaNameFromRq(rq, "page", "hypha")
|
||||||
data, hyphaExists = HyphaStorage[hyphaName]
|
data, hyphaExists = HyphaStorage[hyphaName]
|
||||||
hasAmnt = hyphaExists && data.binaryPath != ""
|
hasAmnt = hyphaExists && data.binaryPath != ""
|
||||||
contents string
|
contents string
|
||||||
|
2
main.go
2
main.go
@ -190,7 +190,7 @@ func main() {
|
|||||||
history.Start(WikiDir)
|
history.Start(WikiDir)
|
||||||
setHeaderLinks()
|
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_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_auth.go for /login, /login-data, /logout, /logout-confirm
|
||||||
// See http_history.go for /history/, /recent-changes
|
// See http_history.go for /history/, /recent-changes
|
||||||
|
14
name.go
14
name.go
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -46,7 +47,14 @@ func naviTitle(canonicalName string) string {
|
|||||||
return html + "</h1>"
|
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".
|
// 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, action string) string {
|
func HyphaNameFromRq(rq *http.Request, actions ...string) string {
|
||||||
return CanonicalName(strings.TrimPrefix(rq.URL.Path, "/"+action+"/"))
|
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…
x
Reference in New Issue
Block a user