today_ai_weather/app/helpers/application_helper.rb
songtianlun 07afbda252
Some checks failed
Docker Dev / docker (push) Has been cancelled
CI / scan_ruby (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / test (push) Has been cancelled
Docker Main / docker (push) Has been cancelled
feat: add default canonical URL handling
- Introduce a new before_action to set the default canonical URL
- Implement set_canonical_url method to manage canonical URLs
- Update application helper to use the canonical URL for meta tags

This change enhances SEO by ensuring that the canonical URL is set
correctly for each page, preventing duplicate content issues. The
canonical URL is derived from the original request URL, excluding
query parameters.
2025-04-23 20:45:49 +08:00

54 lines
1.8 KiB
Ruby

module ApplicationHelper
def weather_art_schema(weather_art)
{
"@context": "https://schema.org",
"@type": "ImageObject",
"name": "#{weather_art.city.name} Weather Art",
"description": weather_art.description,
"datePublished": weather_art.created_at.iso8601,
"contentUrl": url_for(weather_art.image),
"author": {
"@type": "Organization",
"name": "TodayAIWeather"
},
"locationCreated": {
"@type": "Place",
"name": weather_art.city.name,
"address": {
"@type": "PostalAddress",
"addressCountry": weather_art.city.country.name
}
}
}.to_json.html_safe if weather_art.image.attached?
end
def current_user_is_admin?
current_user&.admin?
end
def default_meta_tags
{
site: t("site_name", default: "TodayAIWeather"),
title: t("meta.default.title", default: "TodayAIWeather"),
description: t("meta.default.description", default: "Experience weather through artistic AI visualization. Daily updated weather art for cities worldwide."),
keywords: t("meta.default.keywords", default: "AI weather art, weather visualization, city weather, artificial intelligence"),
separator: "—".html_safe,
reverse: true,
canonical: @canonical_url,
og: {
site_name: t("site_name", default: "TodayAIWeather"),
type: "website",
keywords: t("meta.default.og.keywords", default: "ai, ai web, ai art, ai weather, weather art, AI visualization, today ai weather"),
url: request.original_url
},
alternate: available_locales_with_urls
}
end
def available_locales_with_urls
I18n.available_locales.each_with_object({}) do |locale, hash|
hash[locale.to_s] = url_for(locale: locale)
end
end
end