Discard duplicated tags

This commit is contained in:
Deluan
2023-12-26 19:35:14 -05:00
parent b4815ecee5
commit ea7ba22699
2 changed files with 29 additions and 0 deletions
+16
View File
@@ -57,6 +57,9 @@ func Extract(files ...string) (map[string]Tags, error) {
}
func NewTag(filePath string, fileInfo os.FileInfo, tags ParsedTags) Tags {
for t, values := range tags {
tags[t] = removeDuplicates(values)
}
return Tags{
filePath: filePath,
fileInfo: fileInfo,
@@ -64,6 +67,19 @@ func NewTag(filePath string, fileInfo os.FileInfo, tags ParsedTags) Tags {
}
}
func removeDuplicates(values []string) []string {
encountered := map[string]struct{}{}
var result []string
for _, v := range values {
if _, ok := encountered[v]; ok {
continue
}
encountered[v] = struct{}{}
result = append(result, v)
}
return result
}
type ParsedTags map[string][]string
func (p ParsedTags) Map(customMappings ParsedTags) ParsedTags {