From 1ec9140e782b4b45f2e20e320f3c7af8a13a28bc Mon Sep 17 00:00:00 2001 From: Thibaut Date: Sun, 30 Nov 2014 15:55:26 -0500 Subject: [PATCH] Add Atom feed Closes #141. --- lib/app.rb | 47 +++++++++++++++++++++++++++++++++++++++++++++++ views/index.erb | 1 + 2 files changed, 48 insertions(+) diff --git a/lib/app.rb b/lib/app.rb index 7eafe57f..11d493a1 100644 --- a/lib/app.rb +++ b/lib/app.rb @@ -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", '
').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 diff --git a/views/index.erb b/views/index.erb index 4c0c195a..82948d22 100644 --- a/views/index.erb +++ b/views/index.erb @@ -16,6 +16,7 @@ DevDocs: Open-source / Offline API Documentation Browser +