RSS/Atom feed for sites

This commit is contained in:
Kyle Drake 2014-06-12 16:30:02 -07:00
parent b47997a030
commit 5edeba9495
3 changed files with 30 additions and 1 deletions

6
app.rb
View file

@ -75,6 +75,12 @@ get '/profile_mockup' do
erb :'profile_mockup', locals: {site: current_site}
end
get '/site/:sitename.rss' do |sitename|
site = Site[username: sitename]
content_type :xml
site.to_rss.to_xml
end
get '/site/:sitename' do |sitename|
site = Site[username: sitename]
not_found if(site.nil?)

View file

@ -1,4 +1,5 @@
require 'tilt'
require 'rss'
class Site < Sequel::Model
include Sequel::ParanoidDelete
@ -456,7 +457,7 @@ class Site < Sequel::Model
end
def title
values[:title] || values[:username]
values[:title] || "#{values[:username]}.neocities.org"
end
def hits_english
@ -510,4 +511,23 @@ class Site < Sequel::Model
ext = File.extname(filename).gsub('.', '').match(LOSSY_IMAGE_REGEX) ? 'jpg' : 'png'
"#{THUMBNAILS_URL_ROOT}/#{values[:username]}/#{filename}.#{resolution}.#{ext}"
end
def to_rss
RSS::Maker.make("atom") do |maker|
maker.channel.title = title
maker.channel.updated = updated_at
maker.channel.author = username
maker.channel.id = "#{username}.neocities.org"
latest_events.each do |event|
if event.site_change_id
maker.items.new_item do |item|
item.link = "http://#{username}.neocities.org"
item.title = "#{username}.neocities.org has been updated"
item.updated = event.site_change.created_at
end
end
end
end
end
end

View file

@ -29,6 +29,9 @@
<% end %>
<a href="#" id="shareButton" class="btn-Action share" data-container="body" data-toggle="popover" data-placement="bottom" data-content='
<a href="/site/<%= site.username %>.rss"><span>RSS/Atom Feed</span></a>
<br>
<a href="http://facebook.com/sharer.php?u=<%= Rack::Utils.build_query(u: "http://#{site.username}.neocities.org") %>" target="_blank">Facebook</a>
<br>
<a href="https://twitter.com/intent/tweet?<%= Rack::Utils.build_query(text: "This site is awesome: http://#{site.username}.neocities.org") %>">Twitter</a>