add support for syw git views on nex

This commit is contained in:
tjp 2023-11-14 21:50:15 -07:00
parent b081308884
commit 7baecfca55
4 changed files with 22 additions and 6 deletions

View File

@ -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".

View File

@ -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
View File

@ -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)
})
})
}

View File

@ -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")
}