feedreader / pluto

pluto gems - planet feed reader and (static) website generator - auto-build web pages from published web feeds
Creative Commons Zero v1.0 Universal
192 stars 14 forks source link

Youtube feeds don't print in order #35

Closed infominer33 closed 3 years ago

infominer33 commented 3 years ago

Trying to build a page for youtube feeds, but they don't print in chronological order:

This is with the same template that's running my other feeds that are coming out fine.

https://identosphere.net/blogcatcher/test/

image

I tried looking at the youtube feed, but nothing really jumps out at me why it shouldn't print correctly:

<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns:yt="http://www.youtube.com/xml/schemas/2015" xmlns:media="http://search.yahoo.com/mrss/" xmlns="http://www.w3.org/2005/Atom">
 <link rel="self" href="http://www.youtube.com/feeds/videos.xml?channel_id=UCaMfVoHQzwX47XKUawWVCzg"/>
 <id>yt:channel:UCaMfVoHQzwX47XKUawWVCzg</id>
 <yt:channelId>UCaMfVoHQzwX47XKUawWVCzg</yt:channelId>
 <title>Bloom</title>
 <link rel="alternate" href="https://www.youtube.com/channel/UCaMfVoHQzwX47XKUawWVCzg"/>
 <author>
  <name>Bloom</name>
  <uri>https://www.youtube.com/channel/UCaMfVoHQzwX47XKUawWVCzg</uri>
 </author>
 <published>2017-10-11T19:32:16+00:00</published>
 <entry>
  <id>yt:video:yoGUqljxxro</id>
  <yt:videoId>yoGUqljxxro</yt:videoId>
  <yt:channelId>UCaMfVoHQzwX47XKUawWVCzg</yt:channelId>
  <title>Videoguide di Bloom 004 - Verifica la proprietà dei tuoi account di social network</title>
  <link rel="alternate" href="https://www.youtube.com/watch?v=yoGUqljxxro"/>
  <author>
   <name>Bloom</name>
   <uri>https://www.youtube.com/channel/UCaMfVoHQzwX47XKUawWVCzg</uri>
  </author>
  <published>2020-06-09T01:54:49+00:00</published>
  <updated>2020-08-25T20:28:49+00:00</updated>
  <media:group>
   <media:title>Videoguide di Bloom 004 - Verifica la proprietà dei tuoi account di social network</media:title>
   <media:content url="https://www.youtube.com/v/yoGUqljxxro?version=3" type="application/x-shockwave-flash" width="640" height="390"/>
   <media:thumbnail url="https://i2.ytimg.com/vi/yoGUqljxxro/hqdefault.jpg" width="480" height="360"/>
   <media:description>In questa Guida Bloom daremo una rapida occhiata a come attestare i vostri account Facebook, Twitter, Google e LinkedIn. Questo aiuta a convalidare la vostra identità e vi fornisce ulteriori dati che possono essere condivisi in modo appropriato.

Visita https://bloom.co/identity per ulteriori informazioni su BloomID e invia un'email a support@bloom.co per eventuali domande.

Scarica l'applicazione mobile all'indirizzo https://go.onelink.me/9Fr3/198b98f3.

Ulteriori informazioni:

- Sito Web: https://bloom.co
- Blog: https://bloom.co/blog</media:description>
   <media:community>
    <media:starRating count="2" average="3.00" min="1" max="5"/>
    <media:statistics views="100"/>
   </media:community>
  </media:group>
 </entry>
geraldb commented 3 years ago

A feed item usually has at least two dates:

Here's the entry from the post from the youtube feed in xml:

 <published>2019-11-29T04:05:38+00:00</published>
 <updated>2020-08-25T23:25:40+00:00</updated>

As far as I can tell you sort by updated BUT in your template - please check - you print the published date and NOT the updated date - try to change to update to fix.

infominer33 commented 3 years ago

In the template, there doesn't seem to be any sorting method, but somehow they just automagically print in reverse chronological order.

<%
   items = site.items.latest.limit(250)
   ItemCursor.new( items ).each do |item, new_date, new_feed|
%>

<% if new_date %>
 <h2 class='new-date'>
  <%= item.published.strftime('%A, %d. %B %Y') %>
 </h2>
<% else %>
  <hr class='item-seperator'>
<% end %>

With a simple sort_by I can force these youtube feeds into shape :)

<%
   items = site.items.latest.limit(250)
   sorted = items.sort_by { |k| k["published"] }.reverse
   ItemCursor.new( sorted ).each do |item, new_date, new_feed|
%>

that was too easy.. I still dont' get how they usually stay sort.. I suppose like you say by 'updated' but I think blog posts are more frequently updated than youtube videos, and I never seen this before.

geraldb commented 3 years ago

Thanks for the update. I think inside latest the sort (auto-magically) happens. See https://github.com/feedreader/pluto/blob/master/newscast/lib/newscast.rb#L266 and this line if I am not mistaken:

  rec.items.order(
      Arel.sql( "coalesce(items.updated,items.published,'1970-01-01') desc" )
    )

Cheers. Prosit 2021!