Compare commits
2 Commits
656ae8ad46
...
9920e077eb
Author | SHA1 | Date | |
---|---|---|---|
9920e077eb | |||
6782d0c847 |
3
entry.go
3
entry.go
@ -104,6 +104,9 @@ func (e *Entry) Check() error {
|
||||
return fmt.Errorf("link element %v of entry %v: %v", i, e.ID.URI, err)
|
||||
}
|
||||
}
|
||||
if hasAlternateDuplicateLinks(e.Links) {
|
||||
return fmt.Errorf("links with with a rel attribute value of \"alternate\" and duplicate type and hreflang attribute values found in entry %v", e.ID.URI)
|
||||
}
|
||||
|
||||
if e.Published != nil {
|
||||
if err := e.Published.Check(); err != nil {
|
||||
|
21
feed.go
21
feed.go
@ -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)
|
||||
@ -189,7 +170,7 @@ func (f *Feed) Check() error {
|
||||
}
|
||||
}
|
||||
if hasAlternateDuplicateLinks(f.Links) {
|
||||
return errors.New("links with with a rel attribute value of \"alternate\" and duplicate type and hreflang attribute values found")
|
||||
return fmt.Errorf("links with with a rel attribute value of \"alternate\" and duplicate type and hreflang attribute values found in feed %v", f.ID.URI)
|
||||
}
|
||||
|
||||
if f.Logo != nil {
|
||||
|
19
link.go
19
link.go
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user