mirror of
https://github.com/glanceapp/glance.git
synced 2025-06-21 18:31:24 +02:00
added unique to filter arrays with unique items in custom-api
This commit is contained in:
parent
97f43f88eb
commit
d5b89d512a
@ -543,6 +543,18 @@ var customAPITemplateFuncs = func() template.FuncMap {
|
|||||||
"concat": func(items ...string) string {
|
"concat": func(items ...string) string {
|
||||||
return strings.Join(items, "")
|
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 {
|
for key, value := range globalTemplateFunctions {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user