docs/pkg/help/templates.go
Snider 0c474a82d0 refactor(help): remove html/template dependency
All rendering now uses go-html HLCRF layout.
Templates directory and template parsing code removed.

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-06 16:37:53 +00:00

46 lines
1 KiB
Go

// SPDX-Licence-Identifier: EUPL-1.2
package help
import (
"cmp"
"slices"
)
// topicGroup groups topics under a tag for the index page.
type topicGroup struct {
Tag string
Topics []*Topic
}
// groupTopicsByTag groups topics by their first tag.
// Topics without tags are grouped under "other".
// Groups are sorted alphabetically by tag name.
func groupTopicsByTag(topics []*Topic) []topicGroup {
// Sort topics first by Order then Title
sorted := slices.Clone(topics)
slices.SortFunc(sorted, func(a, b *Topic) int {
if a.Order != b.Order {
return cmp.Compare(a.Order, b.Order)
}
return cmp.Compare(a.Title, b.Title)
})
groups := make(map[string][]*Topic)
for _, t := range sorted {
tag := "other"
if len(t.Tags) > 0 {
tag = t.Tags[0]
}
groups[tag] = append(groups[tag], t)
}
var result []topicGroup
for tag, topics := range groups {
result = append(result, topicGroup{Tag: tag, Topics: topics})
}
slices.SortFunc(result, func(a, b topicGroup) int {
return cmp.Compare(a.Tag, b.Tag)
})
return result
}