diff --git a/.gitignore b/.gitignore index 91eb76656..df2840a65 100644 --- a/.gitignore +++ b/.gitignore @@ -51,3 +51,5 @@ package-lock.json #Jetbrains Tools .idea/ +#sitemap +/public/sitemap.xml.gz \ No newline at end of file diff --git a/Gemfile b/Gemfile index c0bdefec9..6e9693e8b 100644 --- a/Gemfile +++ b/Gemfile @@ -87,6 +87,7 @@ gem "sass-rails", "~> 5.0" gem "sdoc", "~> 0.4", group: :doc gem "serviceworker-rails", "~> 0.5" gem "share_meow_client", "~> 0.1" +gem "sitemap_generator", "~> 6.0" gem "skylight", "~> 2.0" gem "slack-notifier", "~> 2.3" gem "sprockets", "~> 3.7" diff --git a/Gemfile.lock b/Gemfile.lock index ccb9b5dd7..dd93f2b69 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -822,6 +822,8 @@ GEM rack (~> 2.0) rack-protection (= 2.0.4) tilt (~> 2.0) + sitemap_generator (6.0.1) + builder (~> 3.0) skylight (2.0.2) skylight-core (= 2.0.2) skylight-core (2.0.2) @@ -1031,6 +1033,7 @@ DEPENDENCIES shoulda-matchers (~> 3.1) simplecov (~> 0.16) sinatra (~> 2.0) + sitemap_generator (~> 6.0) skylight (~> 2.0) slack-notifier (~> 2.3) spring (~> 2.0) diff --git a/config/sitemap.rb b/config/sitemap.rb new file mode 100644 index 000000000..c8badfa26 --- /dev/null +++ b/config/sitemap.rb @@ -0,0 +1,32 @@ +if Rails.env.production? + SitemapGenerator::Sitemap.adapter = SitemapGenerator::S3Adapter.new( + fog_provider: "AWS", + aws_access_key_id: ApplicationConfig["AWS_ID"], + aws_secret_access_key: ApplicationConfig["AWS_SECRET"], + fog_directory: ApplicationConfig["AWS_BUCKET_NAME"], + fog_region: "us-east-1", + ) + + SitemapGenerator::Sitemap.public_path = "tmp/" + SitemapGenerator::Sitemap.sitemaps_host = "https://thepracticaldev.s3.amazonaws.com/" + SitemapGenerator::Sitemap.sitemaps_path = "sitemaps/" +end + +SitemapGenerator::Sitemap.default_host = "#{ApplicationConfig['APP_PROTOCOL']}#{ApplicationConfig['APP_DOMAIN']}" + +SitemapGenerator::Sitemap.create do + Article.where(published: true). + where("reactions_count > ? OR featured = ?", 20, true). + where(published: true). + order("last_comment_at DESC").limit(1000).find_each do |article| + add article.path, lastmod: article.last_comment_at + end + + User.order("comments_count DESC").where("updated_at > ?", 5.days.ago).limit(250).find_each do |user| + add "/#{user.username}", changefreq: "daily" + end + + Tag.order("hotness_score DESC").limit(100).find_each do |tag| + add "/t/#{tag.name}", changefreq: "daily" + end +end