2025-01-23 19:02:52 +08:00
|
|
|
# Set the host name for URL creation
|
2025-01-23 19:40:08 +08:00
|
|
|
host = Rails.env.production? ? "https://todayaiweather.com" : "http://127.0.0.1:3000"
|
2025-01-26 00:07:44 +08:00
|
|
|
Rails.application.routes.default_url_options[:host] = host
|
|
|
|
SitemapGenerator::Sitemap.adapter = SitemapGenerator::AwsSdkAdapter.new(
|
|
|
|
Rails.application.credentials.dig(:aws, :bucket),
|
|
|
|
aws_access_key_id: Rails.application.credentials.dig(:aws, :access_key_id),
|
|
|
|
aws_secret_access_key: Rails.application.credentials.dig(:aws, :secret_access_key),
|
|
|
|
aws_region: Rails.application.credentials.dig(:aws, :region)
|
|
|
|
)
|
|
|
|
SitemapGenerator::Sitemap.sitemaps_path = "sitemaps/"
|
2025-01-23 19:40:08 +08:00
|
|
|
|
|
|
|
SitemapGenerator::Sitemap.default_host = host
|
2025-01-23 19:02:52 +08:00
|
|
|
|
|
|
|
SitemapGenerator::Sitemap.create do
|
2025-01-23 19:03:14 +08:00
|
|
|
add root_path, changefreq: "daily", priority: 1.0
|
|
|
|
add cities_path, changefreq: "daily", priority: 0.9
|
|
|
|
add arts_path, changefreq: "daily", priority: 0.9
|
2025-01-23 19:02:52 +08:00
|
|
|
|
|
|
|
City.find_each do |city|
|
|
|
|
add city_path(city),
|
2025-01-23 19:03:14 +08:00
|
|
|
changefreq: "daily",
|
2025-01-23 19:02:52 +08:00
|
|
|
priority: 0.8,
|
|
|
|
lastmod: city.updated_at
|
|
|
|
end
|
|
|
|
|
|
|
|
WeatherArt.includes(:city).find_each do |art|
|
|
|
|
add city_weather_art_path(art.city, art),
|
2025-01-23 19:03:14 +08:00
|
|
|
changefreq: "daily",
|
2025-01-23 19:02:52 +08:00
|
|
|
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
|
|
|
} ] if art.image.attached?
|
2025-01-23 19:02:52 +08:00
|
|
|
end
|
|
|
|
# Put links creation logic here.
|
|
|
|
#
|
|
|
|
# The root path '/' and sitemap index file are added automatically for you.
|
|
|
|
# Links are added to the Sitemap in the order they are specified.
|
|
|
|
#
|
|
|
|
# Usage: add(path, options={})
|
|
|
|
# (default options are used if you don't specify)
|
|
|
|
#
|
|
|
|
# Defaults: :priority => 0.5, :changefreq => 'weekly',
|
|
|
|
# :lastmod => Time.now, :host => default_host
|
|
|
|
#
|
|
|
|
# Examples:
|
|
|
|
#
|
|
|
|
# Add '/articles'
|
|
|
|
#
|
|
|
|
# add articles_path, :priority => 0.7, :changefreq => 'daily'
|
|
|
|
#
|
|
|
|
# Add all articles:
|
|
|
|
#
|
|
|
|
# Article.find_each do |article|
|
|
|
|
# add article_path(article), :lastmod => article.updated_at
|
|
|
|
# end
|
|
|
|
end
|