-
-
Save wielinde/4b22df86bcd239be7991 to your computer and use it in GitHub Desktop.
You can mount your Tumblr Blog to your existing Rails app on /news. It is SEO optimized as it tells Google only to index yourdomain.com and not yourdomain.tumblr.com routes. Forked from: https://gist.github.com/petewarden/3950261
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
YourApp::Application.routes.draw do | |
get '/news(/*tumblr_path)' => "tumblr#proxy" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add this line to the <head> of your template template. : | |
<meta name="ROBOTS" content="NOINDEX, NOFOLLOW"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TumblrController < ApplicationController | |
def proxy | |
source_url = 'https://yourdomain.tumblr.com' | |
path = params[:tumblr_path] | |
if path | |
source_url = File.join(source_url, request.path.gsub(/^\/news/, '')) | |
end | |
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 + '/news' | |
# set canonical_url to yourdomain and tell google to not index yourdomain.tumblr.com :-) | |
output_body = source_body.gsub(/<meta name="ROBOTS" content="NOINDEX, NOFOLLOW">/, "<link rel=\"canonical\" href=\"#{request.url}\">".html_safe) | |
output_body = output_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)="https:\/\/yourdomain\.tumblr\.com/, '\1="/news') | |
elsif source_content_type == 'text/xml' | |
output_body = source_body.gsub(/(<link>|<guid>)https:\/\/yourdomain\.tumblr\.com/, '\1https://yourdomain.com/news') | |
else | |
output_body = source_body | |
end | |
render :text => output_body.html_safe, :content_type => source_content_type | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment