mirror of
https://github.com/miniflux/v2.git
synced 2025-07-02 16:38:37 +00:00
Parse <category>
from Feeds (RSS, Atom and JSON)
This commit is contained in:
parent
ff8d68c151
commit
8f9ccc6540
12 changed files with 252 additions and 11 deletions
|
@ -156,6 +156,12 @@ type rssEnclosure struct {
|
|||
Length string `xml:"length,attr"`
|
||||
}
|
||||
|
||||
type rssCategory struct {
|
||||
XMLName xml.Name
|
||||
Data string `xml:",chardata"`
|
||||
Inner string `xml:",innerxml"`
|
||||
}
|
||||
|
||||
func (enclosure *rssEnclosure) Size() int64 {
|
||||
if enclosure.Length == "" {
|
||||
return 0
|
||||
|
@ -173,6 +179,7 @@ type rssItem struct {
|
|||
Authors []rssAuthor `xml:"author"`
|
||||
CommentLinks []rssCommentLink `xml:"comments"`
|
||||
EnclosureLinks []rssEnclosure `xml:"enclosure"`
|
||||
Categories []rssCategory `xml:"category"`
|
||||
DublinCoreElement
|
||||
FeedBurnerElement
|
||||
PodcastEntryElement
|
||||
|
@ -189,6 +196,8 @@ func (r *rssItem) Transform() *model.Entry {
|
|||
entry.Content = r.entryContent()
|
||||
entry.Title = r.entryTitle()
|
||||
entry.Enclosures = r.entryEnclosures()
|
||||
entry.Tags = r.entryCategories()
|
||||
|
||||
return entry
|
||||
}
|
||||
|
||||
|
@ -372,6 +381,20 @@ func (r *rssItem) entryEnclosures() model.EnclosureList {
|
|||
return enclosures
|
||||
}
|
||||
|
||||
func (r *rssItem) entryCategories() []string {
|
||||
var categoryList []string
|
||||
|
||||
for _, rssCategory := range r.Categories {
|
||||
if strings.Contains(rssCategory.Inner, "<![CDATA[") {
|
||||
categoryList = append(categoryList, strings.TrimSpace(rssCategory.Data))
|
||||
} else {
|
||||
categoryList = append(categoryList, strings.TrimSpace(rssCategory.Inner))
|
||||
}
|
||||
}
|
||||
|
||||
return categoryList
|
||||
}
|
||||
|
||||
func (r *rssItem) entryCommentsURL() string {
|
||||
for _, commentLink := range r.CommentLinks {
|
||||
if commentLink.XMLName.Space == "" {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue