2023-06-19 23:42:47 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2019-12-23 07:18:21 +01:00
|
|
|
|
2023-08-10 06:15:55 +02:00
|
|
|
package atom // import "miniflux.app/v2/reader/atom"
|
2019-12-23 07:18:21 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2022-01-15 05:12:22 +01:00
|
|
|
type atomAuthors []*atomPerson
|
|
|
|
|
|
|
|
func (a atomAuthors) String() string {
|
|
|
|
var authors []string
|
|
|
|
|
|
|
|
for _, person := range a {
|
|
|
|
authors = append(authors, person.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
return strings.Join(authors, ", ")
|
|
|
|
}
|
|
|
|
|
2019-12-23 07:18:21 +01:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2022-08-01 02:23:58 +02:00
|
|
|
if link.Rel == "" && (link.Type == "" || link.Type == "text/html") {
|
2019-12-23 07:18:21 +01:00
|
|
|
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 ""
|
|
|
|
}
|
|
|
|
|
2020-01-05 00:56:00 +01:00
|
|
|
func (a atomLinks) firstLinkWithRelationAndType(relation string, contentTypes ...string) string {
|
2019-12-23 07:18:21 +01:00
|
|
|
for _, link := range a {
|
2020-01-05 00:56:00 +01:00
|
|
|
if strings.ToLower(link.Rel) == relation {
|
|
|
|
for _, contentType := range contentTypes {
|
|
|
|
if strings.ToLower(link.Type) == contentType {
|
|
|
|
return strings.TrimSpace(link.URL)
|
|
|
|
}
|
|
|
|
}
|
2019-12-23 07:18:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ""
|
|
|
|
}
|