]> git.openstreetmap.org Git - rails.git/commitdiff
Add article:published_time meta tag to diary entries
authorAnton Khorev <tony29@yandex.ru>
Wed, 14 Aug 2024 14:59:00 +0000 (17:59 +0300)
committerAnton Khorev <tony29@yandex.ru>
Wed, 14 Aug 2024 15:00:14 +0000 (18:00 +0300)
app/controllers/diary_entries_controller.rb
app/helpers/open_graph_helper.rb
test/controllers/diary_entries_controller_test.rb

index a8fc4180835d881745108263787d62d12faf7af4..dd7efc7cacf3c359e21a28d32aed1b19357b6674 100644 (file)
@@ -71,7 +71,8 @@ class DiaryEntriesController < ApplicationController
       @opengraph_properties = {
         "og:image" => @entry.body.image,
         "og:image:alt" => @entry.body.image_alt,
       @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
       }
       @comments = can?(:unhide, DiaryComment) ? @entry.comments : @entry.visible_comments
     else
index b3f0ab92849e81be230992c0e3ff1f524258cc64..cde848e5d13762ac718431632aaf44c597c3bf54 100644 (file)
@@ -10,6 +10,8 @@ module OpenGraphHelper
       "og:description" => properties["og:description"] || t("layouts.intro_text")
     }.merge(
       opengraph_image_properties(properties)
       "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|
     )
 
     safe_join(tags.map do |property, content|
index e98342e10a041d04cec90f4a05810a8ec63e23d7..aad759b5b68e3ebae15e20e60df50b27cf30814f 100644 (file)
@@ -766,6 +766,17 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest
     end
   end
 
     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)
   def test_hide
     user = create(:user)
     diary_entry = create(:diary_entry, :user => user)