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
136 200136 200
137 end137 end
138 138
139 get '/feed' do
140 content_type 'application/atom+xml'
141 settings.news_feed
142 end
143
139 get %r{\A/(\w+)(\-[\w\-]+)?(/)?(.+)?\z} do |doc, type, slash, rest|144 get %r{\A/(\w+)(\-[\w\-]+)?(/)?(.+)?\z} do |doc, type, slash, rest|
140 return 404 unless @doc = settings.docs[doc]145 return 404 unless @doc = settings.docs[doc]
141 146
@@ -155,4 +160,46 @@ class App < Sinatra::Application · 13 unmodified lines
155 error do160 error do
156 send_file File.join(settings.public_folder, '500.html'), status: status161 send_file File.join(settings.public_folder, '500.html'), status: status
157 end162 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
158end205end
views/index.erb+1−0
@@ -16,6 +16,7 @@ · 15 unmodified lines
16 <title>DevDocs: Open-source / Offline API Documentation Browser</title>16 <title>DevDocs: Open-source / Offline API Documentation Browser</title>
17 <link rel="canonical" href="http://devdocs.io">17 <link rel="canonical" href="http://devdocs.io">
18 <link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="DevDocs Search">18 <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">
19 <link rel="icon" type="image/x-icon" href="http://maxcdn.devdocs.io/favicon.ico">20 <link rel="icon" type="image/x-icon" href="http://maxcdn.devdocs.io/favicon.ico">
20 <link rel="fluid-icon" href="http://maxcdn.devdocs.io/images/fluid-icon.png" title="DevDocs">21 <link rel="fluid-icon" href="http://maxcdn.devdocs.io/images/fluid-icon.png" title="DevDocs">
21 <link rel="apple-touch-icon" sizes="72x72" href="http://maxcdn.devdocs.io/images/apple-icon-72.png">22 <link rel="apple-touch-icon" sizes="72x72" href="http://maxcdn.devdocs.io/images/apple-icon-72.png">