New search function et drag and drop clean
This commit is contained in:
@ -638,3 +638,33 @@ func extractFrontMatter(path string) (frontMatter, error) {
|
||||
fm, _, err := ExtractFrontMatterAndBody(path)
|
||||
return frontMatter{Tags: fm.Tags}, err
|
||||
}
|
||||
|
||||
// TagCount représente un tag avec son nombre d'utilisations
|
||||
type TagCount struct {
|
||||
Tag string
|
||||
Count int
|
||||
}
|
||||
|
||||
// GetAllTagsWithCount retourne tous les tags avec leur nombre d'utilisations, triés par popularité
|
||||
func (i *Indexer) GetAllTagsWithCount() []TagCount {
|
||||
i.mu.RLock()
|
||||
defer i.mu.RUnlock()
|
||||
|
||||
result := make([]TagCount, 0, len(i.tags))
|
||||
for tag, files := range i.tags {
|
||||
result = append(result, TagCount{
|
||||
Tag: tag,
|
||||
Count: len(files),
|
||||
})
|
||||
}
|
||||
|
||||
// Trier par popularité (nombre décroissant), puis par nom alphabétique
|
||||
sort.Slice(result, func(a, b int) bool {
|
||||
if result[a].Count == result[b].Count {
|
||||
return result[a].Tag < result[b].Tag
|
||||
}
|
||||
return result[a].Count > result[b].Count
|
||||
})
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user