Add RSS Feed (#1500)
This commit is contained in:
+14
-2
@@ -19,7 +19,7 @@ require 'gollum/views/editable'
|
||||
require 'gollum/views/has_page'
|
||||
require 'gollum/views/has_user_icons'
|
||||
require 'gollum/views/pagination'
|
||||
|
||||
require 'gollum/views/rss.rb'
|
||||
|
||||
require File.expand_path '../helpers', __FILE__
|
||||
|
||||
@@ -44,6 +44,7 @@ module Precious
|
||||
register Mustache::Sinatra
|
||||
register Sinatra::Namespace
|
||||
include Precious::Helpers
|
||||
|
||||
dir = File.dirname(File.expand_path(__FILE__))
|
||||
|
||||
set :sprockets, ::Precious::Assets.sprockets(dir)
|
||||
@@ -77,6 +78,8 @@ module Precious
|
||||
@critic_markup = settings.wiki_options[:critic_markup]
|
||||
@redirects_enabled = settings.wiki_options.fetch(:redirects_enabled, true)
|
||||
@per_page_uploads = settings.wiki_options[:per_page_uploads]
|
||||
|
||||
@wiki_title = settings.wiki_options.fetch(:title, 'Gollum Wiki')
|
||||
|
||||
forbid unless @allow_editing || request.request_method == 'GET'
|
||||
Precious::App.set(:mustache, {:templates => settings.wiki_options[:template_dir]}) if settings.wiki_options[:template_dir]
|
||||
@@ -111,7 +114,16 @@ module Precious
|
||||
end
|
||||
|
||||
namespace '/gollum' do
|
||||
|
||||
get '/feed/' do
|
||||
url = "#{env['rack.url_scheme']}://#{env['HTTP_HOST']}"
|
||||
changes = wiki_new.latest_changes(::Gollum::Page.log_pagination_options(
|
||||
per_page: settings.wiki_options.fetch(:pagination_count, 10),
|
||||
page_num: 0)
|
||||
)
|
||||
content_type :rss
|
||||
RSSView.new(@base_url, @wiki_title, url, changes).render
|
||||
end
|
||||
|
||||
get '/assets/mathjax/*' do
|
||||
env['PATH_INFO'].sub!("/gollum/assets/mathjax", '')
|
||||
Rack::Static.new(not_found_proc, {:root => @mathjax_path, :urls => ['']}).call(env)
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
require 'rss'
|
||||
|
||||
class RSSView
|
||||
|
||||
include Precious::Views::AppHelpers
|
||||
include Precious::Views::RouteHelpers
|
||||
|
||||
attr_reader :base_url
|
||||
|
||||
def initialize(base_url, wiki_title, url, changes)
|
||||
@base_url = base_url
|
||||
@wiki_title = wiki_title
|
||||
@url = url
|
||||
@changes = changes
|
||||
end
|
||||
|
||||
def render
|
||||
latest_changes = "#{@url}#{latest_changes_path}"
|
||||
RSS::Maker.make('2.0') do |maker|
|
||||
maker.channel.author = 'Gollum Wiki'
|
||||
maker.channel.updated = @changes.first.authored_date
|
||||
maker.channel.title = "#{@wiki_title} Latest Changes"
|
||||
maker.channel.description = "Latest Changes in #{@wiki_title}"
|
||||
maker.channel.link = latest_changes
|
||||
@changes.each do |change|
|
||||
maker.items.new_item do |item|
|
||||
item.link = latest_changes
|
||||
item.title = change.message
|
||||
item.updated = change.authored_date
|
||||
id = change.id
|
||||
files = change.stats.files.map do |files|
|
||||
[files[:old_file], files[:new_file]].compact.map do |file|
|
||||
f = extract_page_dir(file)
|
||||
"<li><a href=\"#{@url}#{page_route(f)}/#{id}\">#{f}</a></li>"
|
||||
end
|
||||
end
|
||||
item.description = "Commited by: <a href=\"mailto:#{change.author.email}\">#{change.author.name}</a><br/>Commit ID: #{id[0..6]}<br/><br/>Affected files:<ul>#{files.join}</ul>"
|
||||
end
|
||||
end
|
||||
end.to_s
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user