mirror of
https://github.com/miniflux/v2.git
synced 2025-06-27 16:36:00 +00:00
Improve Dublin Core support for RDF feeds
This commit is contained in:
parent
1b33bb3d1c
commit
200b1c304b
3 changed files with 86 additions and 15 deletions
|
@ -21,8 +21,8 @@ type rdfFeed struct {
|
|||
XMLName xml.Name `xml:"RDF"`
|
||||
Title string `xml:"channel>title"`
|
||||
Link string `xml:"channel>link"`
|
||||
Creator string `xml:"channel>creator"`
|
||||
Items []rdfItem `xml:"item"`
|
||||
DublinCoreFeedElement
|
||||
}
|
||||
|
||||
func (r *rdfFeed) Transform() *model.Feed {
|
||||
|
@ -32,9 +32,10 @@ func (r *rdfFeed) Transform() *model.Feed {
|
|||
|
||||
for _, item := range r.Items {
|
||||
entry := item.Transform()
|
||||
if entry.Author == "" && r.Creator != "" {
|
||||
entry.Author = sanitizer.StripTags(r.Creator)
|
||||
if entry.Author == "" && r.DublinCoreCreator != "" {
|
||||
entry.Author = strings.TrimSpace(r.DublinCoreCreator)
|
||||
}
|
||||
entry.Author = sanitizer.StripTags(entry.Author)
|
||||
|
||||
if entry.URL == "" {
|
||||
entry.URL = feed.SiteURL
|
||||
|
@ -55,24 +56,44 @@ type rdfItem struct {
|
|||
Title string `xml:"title"`
|
||||
Link string `xml:"link"`
|
||||
Description string `xml:"description"`
|
||||
Creator string `xml:"creator"`
|
||||
Date string `xml:"date"`
|
||||
DublinCoreEntryElement
|
||||
}
|
||||
|
||||
func (r *rdfItem) Transform() *model.Entry {
|
||||
entry := new(model.Entry)
|
||||
entry.Title = strings.TrimSpace(r.Title)
|
||||
entry.Author = strings.TrimSpace(r.Creator)
|
||||
entry.URL = strings.TrimSpace(r.Link)
|
||||
entry.Content = r.Description
|
||||
entry.Hash = getHash(r)
|
||||
entry.Date = getDate(r)
|
||||
entry.Title = r.entryTitle()
|
||||
entry.Author = r.entryAuthor()
|
||||
entry.URL = r.entryURL()
|
||||
entry.Content = r.entryContent()
|
||||
entry.Hash = r.entryHash()
|
||||
entry.Date = r.entryDate()
|
||||
return entry
|
||||
}
|
||||
|
||||
func getDate(r *rdfItem) time.Time {
|
||||
if r.Date != "" {
|
||||
result, err := date.Parse(r.Date)
|
||||
func (r *rdfItem) entryTitle() string {
|
||||
return strings.TrimSpace(r.Title)
|
||||
}
|
||||
|
||||
func (r *rdfItem) entryContent() string {
|
||||
switch {
|
||||
case r.DublinCoreContent != "":
|
||||
return r.DublinCoreContent
|
||||
default:
|
||||
return r.Description
|
||||
}
|
||||
}
|
||||
|
||||
func (r *rdfItem) entryAuthor() string {
|
||||
return strings.TrimSpace(r.DublinCoreCreator)
|
||||
}
|
||||
|
||||
func (r *rdfItem) entryURL() string {
|
||||
return strings.TrimSpace(r.Link)
|
||||
}
|
||||
|
||||
func (r *rdfItem) entryDate() time.Time {
|
||||
if r.DublinCoreDate != "" {
|
||||
result, err := date.Parse(r.DublinCoreDate)
|
||||
if err != nil {
|
||||
logger.Error("rdf: %v", err)
|
||||
return time.Now()
|
||||
|
@ -84,7 +105,7 @@ func getDate(r *rdfItem) time.Time {
|
|||
return time.Now()
|
||||
}
|
||||
|
||||
func getHash(r *rdfItem) string {
|
||||
func (r *rdfItem) entryHash() string {
|
||||
value := r.Link
|
||||
if value == "" {
|
||||
value = r.Title + r.Description
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue