From 33fdb2c489727f8af972d69506fef02c121c4fd0 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sun, 22 Dec 2019 22:18:21 -0800 Subject: Add support for Atom 0.3 --- reader/atom/atom_common.go | 68 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 reader/atom/atom_common.go (limited to 'reader/atom/atom_common.go') diff --git a/reader/atom/atom_common.go b/reader/atom/atom_common.go new file mode 100644 index 0000000..85e6b29 --- /dev/null +++ b/reader/atom/atom_common.go @@ -0,0 +1,68 @@ +// 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, contentType string) string { + for _, link := range a { + if strings.ToLower(link.Rel) == relation && strings.ToLower(link.Type) == contentType { + return strings.TrimSpace(link.URL) + } + } + + return "" +} -- cgit v1.2.3