blob: 511777b60e8ed04c864057320ccac70de98a3b7a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
// Copyright 2019 Frédéric Guillot. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package atom // import "miniflux.app/reader/atom"
import "strings"
type atomPerson struct {
Name string `xml:"name"`
Email string `xml:"email"`
}
func (a *atomPerson) String() string {
name := ""
switch {
case a.Name != "":
name = a.Name
case a.Email != "":
name = a.Email
}
return strings.TrimSpace(name)
}
type atomLink struct {
URL string `xml:"href,attr"`
Type string `xml:"type,attr"`
Rel string `xml:"rel,attr"`
Length string `xml:"length,attr"`
}
type atomLinks []*atomLink
func (a atomLinks) originalLink() string {
for _, link := range a {
if strings.ToLower(link.Rel) == "alternate" {
return strings.TrimSpace(link.URL)
}
if link.Rel == "" && link.Type == "" {
return strings.TrimSpace(link.URL)
}
}
return ""
}
func (a atomLinks) firstLinkWithRelation(relation string) string {
for _, link := range a {
if strings.ToLower(link.Rel) == relation {
return strings.TrimSpace(link.URL)
}
}
return ""
}
func (a atomLinks) firstLinkWithRelationAndType(relation string, contentTypes ...string) string {
for _, link := range a {
if strings.ToLower(link.Rel) == relation {
for _, contentType := range contentTypes {
if strings.ToLower(link.Type) == contentType {
return strings.TrimSpace(link.URL)
}
}
}
}
return ""
}
|