Check for links with "alternate" ref and duplicate type and hreflang attributes
This commit is contained in:
parent
e1ba1b8277
commit
05cc967ea8
22
feed.go
22
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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user