all repos — flounder @ 619b97c145842b3ef7463cb40e8e7a42712a4bec

A small site builder for the Gemini protocol

Refactor, bold index.gmi in subfolders
alex wennerberg alex@alexwennerberg.com
Sun, 24 Jan 2021 21:41:42 -0800
commit

619b97c145842b3ef7463cb40e8e7a42712a4bec

parent

2db17c0358b3c441a1bf395e3fba9c8a4880e7d2

3 files changed, 22 insertions(+), 22 deletions(-)

jump to
M http.gohttp.go

@@ -436,26 +436,6 @@ const ok = "-0123456789abcdefghijklmnopqrstuvwxyz"

var bannedUsernames = []string{"www", "proxy", "grafana"} -func isOkUsername(s string) error { - if len(s) < 1 { - return fmt.Errorf("Username is too short") - } - if len(s) > 32 { - return fmt.Errorf("Username is too long. 32 char max.") - } - for _, char := range s { - if !strings.Contains(ok, strings.ToLower(string(char))) { - return fmt.Errorf("Username contains invalid characters. Valid characters include lowercase letters, numbers, and hyphens.") - } - } - for _, username := range bannedUsernames { - if username == s { - return fmt.Errorf("Username is not allowed.") - } - } - return nil -} - func registerHandler(w http.ResponseWriter, r *http.Request) { if r.Method == "GET" { data := struct {

@@ -765,7 +745,7 @@ }

func runHTTPServer() { log.Printf("Running http server with hostname %s on port %d.", c.Host, c.HttpPort) var err error - t = template.New("main").Funcs(template.FuncMap{"parent": path.Dir}) + t = template.New("main").Funcs(template.FuncMap{"parent": path.Dir, "hasSuffix": strings.HasSuffix}) t, err = t.ParseGlob(path.Join(c.TemplatesDirectory, "*.html")) if err != nil { log.Fatal(err)
M templates/my_site.htmltemplates/my_site.html

@@ -30,7 +30,7 @@ </td>

{{ else }} <td> <a href="//{{.Creator}}.{{.Host}}/{{.Name}}"> - {{ if eq .Name "index.gmi" }} + {{ if hasSuffix .Name "index.gmi" }} <b>{{ .Name }}</b> {{ else }} {{ .Name }}
M utils.goutils.go

@@ -27,6 +27,26 @@ }

return result } +func isOkUsername(s string) error { + if len(s) < 1 { + return fmt.Errorf("Username is too short") + } + if len(s) > 32 { + return fmt.Errorf("Username is too long. 32 char max.") + } + for _, char := range s { + if !strings.Contains(ok, strings.ToLower(string(char))) { + return fmt.Errorf("Username contains invalid characters. Valid characters include lowercase letters, numbers, and hyphens.") + } + } + for _, username := range bannedUsernames { + if username == s { + return fmt.Errorf("Username is not allowed.") + } + } + return nil +} + // Check if it is a text file, first by checking mimetype, then by reading bytes // Stolen from https://github.com/golang/tools/blob/master/godoc/util/util.go func isTextFile(fullPath string) bool {