Skip to content

Commit d24e449

Browse files
committed
Add feed to updates
1 parent e5cae99 commit d24e449

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

app/controllers/updates_controller.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ def index
1111
@updates, @cursor = paginate_with_cursor(Update, items: 3, by: :published_at, before: params[:before])
1212
end
1313

14+
def feed
15+
@updates = Update.order(published_at: :desc)
16+
render formats: :rss
17+
end
18+
1419
def show
20+
redirect_to updates_path, notice: "Update not found" unless @update
1521
end
1622

1723
def new

app/views/updates/feed.rss.builder

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal: true
2+
3+
xml.instruct! :xml, version: "1.0"
4+
xml.rss version: "2.0" do
5+
xml.channel do
6+
xml.title "Visualizer Updates"
7+
xml.description "These are the latest updates from Visualizer"
8+
xml.link feed_updates_url
9+
xml.lastBuildDate @updates.first.published_at.rfc822
10+
11+
@updates.each do |update|
12+
xml.item do
13+
xml.title update.title
14+
xml.description update.excerpt
15+
xml.link update_url(update.slug.presence || update.id)
16+
xml.guid update_url(update.slug.presence || update.id), isPermaLink: true
17+
xml.pubDate update.published_at.rfc822
18+
end
19+
end
20+
end
21+
end

app/views/updates/index.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<% content_for(:html_title) { "Visualizer | Updates" } %>
2+
<% content_for(:head) { auto_discovery_link_tag :rss, feed_updates_path(format: :rss) } %>
23
<div class="max-w-4xl px-4 mx-auto my-6 sm:px-6">
34
<% if current_user&.admin %>
45
<div class="text-xs text-right">

config/routes.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@
7676

7777
resources :yearly_brew, only: %i[index show]
7878
resources :stats, only: [:index]
79-
resources :updates, except: %i[destroy]
79+
resources :updates, except: %i[destroy] do
80+
get :feed, on: :collection
81+
end
8082
get "/changes(/*path)", to: redirect { |params| "/updates/#{params[:path]}" }
8183

8284
post :airtable, to: "airtable#notification"

0 commit comments

Comments
 (0)