summaryrefslogtreecommitdiff
path: root/nex.go
diff options
context:
space:
mode:
authortjp <tjp@ctrl-c.club>2023-11-14 21:50:15 -0700
committertjp <tjp@ctrl-c.club>2023-11-14 21:50:15 -0700
commit7baecfca55527dc82499686c29ee59ae8c4b972e (patch)
tree8e9d299c204bd195c7c544f3f638b35e49af5b7a /nex.go
parentb081308884cb01d235336c900f65dc0a638f08c8 (diff)
add support for syw git views on nexv1.3.2
Diffstat (limited to 'nex.go')
-rw-r--r--nex.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/nex.go b/nex.go
index d64f588..a8a5a9e 100644
--- a/nex.go
+++ b/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)
+ })
+ })
+}