Add wtfpl.txt to gemini

This commit is contained in:
Brian Picciano 2023-01-21 19:41:40 +01:00
parent 0d420f70d8
commit f536b16e17
2 changed files with 22 additions and 0 deletions

View File

@ -7,7 +7,9 @@ import (
"fmt" "fmt"
"io" "io"
"io/fs" "io/fs"
"mime"
"net/url" "net/url"
"path"
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
@ -194,10 +196,12 @@ func (a *api) tplHandler() (gemini.Handler, error) {
) { ) {
tplPath := strings.TrimPrefix(r.URL.Path, "/") tplPath := strings.TrimPrefix(r.URL.Path, "/")
mimeType := mime.TypeByExtension(path.Ext(r.URL.Path))
ctx = mctx.Annotate(ctx, ctx = mctx.Annotate(ctx,
"url", r.URL, "url", r.URL,
"tplPath", tplPath, "tplPath", tplPath,
"mimeType", mimeType,
) )
tpl := allTpls.Lookup(tplPath) tpl := allTpls.Lookup(tplPath)
@ -207,6 +211,10 @@ func (a *api) tplHandler() (gemini.Handler, error) {
return return
} }
if mimeType != "" {
rw.SetMediaType(mimeType)
}
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
err := tpl.Execute(buf, renderer{ err := tpl.Execute(buf, renderer{

14
src/gmi/tpl/wtfpl.txt Normal file
View File

@ -0,0 +1,14 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.