diff --git a/Gemfile b/Gemfile index 1ad4bde6..542770b0 100644 --- a/Gemfile +++ b/Gemfile @@ -121,6 +121,7 @@ gem 'rakismet' gem 'ruby-progressbar' gem 'sanitize' gem 'simple_form' +gem 'sitemap_generator' gem 'tweet-button' gem 'local_time' diff --git a/Gemfile.lock b/Gemfile.lock index 83c2acaa..47a2aabd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -619,6 +619,8 @@ GEM rack (~> 1.4) rack-protection (~> 1.4) tilt (~> 1.3, >= 1.3.4) + sitemap_generator (5.0.5) + builder slim (2.0.3) temple (~> 0.6.6) tilt (>= 1.3.3, < 2.1) @@ -804,6 +806,7 @@ DEPENDENCIES simple_form simplecov sinatra + sitemap_generator slim-rails spring spring-commands-rspec diff --git a/app/clock.rb b/app/clock.rb index 200eb771..748b1b5d 100644 --- a/app/clock.rb +++ b/app/clock.rb @@ -44,5 +44,9 @@ ClearExpiredSessionsJob.perform_async end +every(1.day, 'sitemap:refresh', at: '06:00') do + SitemapRefreshWorker.perform_async +end + # This is tied with broken code. Probably should delete # every(1.day, 'facts:system', at: '00:00') {} diff --git a/app/workers/sitemap_refresh_worker.rb b/app/workers/sitemap_refresh_worker.rb new file mode 100644 index 00000000..62929b93 --- /dev/null +++ b/app/workers/sitemap_refresh_worker.rb @@ -0,0 +1,40 @@ +class SitemapRefreshWorker + include Sidekiq::Worker + sidekiq_options queue: :high + + def perform + SitemapGenerator::Sitemap.default_host = "https://coderwall.com" + SitemapGenerator::Sitemap.public_path = 'tmp/' + SitemapGenerator::Sitemap.sitemaps_host = "http://#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com/" + SitemapGenerator::Sitemap.sitemaps_path = 'sitemaps/' + SitemapGenerator::Sitemap.adapter = SitemapGenerator::WaveAdapter.new + + SitemapGenerator::Sitemap.create do + add '/welcome', :priority => 0.7, :changefreq => 'montlhy' + add '/contact_us', :priority => 0.5, :changefreq => 'montlhy' + add '/blog', :priority => 0.7, :changefreq => 'weekly' + add '/api', :priority => 0.5, :changefreq => 'monthly' + add '/faq', :priority => 0.5, :changefreq => 'monthly' + add '/privacy_policy', :priority => 0.2, :changefreq => 'monthly' + add '/tos', :priority => 0.2, :changefreq => 'monthly' + add '/jobs', :priority => 0.7, :changefreq => 'daily' + add '/employers', :priority => 0.7, :changefreq => 'monthly' + Protip.find_each do |protip| + add protip_path(protip), :lastmod => protip.updated_at + end + Team.all.each do |team| + add teamname_path(slug: team.slug), :lastmod => team.updated_at + team.jobs.each do |job| + add job_path(:slug => team.slug, :job_id => job.public_id), :lastmod => job.updated_at + end + end + User.find_each do |user| + add badge_path(user.username), :lastmod => user.updated_at + end + BlogPost.all_public.each do |blog_post| + add blog_post_path(blog_post.id), :lastmod => blog_post.posted + end + end + SitemapGenerator::Sitemap.ping_search_engines + end +end \ No newline at end of file diff --git a/public/robots.txt b/public/robots.txt index 3f1858c5..dd34c333 100644 --- a/public/robots.txt +++ b/public/robots.txt @@ -6,3 +6,4 @@ User-agent: EasouSpider Disallow: / +Sitemap: https://coderwall-assets-0.s3.amazonaws.com/sitemaps/sitemap.xml.gz \ No newline at end of file