Skip to content

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

added unique to filter arrays with unique items in custom-api

Ralph Ocdold5b89d512ac6
diff --git a/internal/glance/widget-custom-api.go b/internal/glance/widget-custom-api.go
index 5d82c5a..93d51c0 100644
--- a/internal/glance/widget-custom-api.go
+++ b/internal/glance/widget-custom-api.go
@@ -543,6 +543,18 @@ var customAPITemplateFuncs = func() template.FuncMap {
"concat": func(items ...string) string {
return strings.Join(items, "")
},
+ "unique": func(key string, results []decoratedGJSONResult) []decoratedGJSONResult {
+ seen := make(map[string]struct{})
+ out := make([]decoratedGJSONResult, 0, len(results))
+ for _, result := range results {
+ val := result.String(key)
+ if _, ok := seen[val]; !ok {
+ seen[val] = struct{}{}
+ out = append(out, result)
+ }
+ }
+ return out
+ },
}
for key, value := range globalTemplateFunctions {