Add sitemap generation (#1465)

This commit is contained in:
Ben Halpern 2019-01-05 19:43:24 -05:00 committed by GitHub
parent e79f3bfbc1
commit 98b68fa15c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 0 deletions

2
.gitignore vendored
View file

@ -51,3 +51,5 @@ package-lock.json
#Jetbrains Tools
.idea/
#sitemap
/public/sitemap.xml.gz

View file

@ -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"

View file

@ -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)

32
config/sitemap.rb Normal file
View file

@ -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