Move hasAlternateDumplicateLinks from feed to link in order to also use it elsewhere

This commit is contained in:
Jason Streifling 2024-10-15 18:44:02 +02:00
parent 656ae8ad46
commit 6782d0c847
2 changed files with 19 additions and 19 deletions

19
feed.go
View File

@ -26,25 +26,6 @@ type Feed struct {
Entries []*Entry `xml:"entry,omitempty"`
}
// atom:feed elements MUST NOT contain more than one atom:link element with a
// rel attribute value of "alternate" that has the same combination of type and
// hreflang attribute values.
func hasAlternateDuplicateLinks(l []*Link) bool {
linkMap := make(map[string]bool)
for _, link := range l {
if link.Rel == "alternate" {
key := fmt.Sprint(link.Type, "|", link.HrefLang)
if linkMap[key] {
return true
}
linkMap[key] = true
}
}
return false
}
// NewFeed creates a new feed.
func NewFeed(title string) (*Feed, error) {
text, err := NewText("text", title)

19
link.go
View File

@ -37,3 +37,22 @@ func (l *Link) Check() error {
return nil
}
// atom:feed/entry elements MUST NOT contain more than one atom:link element
// with a rel attribute value of "alternate" that has the same combination of
// type and hreflang attribute values.
func hasAlternateDuplicateLinks(l []*Link) bool {
linkMap := make(map[string]bool)
for _, link := range l {
if link.Rel == "alternate" {
key := fmt.Sprint(link.Type, "|", link.HrefLang)
if linkMap[key] {
return true
}
linkMap[key] = true
}
}
return false
}