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