shuffle users on homepage
alex wennerberg alex@alexwennerberg.com
Fri, 30 Oct 2020 22:34:14 -0700
3 files changed,
14 insertions(+),
6 deletions(-)
M
http.go
→
http.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.go
→
main.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.gmi
→
templates/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}}