Skip to content

Commit

Permalink
Generate RSS feed
Browse files Browse the repository at this point in the history
  • Loading branch information
thutterer committed May 30, 2020
1 parent 933a0ee commit d354724
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
7 changes: 7 additions & 0 deletions app/controllers/bongo/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ class ArticlesController < ApplicationController

def index
@articles = policy_scope(Article).order(publish_at: :desc)
respond_to do |format|
format.html
format.rss do
@articles = @articles.published.order(publish_at: :desc)
render layout: false
end
end
end

def show
Expand Down
18 changes: 18 additions & 0 deletions app/views/bongo/articles/index.rss.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
xml.instruct! :xml, version: "1.0"
xml.rss version: "2.0" do
xml.channel do
xml.title (Front.config.name rescue "My Blog")
xml.description (Front.config.name rescue "A bongo blog")
xml.link root_url

@articles.each do |article|
xml.item do
xml.title article.title
xml.description ActionView::Base.full_sanitizer.sanitize(article.text).truncate(180)
xml.pubDate article.publish_at.to_s(:rfc822)
xml.link article_url(article)
xml.guid article_url(article)
end
end
end
end
4 changes: 4 additions & 0 deletions app/views/layouts/bongo/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
Blog
<% end %>
<% content_for :head do %>
<%= auto_discovery_link_tag :rss, articles_url(format: :rss) %>
<% end %>
<%= render template: "layouts/application" %>
2 changes: 1 addition & 1 deletion lib/bongo/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Bongo
VERSION = '0.0.5'
VERSION = '0.1.0'
end

0 comments on commit d354724

Please sign in to comment.