feat: add tag formatting helper
This commit is contained in:
parent
2d227d5871
commit
5de3d4306f
@ -1,4 +1,5 @@
|
||||
class CitiesController < ApplicationController
|
||||
include TagHelper
|
||||
before_action :authenticate_user!, only: [ :generate_weather_art ]
|
||||
before_action :require_admin, only: [ :generate_weather_art ]
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
class RssController < ApplicationController
|
||||
include TagHelper
|
||||
def feed
|
||||
@weather_arts = WeatherArt.order(created_at: :desc).includes(:image_attachment, city: [ :country, :state ]).limit(20)
|
||||
|
||||
@ -27,11 +28,11 @@ class RssController < ApplicationController
|
||||
date_published: art.created_at.iso8601,
|
||||
image: art.image.attached? ? rails_blob_url(art.webp_image.processed) : nil,
|
||||
metadata: {
|
||||
country: art.city&.country&.name,
|
||||
city: art.city&.name,
|
||||
state: art.city&.state&.name,
|
||||
region: art.city&.region&.name,
|
||||
subregion: art.city&.subregion&.name,
|
||||
country: format_as_tag(art.city&.country&.name),
|
||||
city: format_as_tag(art.city&.name),
|
||||
state: format_as_tag(art.city&.state&.name),
|
||||
region: format_as_tag(art.city&.region&.name),
|
||||
subregion: format_as_tag(art.city&.subregion&.name),
|
||||
description: art.description,
|
||||
prompt: art.prompt,
|
||||
date: art.weather_date&.strftime("%Y-%m-%d"),
|
||||
|
@ -1,4 +1,5 @@
|
||||
class WeatherArtsController < ApplicationController
|
||||
include TagHelper
|
||||
def show
|
||||
@city = City.friendly.find(params[:city_id])
|
||||
@weather_art = @city.weather_arts.friendly.find(params[:slug])
|
||||
|
14
app/helpers/tag_helper.rb
Normal file
14
app/helpers/tag_helper.rb
Normal file
@ -0,0 +1,14 @@
|
||||
module TagHelper
|
||||
def format_as_tag(text)
|
||||
return nil if text.blank?
|
||||
|
||||
# 下划线方式 (选项1)
|
||||
text.strip.gsub(/\s+/, "_")
|
||||
|
||||
# 或者删除空格 (选项2)
|
||||
# text.strip.gsub(/\s+/, '')
|
||||
|
||||
# 或者驼峰式 (选项3)
|
||||
# text.strip.gsub(/\s+(\w)/) { $1.upcase }.gsub(/\s+/, '')
|
||||
end
|
||||
end
|
@ -87,7 +87,7 @@
|
||||
<%= render "shared/share_social",
|
||||
title: share_title,
|
||||
description: share_description,
|
||||
tags: "AIWeather,Art,AIart,Weather,#{@city&.name},#{@city&.country&.name}",
|
||||
tags: "AIWeather,Art,AIart,Weather,#{format_as_tag(@city&.name)},#{format_as_tag(@city&.country&.name)},#{format_as_tag(@city&.country&.region&.name)},#{format_as_tag(@city&.country&.subregion&.name)}",
|
||||
image: url_for(@city&.latest_weather_art&.webp_image&.processed)
|
||||
%>
|
||||
</div>
|
||||
|
@ -119,7 +119,7 @@
|
||||
<%= render "shared/share_social",
|
||||
title: share_title,
|
||||
description: share_description,
|
||||
tags: "AIWeather,Art,AIart,Weather,#{@weather_art.city&.name},#{@weather_art&.city&.country&.name}",
|
||||
tags: "AIWeather,Art,AIart,Weather,#{format_as_tag(@weather_art.city&.name)},#{format_as_tag(@weather_art.city&.country&.name)},#{format_as_tag(@weather_art.city&.country&.region&.name)},#{format_as_tag(@weather_art.city&.country&.subregion&.name)}",
|
||||
image: url_for(@weather_art.webp_image.processed)
|
||||
%>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user