]> git.openstreetmap.org Git - rails.git/commitdiff
Pass properties hash to OpenGraph helper
authorAnton Khorev <tony29@yandex.ru>
Wed, 7 Aug 2024 05:13:29 +0000 (08:13 +0300)
committerAnton Khorev <tony29@yandex.ru>
Wed, 7 Aug 2024 15:58:47 +0000 (18:58 +0300)
app/helpers/open_graph_helper.rb
app/views/layouts/_meta.html.erb

index a2c429ed7ee007dcb7007eb50d43d401cf6f903b..dbd20446295d76a556d10a28481e26eb40a7e039 100644 (file)
@@ -1,7 +1,7 @@
 module OpenGraphHelper
   require "addressable/uri"
 
-  def opengraph_tags(title, og_image, og_image_alt)
+  def opengraph_tags(title, properties)
     tags = {
       "og:site_name" => t("layouts.project_name.title"),
       "og:title" => title || t("layouts.project_name.title"),
@@ -9,7 +9,7 @@ module OpenGraphHelper
       "og:url" => url_for(:only_path => false),
       "og:description" => t("layouts.intro_text")
     }.merge(
-      opengraph_image_properties(og_image, og_image_alt)
+      opengraph_image_properties(properties)
     )
 
     safe_join(tags.map do |property, content|
@@ -19,13 +19,13 @@ module OpenGraphHelper
 
   private
 
-  def opengraph_image_properties(og_image, og_image_alt)
+  def opengraph_image_properties(properties)
     begin
-      if og_image
-        properties = {}
-        properties["og:image"] = Addressable::URI.join(root_url, og_image).normalize
-        properties["og:image:alt"] = og_image_alt if og_image_alt
-        return properties
+      if properties["og:image"]
+        image_properties = {}
+        image_properties["og:image"] = Addressable::URI.join(root_url, properties["og:image"]).normalize
+        image_properties["og:image:alt"] = properties["og:image:alt"] if properties["og:image:alt"]
+        return image_properties
       end
     rescue Addressable::URI::InvalidURIError
       # return default image
index f09449761a4990c9226fb17c4b9cf64e4fc0d533..822238894c287b4e80c56c37ff9eae3898f3fb3f 100644 (file)
@@ -21,7 +21,7 @@
 <% end -%>
 <%= tag.link :rel => "search", :type => "application/opensearchdescription+xml", :title => "OpenStreetMap Search", :href => asset_path("osm.xml") %>
 <%= tag.meta :name => "description", :content => "OpenStreetMap is the free wiki world map." %>
-<%= opengraph_tags(@title, @og_image, @og_image_alt) %>
+<%= opengraph_tags(@title, "og:image" => @og_image, "og:image:alt" => @og_image_alt) %>
 <% if flash[:matomo_goal] -%>
 <%= tag.meta :name => "matomo-goal", :content => flash[:matomo_goal] %>
 <% end -%>