- 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.
54 lines
1.8 KiB
Ruby
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
|