From: Anton Khorev Date: Sun, 20 Oct 2024 16:10:36 +0000 (+0300) Subject: Remove "User's Diary" from diary entry og:title X-Git-Tag: live~73^2 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/eaabf7bb592d9cb986f25347350845c80a671091?ds=sidebyside;hp=-c Remove "User's Diary" from diary entry og:title --- eaabf7bb592d9cb986f25347350845c80a671091 diff --git a/app/controllers/diary_entries_controller.rb b/app/controllers/diary_entries_controller.rb index ff6dfc826..760c9a301 100644 --- a/app/controllers/diary_entries_controller.rb +++ b/app/controllers/diary_entries_controller.rb @@ -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, diff --git a/app/helpers/open_graph_helper.rb b/app/helpers/open_graph_helper.rb index cde848e5d..a496268e4 100644 --- a/app/helpers/open_graph_helper.rb +++ b/app/helpers/open_graph_helper.rb @@ -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") diff --git a/test/controllers/diary_entries_controller_test.rb b/test/controllers/diary_entries_controller_test.rb index aad759b5b..7d543250b 100644 --- a/test/controllers/diary_entries_controller_test.rb +++ b/test/controllers/diary_entries_controller_test.rb @@ -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")