1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-09-30 19:22:11 +00:00

First commit

This commit is contained in:
Frédéric Guillot 2017-11-19 21:10:04 -08:00
commit 8ffb773f43
2121 changed files with 1118910 additions and 0 deletions

82
reader/opml/opml.go Normal file
View file

@ -0,0 +1,82 @@
// Copyright 2017 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 opml
import "encoding/xml"
type Opml struct {
XMLName xml.Name `xml:"opml"`
Version string `xml:"version,attr"`
Outlines []Outline `xml:"body>outline"`
}
type Outline struct {
Title string `xml:"title,attr,omitempty"`
Text string `xml:"text,attr"`
FeedURL string `xml:"xmlUrl,attr,omitempty"`
SiteURL string `xml:"htmlUrl,attr,omitempty"`
Outlines []Outline `xml:"outline,omitempty"`
}
func (o *Outline) GetTitle() string {
if o.Title != "" {
return o.Title
}
if o.Text != "" {
return o.Text
}
if o.SiteURL != "" {
return o.SiteURL
}
if o.FeedURL != "" {
return o.FeedURL
}
return ""
}
func (o *Outline) GetSiteURL() string {
if o.SiteURL != "" {
return o.SiteURL
}
return o.FeedURL
}
func (o *Outline) IsCategory() bool {
return o.Text != "" && o.SiteURL == "" && o.FeedURL == ""
}
func (o *Outline) Append(subscriptions SubcriptionList, category string) SubcriptionList {
if o.FeedURL != "" {
subscriptions = append(subscriptions, &Subcription{
Title: o.GetTitle(),
FeedURL: o.FeedURL,
SiteURL: o.GetSiteURL(),
CategoryName: category,
})
}
return subscriptions
}
func (o *Opml) Transform() SubcriptionList {
var subscriptions SubcriptionList
for _, outline := range o.Outlines {
if outline.IsCategory() {
for _, element := range outline.Outlines {
subscriptions = element.Append(subscriptions, outline.Text)
}
} else {
subscriptions = outline.Append(subscriptions, "")
}
}
return subscriptions
}