mirror of
https://github.com/Growstuff/growstuff.git
synced 2025-12-23 17:47:49 -05:00
Adds the `sitemap_generator` gem to generate a sitemap. - Includes static routes and dynamic routes for active crops, plantings, seeds, photos, posts, and members. - Implements a caching mechanism to ensure the sitemap is generated no more frequently than every 72 hours. - Updates `robots.txt` to point to the new sitemap. - Includes a unit test for the caching Rake task.
20 lines
591 B
Ruby
20 lines
591 B
Ruby
# frozen_string_literal: true
|
|
|
|
namespace :sitemap do
|
|
desc 'Generate sitemap, but only if it has not been generated in the last 72 hours'
|
|
task cached_refresh: :environment do
|
|
sitemap_file = Rails.root.join('tmp', 'sitemap_generated_at.txt')
|
|
if File.exist?(sitemap_file)
|
|
last_generated_at = Time.parse(File.read(sitemap_file))
|
|
if last_generated_at > 72.hours.ago
|
|
puts 'Sitemap has been generated within the last 72 hours. Skipping.'
|
|
exit
|
|
end
|
|
end
|
|
|
|
Rake::Task['sitemap:refresh'].invoke
|
|
|
|
File.write(sitemap_file, Time.now.to_s)
|
|
end
|
|
end
|