add support for syw git views on nex
This commit is contained in:
parent
b081308884
commit
7baecfca55
|
@ -261,7 +261,7 @@ gemini {
|
|||
}
|
||||
```
|
||||
|
||||
"git" is not supported in finger or nex servers, but otherwise it builds appropriate views according to the protocol of the server it is under (gemtext on gemini and spartan, gopher menu on gopher).
|
||||
"git" is not supported in finger, but otherwise it builds appropriate views according to the protocol of the server it is under (gemtext on gemini and spartan, gopher menu on gopher, plain text on nex).
|
||||
|
||||
The only supported modifier is "templates" - find more details on that in the section on "Git Viewing Templates".
|
||||
|
||||
|
|
|
@ -266,7 +266,7 @@ gemini {
|
|||
}
|
||||
```
|
||||
|
||||
"git" is not supported in finger or nex servers, but otherwise it builds appropriate views according to the protocol of the server it is under (gemtext on gemini and spartan, gopher menu on gopher).
|
||||
"git" is not supported in finger, but otherwise it builds appropriate views according to the protocol of the server it is under (gemtext on gemini and spartan, gopher menu on gopher, plain text on nex).
|
||||
|
||||
The only supported modifier is "templates" - find more details on that in the section on "Git Viewing Templates".
|
||||
|
||||
|
|
20
nex.go
20
nex.go
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/go-kit/log/level"
|
||||
|
||||
|
@ -11,6 +12,7 @@ import (
|
|||
"tildegit.org/tjp/sliderule/contrib/fs"
|
||||
"tildegit.org/tjp/sliderule/logging"
|
||||
"tildegit.org/tjp/sliderule/nex"
|
||||
"tildegit.org/tjp/syw"
|
||||
)
|
||||
|
||||
func buildNexServer(server Server, config *Configuration) (sr.Server, error) {
|
||||
|
@ -57,6 +59,8 @@ func addNexRoute(router *sr.Router, route RouteDirective) {
|
|||
buildAndAddRoute(router, route, func(route RouteDirective) sr.Handler {
|
||||
return cgi.NexCGIDirectory(route.FsPath, route.URLPath, route.Modifiers.ExecCmd)
|
||||
})
|
||||
case "git":
|
||||
addNexGitRoute(router, route)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,3 +88,19 @@ func addNexStaticRoute(router *sr.Router, route RouteDirective) {
|
|||
return sr.FallthroughHandler(handlers...)
|
||||
})
|
||||
}
|
||||
|
||||
func addNexGitRoute(router *sr.Router, route RouteDirective) {
|
||||
buildAndAddRoute(router, route, func(route RouteDirective) sr.Handler {
|
||||
subrouter := syw.NexRouter(route.FsPath, route.Modifiers.Templates)
|
||||
return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response {
|
||||
reqclone := cloneRequest(request)
|
||||
reqclone.Path = strings.TrimPrefix(reqclone.Path, route.URLPath)
|
||||
|
||||
handler, params := subrouter.Match(reqclone)
|
||||
if handler == nil {
|
||||
return nil
|
||||
}
|
||||
return handler.Handle(context.WithValue(ctx, sr.RouteParamsKey, params), request)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
4
parse.go
4
parse.go
|
@ -326,10 +326,6 @@ func validateRoute(serverType string, dir *RouteDirective) error {
|
|||
return errors.New("cgi directives only support the 'extendedgophermap' modifier")
|
||||
}
|
||||
|
||||
if dir.Type == "git" && serverType != "gemini" && serverType != "gopher" && serverType != "spartan" {
|
||||
return fmt.Errorf("git directive not allowed in %s server", serverType)
|
||||
}
|
||||
|
||||
if serverType == "finger" && (dir.Modifiers.DirDefault != "" || dir.Modifiers.DirList) {
|
||||
return errors.New("finger servers don't support directory 'with' modifiers")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue