mirror of
https://github.com/miniflux/v2.git
synced 2025-09-15 18:57:04 +00:00
refactor: unexport symbols
This commit is contained in:
parent
a4d51b5586
commit
566670cc06
36 changed files with 369 additions and 376 deletions
|
|
@ -19,15 +19,11 @@ import (
|
|||
"miniflux.app/v2/internal/urllib"
|
||||
)
|
||||
|
||||
type RSSAdapter struct {
|
||||
rss *RSS
|
||||
type rssAdapter struct {
|
||||
rss *rss
|
||||
}
|
||||
|
||||
func NewRSSAdapter(rss *RSS) *RSSAdapter {
|
||||
return &RSSAdapter{rss}
|
||||
}
|
||||
|
||||
func (r *RSSAdapter) BuildFeed(baseURL string) *model.Feed {
|
||||
func (r *rssAdapter) buildFeed(baseURL string) *model.Feed {
|
||||
feed := &model.Feed{
|
||||
Title: html.UnescapeString(strings.TrimSpace(r.rss.Channel.Title)),
|
||||
FeedURL: strings.TrimSpace(baseURL),
|
||||
|
|
@ -145,7 +141,7 @@ func (r *RSSAdapter) BuildFeed(baseURL string) *model.Feed {
|
|||
return feed
|
||||
}
|
||||
|
||||
func findFeedAuthor(rssChannel *RSSChannel) string {
|
||||
func findFeedAuthor(rssChannel *rssChannel) string {
|
||||
var author string
|
||||
switch {
|
||||
case rssChannel.ItunesAuthor != "":
|
||||
|
|
@ -165,7 +161,7 @@ func findFeedAuthor(rssChannel *RSSChannel) string {
|
|||
return strings.TrimSpace(sanitizer.StripTags(author))
|
||||
}
|
||||
|
||||
func findFeedTags(rssChannel *RSSChannel) []string {
|
||||
func findFeedTags(rssChannel *rssChannel) []string {
|
||||
tags := make([]string, 0)
|
||||
|
||||
for _, tag := range rssChannel.Categories {
|
||||
|
|
@ -189,7 +185,7 @@ func findFeedTags(rssChannel *RSSChannel) []string {
|
|||
return tags
|
||||
}
|
||||
|
||||
func findEntryTitle(rssItem *RSSItem) string {
|
||||
func findEntryTitle(rssItem *rssItem) string {
|
||||
title := rssItem.Title.Content
|
||||
|
||||
if rssItem.DublinCoreTitle != "" {
|
||||
|
|
@ -199,7 +195,7 @@ func findEntryTitle(rssItem *RSSItem) string {
|
|||
return html.UnescapeString(html.UnescapeString(strings.TrimSpace(title)))
|
||||
}
|
||||
|
||||
func findEntryURL(rssItem *RSSItem) string {
|
||||
func findEntryURL(rssItem *rssItem) string {
|
||||
for _, link := range []string{rssItem.FeedBurnerLink, rssItem.Link} {
|
||||
if link != "" {
|
||||
return strings.TrimSpace(link)
|
||||
|
|
@ -222,7 +218,7 @@ func findEntryURL(rssItem *RSSItem) string {
|
|||
return ""
|
||||
}
|
||||
|
||||
func findEntryContent(rssItem *RSSItem) string {
|
||||
func findEntryContent(rssItem *rssItem) string {
|
||||
for _, value := range []string{
|
||||
rssItem.DublinCoreContent,
|
||||
rssItem.Description,
|
||||
|
|
@ -237,7 +233,7 @@ func findEntryContent(rssItem *RSSItem) string {
|
|||
return ""
|
||||
}
|
||||
|
||||
func findEntryDate(rssItem *RSSItem) time.Time {
|
||||
func findEntryDate(rssItem *rssItem) time.Time {
|
||||
value := rssItem.PubDate
|
||||
if rssItem.DublinCoreDate != "" {
|
||||
value = rssItem.DublinCoreDate
|
||||
|
|
@ -260,7 +256,7 @@ func findEntryDate(rssItem *RSSItem) time.Time {
|
|||
return time.Now()
|
||||
}
|
||||
|
||||
func findEntryAuthor(rssItem *RSSItem) string {
|
||||
func findEntryAuthor(rssItem *rssItem) string {
|
||||
var author string
|
||||
|
||||
switch {
|
||||
|
|
@ -283,7 +279,7 @@ func findEntryAuthor(rssItem *RSSItem) string {
|
|||
return strings.TrimSpace(sanitizer.StripTags(author))
|
||||
}
|
||||
|
||||
func findEntryTags(rssItem *RSSItem) []string {
|
||||
func findEntryTags(rssItem *rssItem) []string {
|
||||
tags := make([]string, 0)
|
||||
|
||||
for _, tag := range rssItem.Categories {
|
||||
|
|
@ -303,7 +299,7 @@ func findEntryTags(rssItem *RSSItem) []string {
|
|||
return tags
|
||||
}
|
||||
|
||||
func findEntryEnclosures(rssItem *RSSItem, siteURL string) model.EnclosureList {
|
||||
func findEntryEnclosures(rssItem *rssItem, siteURL string) model.EnclosureList {
|
||||
enclosures := make(model.EnclosureList, 0)
|
||||
duplicates := make(map[string]bool)
|
||||
|
||||
|
|
|
|||
|
|
@ -7,14 +7,14 @@ import (
|
|||
"miniflux.app/v2/internal/reader/atom"
|
||||
)
|
||||
|
||||
type AtomAuthor struct {
|
||||
type atomAuthor struct {
|
||||
Author atom.AtomPerson `xml:"http://www.w3.org/2005/Atom author"`
|
||||
}
|
||||
|
||||
func (a *AtomAuthor) PersonName() string {
|
||||
func (a *atomAuthor) PersonName() string {
|
||||
return a.Author.PersonName()
|
||||
}
|
||||
|
||||
type AtomLinks struct {
|
||||
type atomLinks struct {
|
||||
Links []*atom.AtomLink `xml:"http://www.w3.org/2005/Atom link"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
package rss // import "miniflux.app/v2/internal/reader/rss"
|
||||
|
||||
// FeedBurnerItemElement represents FeedBurner XML elements.
|
||||
type FeedBurnerItemElement struct {
|
||||
// feedBurnerItemElement represents FeedBurner XML elements.
|
||||
type feedBurnerItemElement struct {
|
||||
FeedBurnerLink string `xml:"http://rssnamespace.org/feedburner/ext/1.0 origLink"`
|
||||
FeedBurnerEnclosureLink string `xml:"http://rssnamespace.org/feedburner/ext/1.0 origEnclosureLink"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,11 +13,12 @@ import (
|
|||
|
||||
// Parse returns a normalized feed struct from a RSS feed.
|
||||
func Parse(baseURL string, data io.ReadSeeker) (*model.Feed, error) {
|
||||
rssFeed := new(RSS)
|
||||
rssFeed := new(rss)
|
||||
decoder := xml.NewXMLDecoder(data)
|
||||
decoder.DefaultSpace = "rss"
|
||||
if err := decoder.Decode(rssFeed); err != nil {
|
||||
return nil, fmt.Errorf("rss: unable to parse feed: %w", err)
|
||||
}
|
||||
return NewRSSAdapter(rssFeed).BuildFeed(baseURL), nil
|
||||
adapter := &rssAdapter{rssFeed}
|
||||
return adapter.buildFeed(baseURL), nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,20 +10,20 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
var ErrInvalidDurationFormat = errors.New("rss: invalid duration format")
|
||||
var errInvalidDurationFormat = errors.New("rss: invalid duration format")
|
||||
|
||||
func getDurationInMinutes(rawDuration string) (int, error) {
|
||||
var sumSeconds int
|
||||
|
||||
durationParts := strings.Split(rawDuration, ":")
|
||||
if len(durationParts) > 3 {
|
||||
return 0, ErrInvalidDurationFormat
|
||||
return 0, errInvalidDurationFormat
|
||||
}
|
||||
|
||||
for i, durationPart := range durationParts {
|
||||
durationPartValue, err := strconv.Atoi(durationPart)
|
||||
if err != nil {
|
||||
return 0, ErrInvalidDurationFormat
|
||||
return 0, errInvalidDurationFormat
|
||||
}
|
||||
|
||||
sumSeconds += int(math.Pow(60, float64(len(durationParts)-i-1))) * durationPartValue
|
||||
|
|
|
|||
|
|
@ -15,15 +15,15 @@ import (
|
|||
)
|
||||
|
||||
// Specs: https://www.rssboard.org/rss-specification
|
||||
type RSS struct {
|
||||
type rss struct {
|
||||
// Version is the version of the RSS specification.
|
||||
Version string `xml:"rss version,attr"`
|
||||
|
||||
// Channel is the main container for the RSS feed.
|
||||
Channel RSSChannel `xml:"rss channel"`
|
||||
Channel rssChannel `xml:"rss channel"`
|
||||
}
|
||||
|
||||
type RSSChannel struct {
|
||||
type rssChannel struct {
|
||||
// Title is the name of the channel.
|
||||
Title string `xml:"rss title"`
|
||||
|
||||
|
|
@ -64,10 +64,10 @@ type RSSChannel struct {
|
|||
DocumentationURL string `xml:"rss docs"`
|
||||
|
||||
// Cloud is a web service that supports the rssCloud interface which can be implemented in HTTP-POST, XML-RPC or SOAP 1.1.
|
||||
Cloud *RSSCloud `xml:"rss cloud"`
|
||||
Cloud *rssCloud `xml:"rss cloud"`
|
||||
|
||||
// Image specifies a GIF, JPEG or PNG image that can be displayed with the channel.
|
||||
Image *RSSImage `xml:"rss image"`
|
||||
Image *rssImage `xml:"rss image"`
|
||||
|
||||
// TTL is a number of minutes that indicates how long a channel can be cached before refreshing from the source.
|
||||
TTL string `xml:"rss ttl"`
|
||||
|
|
@ -83,14 +83,14 @@ type RSSChannel struct {
|
|||
SkipDays []string `xml:"rss skipDays>day"`
|
||||
|
||||
// Items is a collection of items.
|
||||
Items []RSSItem `xml:"rss item"`
|
||||
Items []rssItem `xml:"rss item"`
|
||||
|
||||
AtomLinks
|
||||
atomLinks
|
||||
itunes.ItunesChannelElement
|
||||
googleplay.GooglePlayChannelElement
|
||||
}
|
||||
|
||||
type RSSCloud struct {
|
||||
type rssCloud struct {
|
||||
Domain string `xml:"domain,attr"`
|
||||
Port string `xml:"port,attr"`
|
||||
Path string `xml:"path,attr"`
|
||||
|
|
@ -98,7 +98,7 @@ type RSSCloud struct {
|
|||
Protocol string `xml:"protocol,attr"`
|
||||
}
|
||||
|
||||
type RSSImage struct {
|
||||
type rssImage struct {
|
||||
// URL is the URL of a GIF, JPEG or PNG image that represents the channel.
|
||||
URL string `xml:"url"`
|
||||
|
||||
|
|
@ -109,9 +109,9 @@ type RSSImage struct {
|
|||
Link string `xml:"link"`
|
||||
}
|
||||
|
||||
type RSSItem struct {
|
||||
type rssItem struct {
|
||||
// Title is the title of the item.
|
||||
Title InnerContent `xml:"rss title"`
|
||||
Title innerContent `xml:"rss title"`
|
||||
|
||||
// Link is the URL of the item.
|
||||
Link string `xml:"rss link"`
|
||||
|
|
@ -120,7 +120,7 @@ type RSSItem struct {
|
|||
Description string `xml:"rss description"`
|
||||
|
||||
// Author is the email address of the author of the item.
|
||||
Author RSSAuthor `xml:"rss author"`
|
||||
Author rssAuthor `xml:"rss author"`
|
||||
|
||||
// <category> is an optional sub-element of <item>.
|
||||
// It has one optional attribute, domain, a string that identifies a categorization taxonomy.
|
||||
|
|
@ -133,7 +133,7 @@ type RSSItem struct {
|
|||
// <enclosure> is an optional sub-element of <item>.
|
||||
// It has three required attributes. url says where the enclosure is located,
|
||||
// length says how big it is in bytes, and type says what its type is, a standard MIME type.
|
||||
Enclosures []RSSEnclosure `xml:"rss enclosure"`
|
||||
Enclosures []rssEnclosure `xml:"rss enclosure"`
|
||||
|
||||
// <guid> is an optional sub-element of <item>.
|
||||
// It's a string that uniquely identifies the item.
|
||||
|
|
@ -149,7 +149,7 @@ type RSSItem struct {
|
|||
//
|
||||
// isPermaLink is optional, its default value is true.
|
||||
// If its value is false, the guid may not be assumed to be a url, or a url to anything in particular.
|
||||
GUID RSSGUID `xml:"rss guid"`
|
||||
GUID rssGUID `xml:"rss guid"`
|
||||
|
||||
// <pubDate> is the publication date of the item.
|
||||
// Its value is a string in RFC 822 format.
|
||||
|
|
@ -158,30 +158,30 @@ type RSSItem struct {
|
|||
// <source> is an optional sub-element of <item>.
|
||||
// Its value is the name of the RSS channel that the item came from, derived from its <title>.
|
||||
// It has one required attribute, url, which contains the URL of the RSS channel.
|
||||
Source RSSSource `xml:"rss source"`
|
||||
Source rssSource `xml:"rss source"`
|
||||
|
||||
dublincore.DublinCoreItemElement
|
||||
FeedBurnerItemElement
|
||||
feedBurnerItemElement
|
||||
media.MediaItemElement
|
||||
AtomAuthor
|
||||
AtomLinks
|
||||
atomAuthor
|
||||
atomLinks
|
||||
itunes.ItunesItemElement
|
||||
googleplay.GooglePlayItemElement
|
||||
}
|
||||
|
||||
type RSSAuthor struct {
|
||||
type rssAuthor struct {
|
||||
XMLName xml.Name
|
||||
Data string `xml:",chardata"`
|
||||
Inner string `xml:",innerxml"`
|
||||
}
|
||||
|
||||
type RSSEnclosure struct {
|
||||
type rssEnclosure struct {
|
||||
URL string `xml:"url,attr"`
|
||||
Type string `xml:"type,attr"`
|
||||
Length string `xml:"length,attr"`
|
||||
}
|
||||
|
||||
func (enclosure *RSSEnclosure) Size() int64 {
|
||||
func (enclosure *rssEnclosure) Size() int64 {
|
||||
if strings.TrimSpace(enclosure.Length) == "" {
|
||||
return 0
|
||||
}
|
||||
|
|
@ -189,21 +189,21 @@ func (enclosure *RSSEnclosure) Size() int64 {
|
|||
return size
|
||||
}
|
||||
|
||||
type RSSGUID struct {
|
||||
type rssGUID struct {
|
||||
Data string `xml:",chardata"`
|
||||
IsPermaLink string `xml:"isPermaLink,attr"`
|
||||
}
|
||||
|
||||
type RSSSource struct {
|
||||
type rssSource struct {
|
||||
URL string `xml:"url,attr"`
|
||||
Name string `xml:",chardata"`
|
||||
}
|
||||
|
||||
type InnerContent struct {
|
||||
type innerContent struct {
|
||||
Content string
|
||||
}
|
||||
|
||||
func (ic *InnerContent) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
func (ic *innerContent) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
var content strings.Builder
|
||||
|
||||
for {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue