Order stories by feed publish time, not ingest time
This commit is contained in:
@@ -28,6 +28,7 @@ type FeedItem struct {
|
||||
ArticleURL string
|
||||
Source string
|
||||
DirectRoute string
|
||||
PublishedAt int64 // unix seconds from RSS pubDate / Atom published (or updated as fallback); 0 if absent or unparseable
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -53,11 +54,12 @@ func FetchFeed(feedURL string) ([]FeedItem, error) {
|
||||
items := make([]FeedItem, 0, len(feed.Items))
|
||||
for _, item := range feed.Items {
|
||||
fi := FeedItem{
|
||||
GUID: itemGUID(item),
|
||||
Headline: strings.TrimSpace(item.Title),
|
||||
Lede: extractLede(item.Description),
|
||||
ImageURL: NormalizeImageURL(extractImageURL(item)),
|
||||
ArticleURL: strings.TrimSpace(item.Link),
|
||||
GUID: itemGUID(item),
|
||||
Headline: strings.TrimSpace(item.Title),
|
||||
Lede: extractLede(item.Description),
|
||||
ImageURL: NormalizeImageURL(extractImageURL(item)),
|
||||
ArticleURL: strings.TrimSpace(item.Link),
|
||||
PublishedAt: itemPublished(item),
|
||||
}
|
||||
if fi.GUID == "" || fi.ArticleURL == "" {
|
||||
continue
|
||||
@@ -76,6 +78,19 @@ func itemGUID(item *gofeed.Item) string {
|
||||
return item.Link
|
||||
}
|
||||
|
||||
// itemPublished returns the item's publish time as unix seconds, falling back
|
||||
// to the updated time if pubDate was absent. Returns 0 when neither parses;
|
||||
// the poller clamps future timestamps to ingest time.
|
||||
func itemPublished(item *gofeed.Item) int64 {
|
||||
if item.PublishedParsed != nil {
|
||||
return item.PublishedParsed.Unix()
|
||||
}
|
||||
if item.UpdatedParsed != nil {
|
||||
return item.UpdatedParsed.Unix()
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// extractLede returns the feed description verbatim, with HTML stripped.
|
||||
func extractLede(desc string) string {
|
||||
if desc == "" {
|
||||
|
||||
Reference in New Issue
Block a user