History

Add Atom feed

Closes #141.

Thibaut committed 11 years ago

Commit 1ec91401 parent 752babb2 files · +48 −0Browse files

Unified · Split

2 files
  1. lib/app.rb +47 −0
  2. views/index.erb +1 −0
lib/app.rb+47−0
@@ -136,6 +136,11 @@ class App < Sinatra::Application · 135 unmodified lines
136136 200
137137 end
138138
139+ get '/feed' do
140+ content_type 'application/atom+xml'
141+ settings.news_feed
142+ end
143+
139144 get %r{\A/(\w+)(\-[\w\-]+)?(/)?(.+)?\z} do |doc, type, slash, rest|
140145 return 404 unless @doc = settings.docs[doc]
141146
@@ -155,4 +160,46 @@ class App < Sinatra::Application · 13 unmodified lines
155160 error do
156161 send_file File.join(settings.public_folder, '500.html'), status: status
157162 end
163+
164+ configure do
165+ require 'rss'
166+ feed = RSS::Maker.make('atom') do |maker|
167+ maker.channel.id = 'tag:devdocs.io,2014:/feed'
168+ maker.channel.title = 'DevDocs'
169+ maker.channel.author = 'DevDocs'
170+ maker.channel.updated = "#{settings.news.first.first}T14:00:00Z"
171+
172+ maker.channel.links.new_link do |link|
173+ link.rel = 'self'
174+ link.href = 'http://devdocs.io/feed.atom'
175+ link.type = 'application/atom+xml'
176+ end
177+
178+ maker.channel.links.new_link do |link|
179+ link.rel = 'alternate'
180+ link.href = 'http://devdocs.io/'
181+ link.type = 'text/html'
182+ end
183+
184+ news.each_with_index do |news, i|
185+ maker.items.new_item do |item|
186+ item.id = "tag:devdocs.io,2014:News/#{settings.news.length - i}"
187+ item.title = news[1].split("\n").first.gsub(/<\/?[^>]*>/, '')
188+ item.description do |desc|
189+ desc.content = news[1..-1].join.gsub("\n", '<br>').gsub('href="/', 'href="http://devdocs.io/')
190+ desc.type = 'html'
191+ end
192+ item.updated = "#{news.first}T14:00:00Z"
193+ item.published = "#{news.first}T14:00:00Z"
194+ item.links.new_link do |link|
195+ link.rel = 'alternate'
196+ link.href = 'http://devdocs.io/'
197+ link.type = 'text/html'
198+ end
199+ end
200+ end
201+ end
202+
203+ set :news_feed, feed.to_s
204+ end
158205 end
views/index.erb+1−0
@@ -16,6 +16,7 @@ · 15 unmodified lines
1616 <title>DevDocs: Open-source / Offline API Documentation Browser</title>
1717 <link rel="canonical" href="http://devdocs.io">
1818 <link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="DevDocs Search">
19+ <link rel="alternate" href="http://devdocs.io/feed" title="DevDocs" type="application/atom+xml">
1920 <link rel="icon" type="image/x-icon" href="http://maxcdn.devdocs.io/favicon.ico">
2021 <link rel="fluid-icon" href="http://maxcdn.devdocs.io/images/fluid-icon.png" title="DevDocs">
2122 <link rel="apple-touch-icon" sizes="72x72" href="http://maxcdn.devdocs.io/images/apple-icon-72.png">