Class: BardStatic::NoRobotsMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/bard_static/no_robots_middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ NoRobotsMiddleware

Returns a new instance of NoRobotsMiddleware.



3
4
5
# File 'lib/bard_static/no_robots_middleware.rb', line 3

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/bard_static/no_robots_middleware.rb', line 7

def call(env)
  status, headers, response = @app.call(env)

  if env["bard_static.prototype"] && status == 200
    no_robots_tag = %{<meta name="robots" content="noindex, nofollow"/>\n}
    response.each do |part|
      part.sub! "</head>", "#{no_robots_tag}</head>"
    end
  end

  [status, headers, response]
end