From 43d8951296ce2f232ca94f0577e2e726291bf783 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Sun, 26 May 2024 21:16:02 +0200 Subject: Replace URL building methods with the URLBuilder --- src/gmi/tpl.go | 33 ++++----------------------------- 1 file changed, 4 insertions(+), 29 deletions(-) (limited to 'src/gmi/tpl.go') diff --git a/src/gmi/tpl.go b/src/gmi/tpl.go index d4c6b00..fb62a17 100644 --- a/src/gmi/tpl.go +++ b/src/gmi/tpl.go @@ -9,9 +9,7 @@ import ( "io" "io/fs" "mime" - "net/url" "path" - "path/filepath" "strings" "text/template" @@ -36,26 +34,6 @@ var tplFS embed.FS func (a *api) tplHandler() (gemini.Handler, error) { - blogURL := func(base *url.URL, path string, abs bool) string { - - // filepath.Join strips trailing slash, but we want to keep it - trailingSlash := strings.HasSuffix(path, "/") - - path = filepath.Join("/", base.Path, path) - - if trailingSlash && path != "/" { - path += "/" - } - - if !abs { - return path - } - - u := *base - u.Path = path - return u.String() - } - preprocessFuncs := post.PreprocessFunctions{ Image: func(args ...string) (string, error) { var ( @@ -67,10 +45,9 @@ func (a *api) tplHandler() (gemini.Handler, error) { descr = args[1] } - path := filepath.Join("assets", id) - path = blogURL(a.params.PublicURL, path, false) - - return fmt.Sprintf("\n=> %s %s", path, descr), nil + return fmt.Sprintf( + "\n=> %s %s", a.urlBuilder.Asset(id), descr, + ), nil }, } @@ -140,9 +117,7 @@ func (a *api) tplHandler() (gemini.Handler, error) { err := tpl.Execute(buf, render.NewMethods( ctx, r.URL, - a.params.PublicURL, - a.params.HTTPPublicURL, - a.params.PublicURL, // geminiURL + a.urlBuilder, a.params.HTTPGeminiGatewayURL, a.params.PostStore, nil, // asset.Store, not supported by gemini endpoint -- cgit v1.2.3