-
Notifications
You must be signed in to change notification settings - Fork 20
/
surname_index.go
50 lines (41 loc) 路 1.12 KB
/
surname_index.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
package html
import (
"github.com/elliotchance/gedcom"
"github.com/elliotchance/gedcom/html/core"
"io"
)
type SurnameIndex struct {
document *gedcom.Document
selectedLetter rune
visibility LivingVisibility
}
func NewSurnameIndex(document *gedcom.Document, selectedLetter rune, visibility LivingVisibility) *SurnameIndex {
return &SurnameIndex{
document: document,
selectedLetter: selectedLetter,
visibility: visibility,
}
}
func (c *SurnameIndex) WriteHTMLTo(w io.Writer) (int64, error) {
surnames := gedcom.NewStringSet()
for _, individual := range c.document.Individuals() {
if individual.IsLiving() {
switch c.visibility {
case LivingVisibilityHide, LivingVisibilityPlaceholder:
continue
case LivingVisibilityShow:
// Proceed.
}
}
surname := individual.Name().Surname()
if surnameStartsWith(individual, c.selectedLetter) {
surnames.Add(surname)
}
}
// Render
pills := []core.Component{}
for _, surname := range surnames.Strings() {
pills = append(pills, core.NewNavLink(surname, "#"+surname, false))
}
return core.NewNavPillsRow(pills).WriteHTMLTo(w)
}