flounder

A simple gemini site builder
Log | Files | Refs | README | LICENSE

commit 619b97c145842b3ef7463cb40e8e7a42712a4bec
parent 2db17c0358b3c441a1bf395e3fba9c8a4880e7d2
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Sun, 24 Jan 2021 21:41:42 -0800

Refactor, bold index.gmi in subfolders

Diffstat:
Mhttp.go | 22+---------------------
Mtemplates/my_site.html | 2+-
Mutils.go | 20++++++++++++++++++++
3 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/http.go b/http.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 checkDomainHandler(w http.ResponseWriter, r *http.Request) { 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) diff --git a/templates/my_site.html b/templates/my_site.html @@ -30,7 +30,7 @@ For some help building your site, check out the <a href="https://admin.flounder. {{ else }} <td> <a href="//{{.Creator}}.{{.Host}}/{{.Name}}"> - {{ if eq .Name "index.gmi" }} + {{ if hasSuffix .Name "index.gmi" }} <b>{{ .Name }}</b> {{ else }} {{ .Name }} diff --git a/utils.go b/utils.go @@ -27,6 +27,26 @@ func getSchemedFlounderLinkLines(r io.Reader) []string { 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 {