Skip to content

Commit

Permalink
Create dynamic robots.txt page (forem#5794) [deploy]
Browse files Browse the repository at this point in the history
* Create dynamic robots.txt page

* Add tests and remove cachebust
  • Loading branch information
benhalpern authored Jan 28, 2020
1 parent cd25f9a commit 82f2281
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
7 changes: 6 additions & 1 deletion app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class PagesController < ApplicationController
# No authorization required for entirely public controller
before_action :set_cache_control_headers, only: %i[show rlyweb now survey badge shecoded bounty faq]
before_action :set_cache_control_headers, only: %i[show rlyweb now survey badge shecoded bounty faq robots]

def show
@page = Page.find_by!(slug: params[:slug])
Expand Down Expand Up @@ -51,6 +51,11 @@ def report_abuse
render "pages/report-abuse"
end

def robots
respond_to :text
set_surrogate_key_header "robots_page"
end

def rlyweb
set_surrogate_key_header "rlyweb"
end
Expand Down
6 changes: 6 additions & 0 deletions app/views/pages/robots.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
User-agent: *
Disallow: /users/auth/twitter*
Disallow: /users/auth/github*
Disallow: /report-abuse?url=*

Sitemap: https://<%= ApplicationConfig["AWS_BUCKET_NAME"] %>.s3.amazonaws.com/sitemaps/sitemap.xml.gz
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@

# You can have the root of your site routed with "root
get "/about" => "pages#about"
get "/robots.:format" => "pages#robots"
get "/api", to: redirect("https://docs.dev.to/api")
get "/privacy" => "pages#privacy"
get "/terms" => "pages#terms"
Expand Down
7 changes: 0 additions & 7 deletions public/robots.txt

This file was deleted.

7 changes: 7 additions & 0 deletions spec/requests/pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,11 @@
end
end
end

describe "GET /robots.txt" do
it "has proper text" do
get "/robots.txt"
expect(response.body).to include("Sitemap: https://#{ApplicationConfig['AWS_BUCKET_NAME']}.s3.amazonaws.com/sitemaps/sitemap.xml.gz")
end
end
end

0 comments on commit 82f2281

Please sign in to comment.