Skip to content

Instantly share code, notes, and snippets.

@takkyuuplayer
Last active December 18, 2015 13:48
Show Gist options
  • Save takkyuuplayer/5792269 to your computer and use it in GitHub Desktop.
Save takkyuuplayer/5792269 to your computer and use it in GitHub Desktop.
rss list with sinatra
#!/usr/bin/ruby
# -*- coding:utf-8 -*-
require 'sinatra'
require 'feedzirra'
atom_url = 'http://blog.takkyuuplayer.com/feeds/posts/summary'
get '/' do
feed = Feedzirra::Feed.fetch_and_parse(atom_url)
erb :index, :locals => { :feed => feed }
end
proxy_cache_path /var/cache/nginx/sinatra levels=1:2 keys_zone=cache_static_file:128m inactive=7d max_size=512m;
proxy_temp_path /var/cache/nginx/temp;
upstream sinatra {
server localhost:4567;
}
server {
listen 80;
server_name www.takkyuuplayer.com;
charset utf-8;
access_log /var/log/nginx/vh/sinatra-access.log;
error_log /var/log/nginx/vh/sinatra-error.log;
location / {
proxy_redirect off;
set $do_not_cache 0;
if ($request_method != GET) {
set $do_not_cache 1;
}
proxy_no_cache $do_not_cache;
proxy_cache_bypass $do_not_cache;
proxy_cache cache_static_file;
proxy_cache_key $scheme$host$uri$is_args$args;
proxy_cache_valid 200 2h;
proxy_cache_valid any 1m;
proxy_pass http://sinatra;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
}
<% feed.entries.each do |entry| %>
<li>
<a href="<%= entry.url %>" target="_blank">
<%= entry.published.to_s[0, 10].gsub('-', '/') %>
<%= entry.title %>
</a>
</li>
<% end; %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment