diff --git a/feed.go b/feed.go index 956a750..8e6f53c 100644 --- a/feed.go +++ b/feed.go @@ -26,6 +26,25 @@ 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) @@ -172,6 +191,9 @@ func (f *Feed) Check() error { } } } + if hasAlternateDuplicateLinks(f.Links) { + return errors.New("duplicate links with with a rel attribute value of \"alternate\" found") + } if f.Logo != nil { if err := f.Logo.Check(); err != nil {