feat: enhance city description generation

- Modify get_description method to include an additional
  parameter for user context
- Update usage in views to reflect the new parameter
- Adjust temporary description message based on user context

This change enhances the city description generation logic by
allowing differentiation in how the description is provided
depending on whether the calling context is a user. It improves
the user experience while ensuring that non-user contexts
handle descriptions differently. This minor enhancement also
included updating the view to support this new logic.
This commit is contained in:
songtianlun 2025-04-12 14:46:44 +08:00
parent e33209ccdd
commit 6f01174ea9
3 changed files with 7 additions and 4 deletions

View File

@ -65,7 +65,7 @@ class CitiesController < ApplicationController
set_meta_tags(
title: t("meta.cities.show.title", city_name: @city.name, country_name: @city&.country&.name.to_s),
description: t("meta.cities.show.description", city_name: @city.name),
description: t("meta.cities.show.description", city_name: @city.get_description("en", false, true, false)),
keywords: t("meta.cities.show.keywords", city_name: @city.name, country_name: @city.country&.name.to_s),
og: {
image: @city.latest_weather_art&.image&.attached? ? url_for(@city.latest_weather_art.image) : nil

View File

@ -251,7 +251,7 @@ class City < ApplicationRecord
end
# 获取城市描述,支持多语言
def get_description(locale = I18n.locale.to_s, force_refresh = false, quick = false)
def get_description(locale = I18n.locale.to_s, force_refresh = false, quick = false, is_user = true)
# 标准化语言代码为小写字符串
locale = locale.to_s.downcase
@ -266,7 +266,10 @@ class City < ApplicationRecord
if quick
GenerateCityDescriptionWorker.perform_async(id, force_refresh)
return "#{full_name} - Please wait a Minute. (City description is being generated in the background. Please refresh the page in a moment to see the complete description)."
temp_desc = !is_user ?
"#{full_name}" :
"#{full_name} - Please wait a Minute. (City description is being generated in the background. Please refresh the page in a moment to see the complete description)."
return temp_desc
end
# 否则,生成新的描述并保存

View File

@ -9,7 +9,7 @@
<span>City Description</span>
</h2>
<div class="prose max-w-none text-left">
<p><%= city.get_description('en', false, true) %></p>
<p><%= city.get_description('en', false, true, true) %></p>
</div>
<div class="text-sm opacity-70 mt-4 flex items-center gap-2">
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">