Skip to content

Commit

Permalink
Add a sitemap (Closes #44)
Browse files Browse the repository at this point in the history
  • Loading branch information
zedtux committed Jan 30, 2016
1 parent 3dadfca commit b4323a4
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -80,3 +80,5 @@ pickle-email-*.html


# Keep newrelic license key secret =) # Keep newrelic license key secret =)
config/newrelic.yml config/newrelic.yml

public/sitemaps/
3 changes: 3 additions & 0 deletions Gemfile
Expand Up @@ -29,6 +29,9 @@ gem 'redcarpet'
# Pagination # Pagination
gem 'kaminari' gem 'kaminari'


# SEO
gem 'dynamic_sitemaps'

group :assets do group :assets do
gem 'coffee-rails' gem 'coffee-rails'
end end
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Expand Up @@ -131,6 +131,7 @@ GEM
docile (1.1.5) docile (1.1.5)
domain_name (0.5.25) domain_name (0.5.25)
unf (>= 0.0.5, < 1.0.0) unf (>= 0.0.5, < 1.0.0)
dynamic_sitemaps (2.0.0)
email_spec (2.0.0) email_spec (2.0.0)
htmlentities (~> 4.3.3) htmlentities (~> 4.3.3)
launchy (~> 2.1) launchy (~> 2.1)
Expand Down Expand Up @@ -364,6 +365,7 @@ DEPENDENCIES
cucumber-rails cucumber-rails
cucumber-timecop (= 0.0.3) cucumber-timecop (= 0.0.3)
database_cleaner database_cleaner
dynamic_sitemaps
email_spec email_spec
git git
hub hub
Expand Down
12 changes: 12 additions & 0 deletions app/controllers/home_controller.rb
@@ -0,0 +1,12 @@
class HomeController < ApplicationController
def sitemap
path = Rails.root.join('public', 'sitemaps', 'sitemap.xml')
if File.exists?(path)
render xml: open(path).read
else
render text: 'Sitemap not found.', status: :not_found
end
end

def robots; end
end
3 changes: 2 additions & 1 deletion app/models/homebrew/tools.rb
Expand Up @@ -16,7 +16,7 @@ def self.extract_class_name(formula)
GithubGistFormula GithubGistFormula
) )
class_name = formula.scan( class_name = formula.scan(
/^class\s(\w+)\s<\s(?:#{inheriting_classes.join("|")})$/ /^(\s+)?class\s(\w+)\s<\s(?:#{inheriting_classes.join("|")})$/
) )
class_name.flatten.last class_name.flatten.last
end end
Expand Down Expand Up @@ -92,6 +92,7 @@ def self.find_or_create_formula!(filename, name)
formula = Homebrew::Formula.find_by(filename: filename) formula = Homebrew::Formula.find_by(filename: filename)
return formula if formula return formula if formula


Rails.logger.info "Creating formula '#{name}' (#{filename})"
Homebrew::Formula.create!(filename: filename, name: name, external: true) Homebrew::Formula.create!(filename: filename, name: name, external: true)
end end
end end
Expand Down
1 change: 1 addition & 0 deletions app/views/home/robots.text.erb
@@ -0,0 +1 @@
Sitemap: <%= sitemap_url %>
5 changes: 4 additions & 1 deletion app/workers/homebrew_formula_import_worker.rb
Expand Up @@ -6,6 +6,7 @@
class HomebrewFormulaImportWorker class HomebrewFormulaImportWorker
include Sidekiq::Worker include Sidekiq::Worker
include Sidetiq::Schedulable include Sidetiq::Schedulable
sidekiq_options backtrace: true


attr_accessor :formula attr_accessor :formula


Expand Down Expand Up @@ -65,7 +66,9 @@ def perform
"#{error.message}" "#{error.message}"
ensure ensure
@import.ended_at = Time.now @import.ended_at = Time.now
unless @import.save if @import.save
DynamicSitemaps.generate_sitemap
else
Rails.logger.warn 'Unable to update the import with ID ' \ Rails.logger.warn 'Unable to update the import with ID ' \
"#{@import.id} : #{@import.errors.full_message}" "#{@import.id} : #{@import.errors.full_message}"
end end
Expand Down
3 changes: 3 additions & 0 deletions config/routes.rb
Expand Up @@ -8,6 +8,9 @@


resources :documentation, only: :index resources :documentation, only: :index


get 'sitemap.xml' => 'home#sitemap', format: :xml, as: :sitemap
get 'robots.:format' => 'home#robots', format: :text, as: :robots

resources :formulas, only: [:index, :show], path: '' do resources :formulas, only: [:index, :show], path: '' do
member do member do
get 'refresh_description' get 'refresh_description'
Expand Down
46 changes: 46 additions & 0 deletions config/sitemap.rb
@@ -0,0 +1,46 @@
# Change this to your host.
# See the readme at https://github.com/lassebunk/dynamic_sitemaps
# for examples of multiple hosts and folders.
host 'brewformulas.org'

sitemap :site do
url root_url, last_mod: Time.now, change_freq: 'daily', priority: 1.0
end

# You can have multiple sitemaps like the above – just make sure their names
# are different.

# Automatically link to all pages using the routes specified
# using "resources :pages" in config/routes.rb. This will also
# automatically set <lastmod> to the date and time in page.updated_at:
#
sitemap_for Homebrew::Formula.internals.active, name: :formula do |formula|
url formula_url(formula.name)
end

# For products with special sitemap name and priority, and link to comments:
#
# sitemap_for Product.published, name: :published_products do |product|
# url product, last_mod: product.updated_at,
# priority: (product.featured? ? 1.0 : 0.7)
# url product_comments_url(product)
# end

# If you want to generate multiple sitemaps in different folders
# (for example if you have more than one domain), you can specify a folder
# before the sitemap definitions:
#
# Site.all.each do |site|
# folder "sitemaps/#{site.domain}"
# host site.domain
#
# sitemap :site do
# url root_url
# end
#
# sitemap_for site.products.scoped
# end

# Ping search engines after sitemap generation:
#
# ping_with "http://#{host}/sitemap.xml"
5 changes: 0 additions & 5 deletions public/robots.txt

This file was deleted.

0 comments on commit b4323a4

Please sign in to comment.