Skip to content

Instantly share code, notes, and snippets.

@furkanayhan
Forked from petewarden/tumblrproxy.rb
Last active February 3, 2016 11:22
Show Gist options
  • Save furkanayhan/8728297 to your computer and use it in GitHub Desktop.
Save furkanayhan/8728297 to your computer and use it in GitHub Desktop.
You can mount your Tumblr Blog to your existing Rails app. Forked from: https://gist.github.com/petewarden/3950261
class BlogController < ApplicationController
def index
path = params[:path].to_s
source_url = 'http://yourblog.tumblr.com/' + path
source_content_type = ''
source_body = open(source_url) do |f|
source_content_type = f.content_type # "text/html"
f.read
end
if source_content_type == 'text/html'
output_base = request.base_url + '/blog'
output_body = source_body.gsub(/\b(href|src|rel)="\/\//, '\1="https:\/\/')
output_body = output_body.gsub(/\b(href|src|rel)="\//, '\1="' + output_base + '/')
output_body = output_body.gsub(/\b(href|src|rel)="http:\/\/yourblog\.tumblr\.com/, '\1="/blog')
else
output_body = source_body
end
render :text => output_body, :content_type => source_content_type, :layout => false
end
end
YourApp::Application.routes.draw do
get "/blog" => "blog#index"
get "/blog/*path" => "blog#index"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment