Compare commits
No commits in common. "9920e077ebb5f5bc176bc7182b76365670932615" and "656ae8ad46c68cbc4900660a0a97d9d337a6af93" have entirely different histories.
9920e077eb
...
656ae8ad46
3
entry.go
3
entry.go
@ -104,9 +104,6 @@ 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,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)
|
||||
@ -170,7 +189,7 @@ func (f *Feed) Check() error {
|
||||
}
|
||||
}
|
||||
if hasAlternateDuplicateLinks(f.Links) {
|
||||
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)
|
||||
return errors.New("links with with a rel attribute value of \"alternate\" and duplicate type and hreflang attribute values found")
|
||||
}
|
||||
|
||||
if f.Logo != nil {
|
||||
|
19
link.go
19
link.go
@ -37,22 +37,3 @@ 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