flounder

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

commit 60827dbbdafd978ba7aab4dfeaf136b77a8bba43
parent eb3dc1e908eec909c858b2fc02836870c4b327ee
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Fri, 30 Oct 2020 22:34:14 -0700

shuffle users on homepage

Diffstat:
Mhttp.go | 2+-
Mmain.go | 10+++++++++-
Mtemplates/index.gmi | 8++++----
3 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/http.go b/http.go @@ -85,7 +85,7 @@ func editFileHandler(w http.ResponseWriter, r *http.Request) { fileName := filepath.Clean(r.URL.Path[len("/edit/"):]) isText := strings.HasPrefix(mime.TypeByExtension(path.Ext(fileName)), "text") if !isText { - renderError(w, "Not a text file", 400) // correct status code? + renderError(w, "Not a text file, cannot be edited here", 400) // correct status code? return } filePath := path.Join(c.FilesDirectory, authUser, fileName) diff --git a/main.go b/main.go @@ -9,6 +9,7 @@ import ( "io" "io/ioutil" "log" + mathrand "math/rand" "mime" "os" "path" @@ -37,6 +38,7 @@ type User struct { CreatedAt int // timestamp } +// returns in a random order func getActiveUserNames() ([]string, error) { rows, err := DB.Query(`SELECT username from user WHERE active is true`) if err != nil { @@ -51,7 +53,13 @@ func getActiveUserNames() ([]string, error) { } users = append(users, user) } - return users, nil + + dest := make([]string, len(users)) + perm := mathrand.Perm(len(users)) + for i, v := range perm { + dest[v] = users[i] + } + return dest, nil } func getUsers() ([]User, error) { diff --git a/templates/index.gmi b/templates/index.gmi @@ -6,10 +6,10 @@ Welcome to flounder, a home for Gemini sites. Flounder hosts small Gemini web pa => gemini://admin.{{$host}} Admin page => https://{{$host}} View on HTTPS -## All Users: -{{range .Users}}=> gemini://{{.}}.{{$host}} -{{end}} - ## Recently updated files: {{range .Files}}=> gemini://{{.Creator}}.{{$host}}/{{.Name}} {{.Creator}}: {{.Name}} ({{.TimeAgo}}) {{end}} + +## All Users: +{{range .Users}}=> gemini://{{.}}.{{$host}} +{{end}}