From 9a3f6943c36d2bac4d0a4feb5cc4dc7b8eccc813 Mon Sep 17 00:00:00 2001 From: Alexis Fellenius Date: Fri, 27 Nov 2015 22:18:14 +0100 Subject: [PATCH] Add RSS feed --- app/controllers/articles_controller.rb | 8 ++++++++ app/views/articles/feed.rss.builder | 26 ++++++++++++++++++++++++++ app/views/layouts/application.html.erb | 1 + config/routes.rb | 2 ++ 4 files changed, 37 insertions(+) create mode 100644 app/views/articles/feed.rss.builder diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index c7f624b..d4adc81 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -3,6 +3,14 @@ def index @articles = Article.all.order("created_at DESC") end + def feed + @articles = Article.all.order("created_at DESC") + + respond_to do |format| + format.rss { render :layout => false } + end + end + def show @article = RenderableArticle.new Article.friendly.find(params[:id]) diff --git a/app/views/articles/feed.rss.builder b/app/views/articles/feed.rss.builder new file mode 100644 index 0000000..3012361 --- /dev/null +++ b/app/views/articles/feed.rss.builder @@ -0,0 +1,26 @@ +#encoding: UTF-8 + +xml.instruct! :xml, :version => "1.0" +xml.rss :version => "2.0" do + xml.channel do + xml.title "Alexis Fellenius Makrigianni" + xml.description "Alexis is a product designer, digital strategist and partner at Oktavilla" + xml.link "http://lexi.se" + xml.language "en" + xml.tag! 'atom:link', :rel => 'self', :type => 'application/rss+xml', :href => feed_url + + for article in @articles + xml.item do + xml.title article.title + xml.author "Alexis Fellenius Makrigianni" + xml.pubDate article.created_at.to_s(:rfc822) + xml.link "#{article_url(article)}" + xml.guid article.id + + rendered_article = RenderableArticle.new article + xml.description rendered_article.body + + end + end + end +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index e2bff92..faecbc0 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -5,6 +5,7 @@ <%= @page_title ? "#{@page_title} – Alexis Fellenius Makrigianni" : "Alexis Fellenius Makrigianni is a designer and partner at Oktavilla" %> + <%= stylesheet_link_tag "application" %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> diff --git a/config/routes.rb b/config/routes.rb index b7df49c..f9ce7ef 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,6 +4,8 @@ resources :articles + get 'feed' => 'articles#feed' + # Redirect old URLs for moved articles get '/post/18401593732/thoughts-on-responsive-navigation', to: redirect('/articles/thoughts-on-responsive-navigation')