all repos — flounder @ 60827dbbdafd978ba7aab4dfeaf136b77a8bba43

A small site builder for the Gemini protocol

shuffle users on homepage
alex wennerberg alex@alexwennerberg.com
Fri, 30 Oct 2020 22:34:14 -0700
commit

60827dbbdafd978ba7aab4dfeaf136b77a8bba43

parent

eb3dc1e908eec909c858b2fc02836870c4b327ee

3 files changed, 14 insertions(+), 6 deletions(-)

jump to
M http.gohttp.go

@@ -85,7 +85,7 @@ }

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)
M main.gomain.go

@@ -9,6 +9,7 @@ "github.com/gorilla/sessions"

"io" "io/ioutil" "log" + mathrand "math/rand" "mime" "os" "path"

@@ -37,6 +38,7 @@ Admin bool

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 @@ return nil, err

} 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) {
M templates/index.gmitemplates/index.gmi

@@ -6,10 +6,10 @@

=> 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}}