From f536b16e170a5efb5b3bdd720e48100d5d0f83ba Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Sat, 21 Jan 2023 19:41:40 +0100 Subject: Add wtfpl.txt to gemini --- src/gmi/tpl.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/gmi/tpl.go') diff --git a/src/gmi/tpl.go b/src/gmi/tpl.go index 8220a49..e448afd 100644 --- a/src/gmi/tpl.go +++ b/src/gmi/tpl.go @@ -7,7 +7,9 @@ import ( "fmt" "io" "io/fs" + "mime" "net/url" + "path" "path/filepath" "strconv" "strings" @@ -194,10 +196,12 @@ func (a *api) tplHandler() (gemini.Handler, error) { ) { tplPath := strings.TrimPrefix(r.URL.Path, "/") + mimeType := mime.TypeByExtension(path.Ext(r.URL.Path)) ctx = mctx.Annotate(ctx, "url", r.URL, "tplPath", tplPath, + "mimeType", mimeType, ) tpl := allTpls.Lookup(tplPath) @@ -207,6 +211,10 @@ func (a *api) tplHandler() (gemini.Handler, error) { return } + if mimeType != "" { + rw.SetMediaType(mimeType) + } + buf := new(bytes.Buffer) err := tpl.Execute(buf, renderer{ -- cgit v1.2.3