Compare commits

...

2 Commits

Author SHA1 Message Date
tjp 7baecfca55 add support for syw git views on nex 2023-11-14 21:50:15 -07:00
tjp b081308884 minor optimization for git routes 2023-11-14 21:48:48 -07:00
7 changed files with 27 additions and 12 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".

View File

@ -148,9 +148,8 @@ func addGeminiStaticRoute(router *sr.Router, route RouteDirective) {
func addGeminiGitRoute(router *sr.Router, route RouteDirective) {
buildAndAddRoute(router, route, func(route RouteDirective) sr.Handler {
subrouter := syw.GeminiRouter(route.FsPath, route.Modifiers.Templates)
handler := sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response {
subrouter := syw.GeminiRouter(route.FsPath, route.Modifiers.Templates)
reqclone := cloneRequest(request)
reqclone.Path = strings.TrimPrefix(reqclone.Path, route.URLPath)

View File

@ -108,9 +108,8 @@ func addGopherCGIRoute(router *sr.Router, route RouteDirective) {
func addGopherGitRoute(router *sr.Router, route RouteDirective) {
buildAndAddRoute(router, route, func(route RouteDirective) sr.Handler {
subrouter := syw.GopherRouter(route.FsPath, route.Modifiers.Templates)
return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response {
subrouter := syw.GopherRouter(route.FsPath, route.Modifiers.Templates)
reqclone := cloneRequest(request)
reqclone.Path = strings.TrimPrefix(reqclone.Path, route.URLPath)

22
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) {
@ -20,6 +22,8 @@ func buildNexServer(server Server, config *Configuration) (sr.Server, error) {
info := level.Info(baselog)
errlog := level.Error(baselog)
_ = info.Log("msg", "starting nex server", "addr", addr)
hostname := ""
if len(server.Hostnames) > 0 {
hostname = server.Hostnames[0]
@ -55,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)
}
}
@ -82,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")
}

View File

@ -121,9 +121,8 @@ func addSpartanStaticRoute(router *sr.Router, route RouteDirective) {
func addSpartanGitRoute(router *sr.Router, route RouteDirective) {
buildAndAddRoute(router, route, func(route RouteDirective) sr.Handler {
subrouter := syw.SpartanRouter(route.FsPath, route.Modifiers.Templates)
handler := sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response {
subrouter := syw.SpartanRouter(route.FsPath, route.Modifiers.Templates)
reqclone := cloneRequest(request)
reqclone.Path = strings.TrimPrefix(reqclone.Path, route.URLPath)