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

This commit is contained in:
Ralph Ocdol 2025-04-13 10:46:43 +08:00
parent eeda2104a6
commit db97871945

View File

@ -547,6 +547,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 {