-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
34 lines (31 loc) · 962 Bytes
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# -*- encoding : utf-8 -*-
require 'rubygems'
require 'bundler/setup'
require 'sinatra'
require File.expand_path('../lib/database', __FILE__)
require File.expand_path('../models/article', __FILE__)
get '/' do
"<a href='/rss.xml'>纽约时报中文网非官方Feed</a>"
end
get '/rss.xml' do
content_type 'application/rss+xml'
builder do |xml|
xml.instruct! :xml, :version => '1.0', :encoding => 'UTF-8'
xml.rss :version => "2.0" do
xml.channel do
xml.title "纽约时报中文网"
xml.description "纽约时报中文网非官方Feed"
xml.link "http://cn.nytimes.com/"
Article.order_by(published_at: :desc).limit(50).each do |article|
xml.item do
xml.title article.title
xml.link article.url
xml.description article.body
xml.pubDate article.published_at.rfc822()
xml.guid article.url
end
end
end
end
end
end