prerender_rails 0.0.8 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59948717e824a0f84b73f6a8f3b5c1a3cadb294d
4
- data.tar.gz: 811bc0d1154cadc3a8ad64fa3ea94bb6db48f2bc
3
+ metadata.gz: 89e1c2e1dd21adf5e3825a67ad848b35982ed781
4
+ data.tar.gz: cdec4ea8f7fa82fc8d6a4922910f09fbb9906be8
5
5
  SHA512:
6
- metadata.gz: 3860c469fdb0f557d85ca341c4869bc47d86da0942a5690ddeced8c3e9e8be4930689f602d5190bcf71a3a24e0e41eefcbb4013e83e77155d7f736ff5b78270c
7
- data.tar.gz: 5912a78bd5e7099ff969c49b93c4bdf44c038b6ab05fb8942fdee21cd69c79c3f48950b22df9c867842299d418193860c6d07ef417269f6670943c5044728010
6
+ metadata.gz: 281e4c4a83be7f2bdd50d2817fff311f7fe9c272d939216b436ef81283ba8030ed23bde71521057ca213a7ce2bf022073cd008b2cd94cc4f8e617c96ff195295
7
+ data.tar.gz: 305173a965270584c6880ce57e9101126ffbdbc0b3bd570574d24070faf3a246285b5f585f2f2fa8a5d787caaae5668803f8433d691f80f177bc4deffab7606b
data/README.md CHANGED
@@ -5,6 +5,8 @@ Are you using backbone, angular, emberjs, etc, but you're unsure about the SEO i
5
5
 
6
6
  Use this gem to install rails middleware that prerenders a javascript-rendered page using an external service and returns the HTML to the search engine crawler for SEO.
7
7
 
8
+ `Note:` If you are using a `#` in your urls, make sure to change it to `#!`. [View Google's ajax crawling protocol](https://developers.google.com/webmasters/ajax-crawling/docs/getting-started)
9
+
8
10
  `Note:` Make sure you have more than one webserver thread/process running because the prerender service will make a request to your server to render the HTML.
9
11
 
10
12
  Add this line to your application's Gemfile:
@@ -19,7 +21,7 @@ And in `config/environment/production.rb`, add this line:
19
21
 
20
22
  ## How it works
21
23
  1. Check to make sure we should show a prerendered page
22
- 1. Check if the request is from a crawler (agent string)
24
+ 1. Check if the request is from a crawler (`_escaped_fragment_` or agent string)
23
25
  2. Check to make sure we aren't requesting a resource (js, css, etc...)
24
26
  3. (optional) Check to make sure the url is in the whitelist
25
27
  4. (optional) Check to make sure the url isn't in the blacklist
@@ -54,6 +56,16 @@ If you've deployed the prerender service on your own, set the `PRERENDER_SERVICE
54
56
 
55
57
  $ export PRERENDER_SERVICE_URL=<new url>
56
58
 
59
+ Or on heroku:
60
+
61
+ $ heroku config:add PRERENDER_SERVICE_URL=<new url>
62
+
63
+ As an alternative, you can pass `prerender_service_url` in the options object during initialization of the middleware
64
+
65
+ ``` ruby
66
+ config.middleware.use Rack::Prerender, prerender_service_url: '<new url>'
67
+ ```
68
+
57
69
  ## Testing
58
70
 
59
71
  If you want to make sure your pages are rendering correctly:
@@ -3,13 +3,13 @@ module Rack
3
3
  require 'net/http'
4
4
 
5
5
  def initialize(app, options={})
6
- # googlebot, yahoo, and bingbot are not in this list because
7
- # we support _escaped_fragment_ instead of checking user
8
- # agent for those crawlers
6
+ # googlebot, yahoo, and bingbot are in this list even though
7
+ # we support _escaped_fragment_ to ensure it works for people
8
+ # who might not use the _escaped_fragment_ protocol
9
9
  @crawler_user_agents = [
10
- # 'googlebot',
11
- # 'yahoo',
12
- # 'bingbot',
10
+ 'googlebot',
11
+ 'yahoo',
12
+ 'bingbot',
13
13
  'baiduspider',
14
14
  'facebookexternalhit'
15
15
  ]
@@ -79,7 +79,7 @@ module Rack
79
79
  request = Rack::Request.new(env)
80
80
 
81
81
  return true if request.query_string.include? '_escaped_fragment_'
82
-
82
+
83
83
  #if it is not a bot...dont prerender
84
84
  return false if @crawler_user_agents.all? { |crawler_user_agent| !user_agent.downcase.include?(crawler_user_agent.downcase) }
85
85
 
@@ -122,7 +122,7 @@ module Rack
122
122
  end
123
123
 
124
124
  def get_prerender_service_url
125
- ENV['PRERENDER_SERVICE_URL'] || 'http://prerender.herokuapp.com/'
125
+ @options[:prerender_service_url] || ENV['PRERENDER_SERVICE_URL'] || 'http://prerender.herokuapp.com/'
126
126
  end
127
127
  end
128
128
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "prerender_rails"
5
- spec.version = "0.0.8"
5
+ spec.version = "0.1.0"
6
6
  spec.authors = ["Todd Hooper"]
7
7
  spec.email = ["todd@collectiveip.com"]
8
8
  spec.description = %q{Rails middleware to prerender your javascript heavy pages on the fly by a phantomjs service}
@@ -101,6 +101,12 @@ describe Rack::Prerender do
101
101
  assert_equal @prerender.build_api_url(request), 'http://prerenderurl.com/https://google.com/search?q=javascript'
102
102
  ENV['PRERENDER_SERVICE_URL'] = nil
103
103
  end
104
+
105
+ it "should build the correct api url with an initialization variable url" do
106
+ @prerender = Rack::Prerender.new(@app, prerender_service_url: 'http://prerenderurl.com')
107
+ request = Rack::MockRequest.env_for "https://google.com/search?q=javascript"
108
+ assert_equal @prerender.build_api_url(request), 'http://prerenderurl.com/https://google.com/search?q=javascript'
109
+ end
104
110
  end
105
111
 
106
- end
112
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prerender_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Hooper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-10 00:00:00.000000000 Z
11
+ date: 2013-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack