From a175b5bc9bb6bccaf2ca83a4cd4221f54ac8cd74 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Fri, 2 Dec 2016 11:26:46 +0100 Subject: [PATCH 1/6] add gem sitemap_generator --- Gemfile | 1 + Gemfile.lock | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/Gemfile b/Gemfile index 1ce218638..b50540b5f 100644 --- a/Gemfile +++ b/Gemfile @@ -55,6 +55,7 @@ gem 'devise-async' gem 'newrelic_rpm', '~> 3.17.0.325' gem 'whenever', require: false gem 'pg_search' +gem 'sitemap_generator' gem 'ahoy_matey', '~> 1.4.2' gem 'groupdate', '~> 3.1.0' # group temporary data diff --git a/Gemfile.lock b/Gemfile.lock index 50ab5bb9d..d787b4a81 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -381,6 +381,8 @@ GEM json (>= 1.8, < 3) simplecov-html (~> 0.10.0) simplecov-html (0.10.0) + sitemap_generator (5.2.0) + builder (~> 3.0) social-share-button (0.3.1) coffee-rails sass-rails @@ -511,6 +513,7 @@ DEPENDENCIES rvm1-capistrano3 sass-rails (~> 5.0, >= 5.0.4) savon + sitemap_generator social-share-button spring spring-commands-rspec @@ -522,3 +525,6 @@ DEPENDENCIES unicorn (~> 5.1.0) web-console (= 3.3.0) whenever + +BUNDLED WITH + 1.13.6 From bb61d73c04998ba0fefee35bc2f924ff7e16a10d Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Fri, 2 Dec 2016 11:28:39 +0100 Subject: [PATCH 2/6] add sitemap generator --- config/sitemap.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 config/sitemap.rb diff --git a/config/sitemap.rb b/config/sitemap.rb new file mode 100644 index 000000000..73990620c --- /dev/null +++ b/config/sitemap.rb @@ -0,0 +1,30 @@ +# default host +SitemapGenerator::Sitemap.default_host = "https://decide.madrid.es" + +# sitemap generator +SitemapGenerator::Sitemap.create do + pages = Dir.entries(File.join(Rails.root,"app","views","pages")) + pages.each do |page| + page_name = page.split(".").first + add page_name if page_name.present? + end + + add "help_translate" + + add debates_path, priority: 0.7, changefreq: "daily" + Debate.find_each do |debate| + add debate_path(debate), lastmod: debate.updated_at + end + + add proposals_path, priority: 0.7, changefreq: "daily" + Proposal.find_each do |proposal| + add proposal_path(proposal), lastmod: proposal.updated_at + end + + add proposal_ballots_path + + add spending_proposals_path, priority: 0.7, changefreq: "daily" + SpendingProposal.find_each do |spending_proposal| + add spending_proposal_path(spending_proposal), lastmod: spending_proposal.updated_at + end +end From 39401656424bf9f1d5e2ca9ef7405fb3e818b971 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Fri, 2 Dec 2016 11:29:35 +0100 Subject: [PATCH 3/6] don't compress the sitemap --- config/sitemap.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/config/sitemap.rb b/config/sitemap.rb index 73990620c..9e60f483f 100644 --- a/config/sitemap.rb +++ b/config/sitemap.rb @@ -1,3 +1,9 @@ +# not use compression +class SitemapGenerator::FileAdapter + def gzip(stream, data); stream.write(data); stream.close end +end +SitemapGenerator::Sitemap.namer = SitemapGenerator::SimpleNamer.new(:sitemap, extension: '.xml') + # default host SitemapGenerator::Sitemap.default_host = "https://decide.madrid.es" From fec84c47103d56e8b41d7fc8c9151b3a6562d0a6 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Fri, 2 Dec 2016 11:30:12 +0100 Subject: [PATCH 4/6] include public/sitemap to gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index f4b9c99fb..35f5651a4 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,5 @@ # Mac finder artifacts .DS_Store .ruby-gemset + +public/sitemap.xml \ No newline at end of file From 0c09d1016c06504bcb0670a9e81181b6eb54ac8d Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Fri, 2 Dec 2016 11:30:57 +0100 Subject: [PATCH 5/6] generate a new sitemap everyday at 5:00am --- config/schedule.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config/schedule.rb b/config/schedule.rb index 308cdc69c..f4c03fd61 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -22,3 +22,7 @@ every 1.minute do command "date > ~/cron-test.txt" end + +every 1.day, at: '5:00 am' do + rake "-s sitemap:refresh" +end From 9a2b049ec88626aa0a91a6f0a2346b2eee5c7e50 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Sat, 3 Dec 2016 12:19:58 +0100 Subject: [PATCH 6/6] take default host from settings --- config/sitemap.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/sitemap.rb b/config/sitemap.rb index 9e60f483f..11ec9fb09 100644 --- a/config/sitemap.rb +++ b/config/sitemap.rb @@ -5,7 +5,7 @@ end SitemapGenerator::Sitemap.namer = SitemapGenerator::SimpleNamer.new(:sitemap, extension: '.xml') # default host -SitemapGenerator::Sitemap.default_host = "https://decide.madrid.es" +SitemapGenerator::Sitemap.default_host = Setting["url"] # sitemap generator SitemapGenerator::Sitemap.create do