]> git.openstreetmap.org Git - rails.git/commitdiff
Remove "User's Diary" from diary entry og:title
authorAnton Khorev <tony29@yandex.ru>
Sun, 20 Oct 2024 16:10:36 +0000 (19:10 +0300)
committerAnton Khorev <tony29@yandex.ru>
Sun, 20 Oct 2024 16:12:09 +0000 (19:12 +0300)
app/controllers/diary_entries_controller.rb
app/helpers/open_graph_helper.rb
test/controllers/diary_entries_controller_test.rb

index ff6dfc826cbf67763889a8c9c490b87558a58c45..760c9a301248d5bba8ff9b03ca7540e2d31d875d 100644 (file)
@@ -71,6 +71,7 @@ class DiaryEntriesController < ApplicationController
     if @entry
       @title = t ".title", :user => params[:display_name], :title => @entry.title
       @opengraph_properties = {
+        "og:title" => @entry.title,
         "og:image" => @entry.body.image,
         "og:image:alt" => @entry.body.image_alt,
         "og:description" => @entry.body.description,
index cde848e5d13762ac718431632aaf44c597c3bf54..a496268e49909c7381cec21ec2729c15dfc4aeb4 100644 (file)
@@ -4,7 +4,7 @@ module OpenGraphHelper
   def opengraph_tags(title, properties)
     tags = {
       "og:site_name" => t("layouts.project_name.title"),
-      "og:title" => title || t("layouts.project_name.title"),
+      "og:title" => properties["og:title"] || title || t("layouts.project_name.title"),
       "og:type" => "website",
       "og:url" => url_for(:only_path => false),
       "og:description" => properties["og:description"] || t("layouts.intro_text")
index aad759b5b68e3ebae15e20e60df50b27cf30814f..7d543250bc88a17b565cc72d99196d3f4b48a16d 100644 (file)
@@ -648,6 +648,17 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest
     end
   end
 
+  def test_show_og_title
+    user = create(:user)
+    diary_entry = create(:diary_entry, :user => user, :title => "The Important Blog Post")
+
+    get diary_entry_path(user, diary_entry)
+    assert_response :success
+    assert_dom "head meta[property='og:title']" do
+      assert_dom "> @content", "The Important Blog Post"
+    end
+  end
+
   def test_show_og_image_with_no_image
     user = create(:user)
     diary_entry = create(:diary_entry, :user => user, :body => "nothing")