feat: improve weather art display and generation

- Display the latest weather art on the cities index page.
- Update the weather art preview image size to be big.
- Improve image display by using webp format.
- Adjust the daily and per-run generation limits.

These changes enhance the user experience by providing more
up-to-date and visually appealing content, while also controlling
the resource usage during image generation.
This commit is contained in:
songtianlun 2025-02-17 00:15:32 +08:00
parent fa1fc7c21a
commit f02587da57
5 changed files with 6 additions and 5 deletions

View File

@ -5,6 +5,7 @@ class CitiesController < ApplicationController
def index
@regions = Region.order(:name)
@cities = City.includes(:country, country: :region).order(:name)
@latest_arts = WeatherArt.includes(:city, :image_attachment).latest(1)
if params[:query].present?
@cities = @cities.search_by_name(params[:query])

View File

@ -120,7 +120,7 @@ class WeatherArt < ApplicationRecord
medium: [ 896, 512 ],
small: [ 448, 256 ]
}.freeze
def preview_image(size = :medium)
def preview_image(size = :big)
return nil unless image.attached?
width, height = PREVIEW_DIMENSIONS[size] || PREVIEW_DIMENSIONS[:medium]

View File

@ -1,7 +1,7 @@
<!-- app/views/cities/index.html.erb -->
<div class="min-h-screen">
<!-- 页面标题和背景 -->
<% featured_art = WeatherArt.includes(:city).joins(:image_attachment).order(created_at: :desc).first %>
<% featured_art = @latest_arts.first %>
<div class="relative bg-base-100">
<!-- 背景图像和渐变 -->
<% if featured_art&.image&.attached? %>

View File

@ -3,7 +3,7 @@
<section class="h-screen-90 relative overflow-hidden">
<% if @latest_arts.first&.image&.attached? %>
<div class="absolute inset-0">
<%= image_tag @latest_arts.first.preview_image(:large).processed, class: "w-full h-full object-cover" %>
<%= image_tag @latest_arts.first.webp_image.processed, class: "w-full h-full object-cover" %>
<div class="absolute inset-0 bg-gradient-to-r from-base-100/90 to-base-100/50"></div>
</div>
<% end %>

View File

@ -4,8 +4,8 @@ class BatchGenerateWeatherArtsWorker
GENERATION_INTERVAL = 36.hours
MAX_DURATION = 5.minutes
SLEEP_DURATION = 10.seconds
DAILY_GENERATION_LIMIT = 50 # 每日生成图片上限
PER_RUN_GENERATION_LIMIT = 5 # 每次运行生成图片上限
DAILY_GENERATION_LIMIT = 60 # 每日生成图片上限
PER_RUN_GENERATION_LIMIT = 3 # 每次运行生成图片上限
def perform(*args)
start_time = Time.current