Skip to content

Commit bf8ab92

Browse files
committed
Merge pull request #210 from bjfish/sitemap_generation
Adding site map generation #185
2 parents d85ae75 + 680c1fd commit bf8ab92

File tree

5 files changed

+49
-0
lines changed

5 files changed

+49
-0
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ gem 'rakismet'
121121
gem 'ruby-progressbar'
122122
gem 'sanitize'
123123
gem 'simple_form'
124+
gem 'sitemap_generator'
124125
gem 'tweet-button'
125126
gem 'local_time'
126127

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,8 @@ GEM
619619
rack (~> 1.4)
620620
rack-protection (~> 1.4)
621621
tilt (~> 1.3, >= 1.3.4)
622+
sitemap_generator (5.0.5)
623+
builder
622624
slim (2.0.3)
623625
temple (~> 0.6.6)
624626
tilt (>= 1.3.3, < 2.1)
@@ -804,6 +806,7 @@ DEPENDENCIES
804806
simple_form
805807
simplecov
806808
sinatra
809+
sitemap_generator
807810
slim-rails
808811
spring
809812
spring-commands-rspec

app/clock.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,9 @@
4444
ClearExpiredSessionsJob.perform_async
4545
end
4646

47+
every(1.day, 'sitemap:refresh', at: '06:00') do
48+
SitemapRefreshWorker.perform_async
49+
end
50+
4751
# This is tied with broken code. Probably should delete
4852
# every(1.day, 'facts:system', at: '00:00') {}

app/workers/sitemap_refresh_worker.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
class SitemapRefreshWorker
2+
include Sidekiq::Worker
3+
sidekiq_options queue: :high
4+
5+
def perform
6+
SitemapGenerator::Sitemap.default_host = "https://coderwall.com"
7+
SitemapGenerator::Sitemap.public_path = 'tmp/'
8+
SitemapGenerator::Sitemap.sitemaps_host = "http://#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com/"
9+
SitemapGenerator::Sitemap.sitemaps_path = 'sitemaps/'
10+
SitemapGenerator::Sitemap.adapter = SitemapGenerator::WaveAdapter.new
11+
12+
SitemapGenerator::Sitemap.create do
13+
add '/welcome', :priority => 0.7, :changefreq => 'montlhy'
14+
add '/contact_us', :priority => 0.5, :changefreq => 'montlhy'
15+
add '/blog', :priority => 0.7, :changefreq => 'weekly'
16+
add '/api', :priority => 0.5, :changefreq => 'monthly'
17+
add '/faq', :priority => 0.5, :changefreq => 'monthly'
18+
add '/privacy_policy', :priority => 0.2, :changefreq => 'monthly'
19+
add '/tos', :priority => 0.2, :changefreq => 'monthly'
20+
add '/jobs', :priority => 0.7, :changefreq => 'daily'
21+
add '/employers', :priority => 0.7, :changefreq => 'monthly'
22+
Protip.find_each do |protip|
23+
add protip_path(protip), :lastmod => protip.updated_at
24+
end
25+
Team.all.each do |team|
26+
add teamname_path(slug: team.slug), :lastmod => team.updated_at
27+
team.jobs.each do |job|
28+
add job_path(:slug => team.slug, :job_id => job.public_id), :lastmod => job.updated_at
29+
end
30+
end
31+
User.find_each do |user|
32+
add badge_path(user.username), :lastmod => user.updated_at
33+
end
34+
BlogPost.all_public.each do |blog_post|
35+
add blog_post_path(blog_post.id), :lastmod => blog_post.posted
36+
end
37+
end
38+
SitemapGenerator::Sitemap.ping_search_engines
39+
end
40+
end

public/robots.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66

77
User-agent: EasouSpider
88
Disallow: /
9+
Sitemap: https://coderwall-assets-0.s3.amazonaws.com/sitemaps/sitemap.xml.gz

0 commit comments

Comments
 (0)