-
Notifications
You must be signed in to change notification settings - Fork 0
/
topic.go
52 lines (43 loc) · 1.09 KB
/
topic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package apidocs
import (
"path/filepath"
"sort"
"strings"
)
// Topic represents an asciibinder topic
type Topic struct {
Name string `yaml:"Name"`
File string `yaml:"File,omitempty"`
Dir string `yaml:"Dir,omitempty"`
Distros string `yaml:"Distros,omitempty"`
Topics []Topic `yaml:"Topics,omitempty"`
}
func BuildTopics(pages Pages) []Topic {
m := make(map[string]Topic)
for _, page := range pages {
path := page.OutputPath()
parentName := page.ParentTopicName()
parent, found := m[parentName]
if !found {
parent = Topic{
Name: parentName,
Dir: filepath.Base(filepath.Dir(path)),
}
}
child := Topic{
Name: page.Title(),
File: strings.TrimSuffix(filepath.Base(path), ".adoc"),
}
parent.Topics = append(parent.Topics, child)
m[parentName] = parent
}
parents := make([]Topic, 0, len(m))
for _, parent := range m {
sort.Sort(childTopicsByName(parent.Topics))
parents = append(parents, parent)
}
sort.Sort(parentTopicsByVersion(parents))
sort.Stable(parentTopicsByGroup(parents))
sort.Stable(parentTopicsByRoot(parents))
return parents
}