Move hasAlternateDumplicateLinks from feed to link in order to also use it elsewhere
This commit is contained in:
parent
656ae8ad46
commit
6782d0c847
19
feed.go
19
feed.go
@ -26,25 +26,6 @@ type Feed struct {
|
|||||||
Entries []*Entry `xml:"entry,omitempty"`
|
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.
|
// NewFeed creates a new feed.
|
||||||
func NewFeed(title string) (*Feed, error) {
|
func NewFeed(title string) (*Feed, error) {
|
||||||
text, err := NewText("text", title)
|
text, err := NewText("text", title)
|
||||||
|
19
link.go
19
link.go
@ -37,3 +37,22 @@ func (l *Link) Check() error {
|
|||||||
|
|
||||||
return nil
|
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