2025-01-23 19:02:52 +08:00
|
|
|
class RefreshSitemapWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
|
|
|
def perform
|
|
|
|
SitemapGenerator::Sitemap.create do
|
|
|
|
add root_path, changefreq: "daily", priority: 1.0
|
|
|
|
add cities_path, changefreq: "daily", priority: 0.9
|
|
|
|
add arts_path, changefreq: "daily", priority: 0.9
|
|
|
|
|
|
|
|
City.find_each do |city|
|
|
|
|
add city_path(city),
|
|
|
|
changefreq: "daily",
|
|
|
|
priority: 0.8,
|
|
|
|
lastmod: city.updated_at
|
|
|
|
end
|
|
|
|
|
|
|
|
WeatherArt.includes(:city).find_each do |art|
|
|
|
|
if art.image.attached?
|
|
|
|
add city_weather_art_path(art.city, art),
|
|
|
|
changefreq: "daily",
|
|
|
|
priority: 0.7,
|
|
|
|
lastmod: art.updated_at,
|
2025-01-23 19:03:14 +08:00
|
|
|
images: [ {
|
2025-01-23 19:02:52 +08:00
|
|
|
loc: url_for(art.image),
|
|
|
|
title: "#{art.city.name} Weather Art - #{art.weather_date.strftime('%B %d, %Y')}"
|
2025-01-23 19:03:14 +08:00
|
|
|
} ]
|
2025-01-23 19:02:52 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
SitemapGenerator::Sitemap.ping_search_engines if Rails.env.production?
|
|
|
|
rescue => e
|
|
|
|
Rails.logger.error "Error refreshing sitemap: #{e.message}"
|
|
|
|
end
|
2025-01-23 19:03:14 +08:00
|
|
|
end
|