- Include formattedDate in the RSS feed response - Utilize art.formatted_time method for better date formatting This change enhances the RSS feed by providing a more user-friendly formatted date alongside the existing weather date. This allows clients consuming the RSS feed to display dates in a more readable format, improving overall usability.
44 lines
1.4 KiB
Ruby
44 lines
1.4 KiB
Ruby
class RssController < ApplicationController
|
|
def feed
|
|
@weather_arts = WeatherArt.order(created_at: :desc).includes(:image_attachment, city: [ :country, :state ]).limit(20)
|
|
|
|
Rails.logger.info "RssController#feed - Format: #{request.format}"
|
|
|
|
respond_to do |format|
|
|
format.rss { render layout: false }
|
|
format.json { render json: generate_json_feed }
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def generate_json_feed
|
|
{
|
|
version: "https://jsonfeed.org/version/1.1",
|
|
title: "Today AI Weather Art",
|
|
home_page_url: root_url,
|
|
feed_url: rss_feed_url(format: :json),
|
|
items: @weather_arts.map do |art|
|
|
{
|
|
id: city_weather_art_url(art.city, art),
|
|
url: city_weather_art_url(art.city, art),
|
|
title: "#{art.city.full_name} Weather Art",
|
|
content_html: "<p>#{art.description}</p>",
|
|
date_published: art.created_at.iso8601,
|
|
image: art.image.attached? ? rails_blob_url(art.webp_image.processed) : nil,
|
|
# 自定义字段
|
|
_weather: {
|
|
country: art.city&.country&.name,
|
|
city: art.city&.name,
|
|
state: art.city&.state&.name,
|
|
description: art.description,
|
|
prompt: art.prompt,
|
|
date: art.weather_date&.strftime("%Y-%m-%d"),
|
|
formattedDate: art.formatted_time(:all, true)
|
|
}
|
|
}
|
|
end
|
|
}
|
|
end
|
|
end
|