improve handling of feeds with no summary
When testing Openring with Atom feeds like http://blog.davidchudzicki.com/feeds/posts/default and http://www.givinggladly.com/feeds/posts/default I noticed it wasn't able to pull out a text snippet. Falling back to Content if Summary is null fixes this. Content is html encoded, however, which means that we also need an UnescapeString or else Sanitize won't remove the HTML tags.
This commit is contained in:
parent
4c35eaad3b
commit
f75cc73b8b
1 changed files with 6 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"html"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
@ -114,8 +115,12 @@ func main() {
|
||||||
items = items[:perSource]
|
items = items[:perSource]
|
||||||
}
|
}
|
||||||
for _, item := range items {
|
for _, item := range items {
|
||||||
|
raw_summary := item.Summary
|
||||||
|
if len(raw_summary) == 0 {
|
||||||
|
raw_summary = html.UnescapeString(item.Content)
|
||||||
|
}
|
||||||
summary := runewidth.Truncate(
|
summary := runewidth.Truncate(
|
||||||
policy.Sanitize(item.Summary), summaryLen, "…")
|
policy.Sanitize(raw_summary), summaryLen, "…")
|
||||||
articles = append(articles, &Article{
|
articles = append(articles, &Article{
|
||||||
Date: item.Date,
|
Date: item.Date,
|
||||||
SourceLink: feed.Link,
|
SourceLink: feed.Link,
|
||||||
|
|
Loading…
Reference in a new issue