indexable 0.0.4 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea666f584199ac33afce60449c7e2ca89a58fe09
4
- data.tar.gz: c6cd4101fa9c6ae24f67e8fc1fe58d0fe923cf16
3
+ metadata.gz: 64a1e1b305b64588744f3df8c892511cb49936e0
4
+ data.tar.gz: 13a2987bcff19059f7f1bed603b6ca48219917f9
5
5
  SHA512:
6
- metadata.gz: 3d99e57df1a36bd2330f1f1b118c1433581a5411cd6427efd8642b2815003763a7128f51796e9d5bdcb79ef0c824cd6243f03f0380ea517d6ce8250dc3a423c9
7
- data.tar.gz: 91554eb4a3c2ffa54239a0ceff1c766b9ff7d5b74641f5be6329a7293c9597df310babf217be4ca35f3f043151439100d3b15a0ed8b096c99e28fd80c0aeda13
6
+ metadata.gz: 4cc15e9a4ccff9f84f43bdf21b6bba08ca59c6b04463560f03da641305505fcb0d72e255e8824803fed0c7b0ba1838f3e589941a0a3f2242387d7e482c2488ca
7
+ data.tar.gz: 18f3d230291c6bb07f628ebf7fd0b7f48811a7abda1aca2c026c87e9e3f6a20ef9c212af5335c89a5cb2b09772733f68b23868b2c76c054b827beb4ee95abccf
@@ -1,53 +1,2 @@
1
- require 'phantomjs'
2
- require 'rack/request'
3
-
4
- module Rack
5
- class Indexable
6
- CRAWLER_USER_AGENTS = [
7
- /^Twitterbot/, /^curl/, /Googlebot/, /Mediapartners/, /Adsbot-Google/,
8
- /\(.*http(s|\(s\))?:\/\/.*\)/
9
- ]
10
-
11
- def initialize(app)
12
- @app = app
13
- end
14
-
15
- # Detect whether the current request comes from a bot. Based on the logic used
16
- # by Bustle.com (https://www.dropbox.com/s/s4oibqsxqpo3hll/bustle%20slizzle.pdf)
17
- def request_from_crawler?(env)
18
- user_agent = env["HTTP_USER_AGENT"]
19
- params = Rack::Request.new(env).params
20
- return false unless user_agent
21
- return true if CRAWLER_USER_AGENTS.any? {|s| user_agent.match(s) }
22
- return true if params.has_key?('_escaped_fragment_')
23
- params['nojs'].eql?('true')
24
- end
25
-
26
- def call(env)
27
- status, headers, content = *@app.call(env)
28
-
29
- if status == 200 and headers['Content-Type'].match(/^text\/html/) and request_from_crawler?(env)
30
- script = ::File.dirname(__FILE__) + "/render_page.js"
31
- file = Tempfile.new(['indexable', '.html'])
32
-
33
- if content.respond_to? :body
34
- html = content.body
35
- else
36
- html = content.join('')
37
- end
38
-
39
- file.write html
40
- file.close
41
- begin
42
- url = Rack::Request.new(env).url
43
- content = [Phantomjs.new(script, file.path, url).run]
44
- status = 500 if content[0] == "Couldn't render page... orz."
45
- ensure
46
- file.unlink
47
- end
48
- end
49
-
50
- [status, headers, content]
51
- end
52
- end
53
- end
1
+ require 'indexable/indexable'
2
+ require 'indexable/railtie' if defined?(Rails)
@@ -0,0 +1,7 @@
1
+ module Indexable
2
+ class Railtie < Rails::Railtie
3
+ initializer "indexable.insert_middleware" do |app|
4
+ app.config.middleware.use Indexable::Middleware
5
+ end
6
+ end
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: indexable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vikhyat Korrapati
@@ -31,8 +31,9 @@ extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
33
  - lib/indexable.rb
34
- - lib/render_page.js
35
- - lib/phantomjs.rb
34
+ - lib/indexable/render_page.js
35
+ - lib/indexable/phantomjs.rb
36
+ - lib/indexable/railtie.rb
36
37
  homepage: https://github.com/vikhyat/indexable
37
38
  licenses:
38
39
  - MIT