From: Anton Khorev Date: Wed, 14 Aug 2024 14:59:00 +0000 (+0300) Subject: Add article:published_time meta tag to diary entries X-Git-Tag: live~239^2 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/09721c6feeb2e6f26fae5c220e4f4b9e83cbaebc?ds=sidebyside Add article:published_time meta tag to diary entries --- diff --git a/app/controllers/diary_entries_controller.rb b/app/controllers/diary_entries_controller.rb index a8fc41808..dd7efc7ca 100644 --- a/app/controllers/diary_entries_controller.rb +++ b/app/controllers/diary_entries_controller.rb @@ -71,7 +71,8 @@ class DiaryEntriesController < ApplicationController @opengraph_properties = { "og:image" => @entry.body.image, "og:image:alt" => @entry.body.image_alt, - "og:description" => @entry.body.description + "og:description" => @entry.body.description, + "article:published_time" => @entry.created_at.xmlschema } @comments = can?(:unhide, DiaryComment) ? @entry.comments : @entry.visible_comments else diff --git a/app/helpers/open_graph_helper.rb b/app/helpers/open_graph_helper.rb index b3f0ab928..cde848e5d 100644 --- a/app/helpers/open_graph_helper.rb +++ b/app/helpers/open_graph_helper.rb @@ -10,6 +10,8 @@ module OpenGraphHelper "og:description" => properties["og:description"] || t("layouts.intro_text") }.merge( opengraph_image_properties(properties) + ).merge( + properties.slice("article:published_time") ) safe_join(tags.map do |property, content| diff --git a/test/controllers/diary_entries_controller_test.rb b/test/controllers/diary_entries_controller_test.rb index e98342e10..aad759b5b 100644 --- a/test/controllers/diary_entries_controller_test.rb +++ b/test/controllers/diary_entries_controller_test.rb @@ -766,6 +766,17 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest end end + def test_show_article_published_time + user = create(:user) + diary_entry = create(:diary_entry, :user => user, :created_at => "2020-03-04") + + get diary_entry_path(user, diary_entry) + assert_response :success + assert_dom "head meta[property='article:published_time']" do + assert_dom "> @content", "2020-03-04T00:00:00Z" + end + end + def test_hide user = create(:user) diary_entry = create(:diary_entry, :user => user)