-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ATOM syndication feeds to the site (#80)
The following endpoints have been defined: * Recent videos (master feed). Location: /videos/feed Purpose: always syndicates the most recent 15 videos on this site. * Videos for a playlist Location: /playlist/:id/feed Purpose: always syndicates all the videos in a playlist. * Videos for a topic Location: /topics/:id/feed Purpose: always syndicates the most recent 15 videos part of a playlist in a particular topic on this site. Only the playlist feed syndicates the entire list of videos. Other feeds discard old items as new videos are published on the site.
- Loading branch information
Showing
13 changed files
with
143 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
class PlaylistsController < ApplicationController | ||
|
||
|
||
before_action :playlist_set, only: [:show, :feed] | ||
|
||
def index | ||
@playlists = Playlist.all.order(created_at: :desc) | ||
end | ||
|
||
def show | ||
|
||
def feed | ||
@videos = @playlist.videos.includes(:playlist, playlist: [:topic]).visible.reverse | ||
@updated_at = Video.order(updated_at: :desc).limit(1).pluck(:updated_at).first | ||
render format: :xml, template: 'playlists/feed.xml.erb', layout: false | ||
end | ||
|
||
private | ||
|
||
def playlist_set | ||
@playlist = Playlist.friendly.find(params[:id]) | ||
if params[:id] != @playlist.slug | ||
redirect_to @playlist, status: 301 | ||
end | ||
redirect_to @playlist, status: 301 if params[:id] != @playlist.slug | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
class TopicsController < ApplicationController | ||
|
||
|
||
before_action :topic_set, only: [:show, :feed] | ||
|
||
def index | ||
@topics = Topic.all | ||
end | ||
|
||
def show | ||
@topic = Topic.friendly.find(params[:id]) | ||
def feed | ||
@videos = Video.visible.joins(:playlist).includes(:playlist, playlist: [:topic]).where(playlists: { topic: @topic }).order(published_at: :desc).limit(15) | ||
@updated_at = Video.order(updated_at: :desc).limit(1).pluck(:updated_at).first | ||
render format: :xml, template: 'topics/feed.xml.erb', layout: false | ||
end | ||
|
||
private | ||
|
||
def topic_set | ||
@topic = Topic.friendly.find(params[:id]) | ||
redirect_to topic_path(@topic) if params[:id] != @topic.slug | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="es-ES"> | ||
|
||
<title type="text">makigas (<%= @playlist.title %>)</title> | ||
<subtitle type="text">Lista de reproducción para el tema <%= @playlist.title %></subtitle> | ||
<updated><%= @updated_at.iso8601 %></updated> | ||
|
||
<id><%= feed_playlist_url(@playlist) %></id> | ||
<icon><%= @playlist.thumbnail.url %></icon> | ||
<logo><%= @playlist.thumbnail.url %></logo> | ||
<link rel="self" href="<%= feed_playlist_url(@playlist) %>" type="application/atom+xml" /> | ||
<link rel="alternate" href="<%= playlist_url(@playlist) %>" type="text/html" /> | ||
|
||
<author><name>makigas.es</name></author> | ||
<generator uri="https://github.com/makigas/makigas">makigas.es</generator> | ||
|
||
<%- @videos.each do |video| -%> | ||
<%= render 'videos/atom', video: video %> | ||
<%- end -%> | ||
|
||
</feed> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="es-ES"> | ||
|
||
<title type="text">makigas (<%= @topic.title %>)</title> | ||
<subtitle type="text">Vídeos recientes publicados en el tema <%= @topic.title %></subtitle> | ||
<updated><%= @updated_at.iso8601 %></updated> | ||
|
||
<id><%= feed_topic_url(@topic) %></id> | ||
<icon><%= @topic.thumbnail.url %></icon> | ||
<logo><%= @topic.thumbnail.url %></logo> | ||
<link rel="self" href="<%= feed_topic_url(@topic) %>" type="application/atom+xml" /> | ||
<link rel="alternate" href="<%= topic_url(@topic) %>" type="text/html" /> | ||
|
||
<author><name>makigas.es</name></author> | ||
<generator uri="https://github.com/makigas/makigas">makigas.es</generator> | ||
|
||
<%- @videos.each do |video| -%> | ||
<%= render 'videos/atom', video: video %> | ||
<%- end -%> | ||
|
||
</feed> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<entry> | ||
<id><%= video_url(video) %></id> | ||
<updated><%= video.published_at.iso8601 %></updated> | ||
<link rel="alternate" href="<%= video_url(video) %>" type="text/html" /> | ||
|
||
<title type="html"><![CDATA[<%= video.title %>]]></title> | ||
<summary type="html"><![CDATA[<%= video.description %>]]></summary> | ||
<category term="<%= video.playlist.title %>" /> | ||
<%- if video.playlist.topic.present? -%> | ||
<category term="<%= video.playlist.topic.title %>" /> | ||
<%- end -%> | ||
</entry> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="es-ES"> | ||
|
||
<title type="text">makigas</title> | ||
<subtitle type="text">Vídeos recientes publicados en makigas</subtitle> | ||
<updated><%= @updated_at.iso8601 %></updated> | ||
|
||
<id><%= feed_videos_url %></id> | ||
<icon><%= URI.join(root_url, 'makigas.png') %></icon> | ||
<logo><%= URI.join(root_url, 'makigas.png') %></logo> | ||
<link rel="self" href="<%= feed_videos_url %>" type="application/atom+xml" /> | ||
<link rel="alternate" href="<%= videos_url %>" type="text/html" /> | ||
|
||
<author><name>makigas.es</name></author> | ||
<generator uri="https://github.com/makigas/makigas">makigas.es</generator> | ||
|
||
<%- @videos.each do |video| -%> | ||
<%= render 'videos/atom', video: video %> | ||
<%- end -%> | ||
|
||
</feed> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters