Add Atom feed

Closes #141.
pull/142/head
Thibaut 10 years ago
parent 752babb9d0
commit 1ec9140e78

@ -136,6 +136,11 @@ class App < Sinatra::Application
200
end
get '/feed' do
content_type 'application/atom+xml'
settings.news_feed
end
get %r{\A/(\w+)(\-[\w\-]+)?(/)?(.+)?\z} do |doc, type, slash, rest|
return 404 unless @doc = settings.docs[doc]
@ -155,4 +160,46 @@ class App < Sinatra::Application
error do
send_file File.join(settings.public_folder, '500.html'), status: status
end
configure do
require 'rss'
feed = RSS::Maker.make('atom') do |maker|
maker.channel.id = 'tag:devdocs.io,2014:/feed'
maker.channel.title = 'DevDocs'
maker.channel.author = 'DevDocs'
maker.channel.updated = "#{settings.news.first.first}T14:00:00Z"
maker.channel.links.new_link do |link|
link.rel = 'self'
link.href = 'http://devdocs.io/feed.atom'
link.type = 'application/atom+xml'
end
maker.channel.links.new_link do |link|
link.rel = 'alternate'
link.href = 'http://devdocs.io/'
link.type = 'text/html'
end
news.each_with_index do |news, i|
maker.items.new_item do |item|
item.id = "tag:devdocs.io,2014:News/#{settings.news.length - i}"
item.title = news[1].split("\n").first.gsub(/<\/?[^>]*>/, '')
item.description do |desc|
desc.content = news[1..-1].join.gsub("\n", '<br>').gsub('href="/', 'href="http://devdocs.io/')
desc.type = 'html'
end
item.updated = "#{news.first}T14:00:00Z"
item.published = "#{news.first}T14:00:00Z"
item.links.new_link do |link|
link.rel = 'alternate'
link.href = 'http://devdocs.io/'
link.type = 'text/html'
end
end
end
end
set :news_feed, feed.to_s
end
end

@ -16,6 +16,7 @@
<title>DevDocs: Open-source / Offline API Documentation Browser</title>
<link rel="canonical" href="http://devdocs.io">
<link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="DevDocs Search">
<link rel="alternate" href="http://devdocs.io/feed" title="DevDocs" type="application/atom+xml">
<link rel="icon" type="image/x-icon" href="http://maxcdn.devdocs.io/favicon.ico">
<link rel="fluid-icon" href="http://maxcdn.devdocs.io/images/fluid-icon.png" title="DevDocs">
<link rel="apple-touch-icon" sizes="72x72" href="http://maxcdn.devdocs.io/images/apple-icon-72.png">

Loading…
Cancel
Save