Files
growstuff/lib/tasks/sitemap_cached.rake
google-labs-jules[bot] 7f75aed146 feat: Add sitemap generator
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.
2025-12-01 14:31:54 +00:00

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