mirror of
https://codeberg.org/pluja/kycnot.me
synced 2025-01-08 21:57:58 -05:00
add random element function
This commit is contained in:
parent
cb27dbb57c
commit
31d13b18c9
@ -3,6 +3,7 @@ package server
|
||||
import (
|
||||
"context"
|
||||
"html/template"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
@ -90,6 +91,7 @@ func (s *Server) RegisterRoutes() {
|
||||
|
||||
// GET
|
||||
s.Router.Get("/", s.handleIndex)
|
||||
s.Router.Get("/pgp", s.handlePgp)
|
||||
s.Router.Get("/about", s.handleAbout)
|
||||
s.Router.Get("/pending", s.handlePending)
|
||||
s.Router.Get("/service/{name:string}", s.handleService)
|
||||
@ -130,6 +132,12 @@ func (s *Server) RegisterViews() {
|
||||
"safe": func(s string) template.HTML {
|
||||
return template.HTML(s)
|
||||
},
|
||||
"randomElem": func(vs []string) string {
|
||||
if len(vs) == 0 {
|
||||
return ""
|
||||
}
|
||||
return vs[rand.Intn(len(vs))]
|
||||
},
|
||||
"shortText": func(s string) string {
|
||||
if len(s) > 50 {
|
||||
return strings.TrimSpace(s[:50]) + "..."
|
||||
|
Loading…
Reference in New Issue
Block a user