Skip to content

A self-hosted dashboard that puts all your feeds in one place

Add randomElement func

Svilen Markov44804debd6ed
diff --git a/internal/glance/widget-custom-api.go b/internal/glance/widget-custom-api.go
index bc3c012..6531030 100644
--- a/internal/glance/widget-custom-api.go
+++ b/internal/glance/widget-custom-api.go
@@ -716,6 +716,13 @@ var customAPITemplateFuncs = func() template.FuncMap {
return data
},
+ "randomElement": func(arr []decoratedGJSONResult) *decoratedGJSONResult {
+ if len(arr) == 0 {
+ return &decoratedGJSONResult{gjson.Result{}}
+ }
+
+ return &arr[rand.Intn(len(arr))]
+ },
}
for key, value := range globalTemplateFunctions {