From dfcb2a0d42d1a34733d46037c4dc86611c79b48b Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Mon, 30 Jul 2018 16:22:51 +0530 Subject: [PATCH] FEATURE: include published_time in metadata --- app/helpers/application_helper.rb | 4 ++++ app/views/topics/plain.html.erb | 2 +- app/views/topics/show.html.erb | 2 +- lib/topic_view.rb | 5 +++++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 098d540a0de..90d148be7f3 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -237,6 +237,10 @@ module ApplicationHelper result << tag(:meta, name: 'twitter:data2', value: "#{opts[:like_count]} ❤") end + if opts[:published_time] + result << tag(:meta, property: 'article:published_time', content: opts[:published_time]) + end + if opts[:ignore_canonical] result << tag(:meta, property: 'og:ignore_canonical', content: true) end diff --git a/app/views/topics/plain.html.erb b/app/views/topics/plain.html.erb index 7e7e31bd027..52d6d5cbdbc 100644 --- a/app/views/topics/plain.html.erb +++ b/app/views/topics/plain.html.erb @@ -3,7 +3,7 @@ <%= @topic_view.topic.title %> - <%= raw crawlable_meta_data(title: @topic_view.title, description: @topic_view.summary(strip_images: true), image: @topic_view.image_url, read_time: @topic_view.read_time, like_count: @topic_view.like_count) %> + <%= raw crawlable_meta_data(title: @topic_view.title, description: @topic_view.summary(strip_images: true), image: @topic_view.image_url, read_time: @topic_view.read_time, like_count: @topic_view.like_count, published_time: @topic_view.published_time) %> <% if @topic_view.prev_page %> <% end %> diff --git a/app/views/topics/show.html.erb b/app/views/topics/show.html.erb index c67fd23ecf6..21788d3b77e 100644 --- a/app/views/topics/show.html.erb +++ b/app/views/topics/show.html.erb @@ -88,7 +88,7 @@ <% content_for :head do %> <%= auto_discovery_link_tag(@topic_view, {action: :feed, slug: @topic_view.topic.slug, topic_id: @topic_view.topic.id}, title: t('rss_posts_in_topic', topic: @topic_view.title), type: 'application/rss+xml') %> - <%= raw crawlable_meta_data(title: @topic_view.title, description: @topic_view.summary(strip_images: true), image: @topic_view.image_url, read_time: @topic_view.read_time, like_count: @topic_view.like_count, ignore_canonical: true) %> + <%= raw crawlable_meta_data(title: @topic_view.title, description: @topic_view.summary(strip_images: true), image: @topic_view.image_url, read_time: @topic_view.read_time, like_count: @topic_view.like_count, ignore_canonical: true, published_time: @topic_view.published_time) %> <% if @topic_view.prev_page || @topic_view.next_page %> <% if @topic_view.prev_page %> diff --git a/lib/topic_view.rb b/lib/topic_view.rb index f794e9477c9..625c9ef4337 100644 --- a/lib/topic_view.rb +++ b/lib/topic_view.rb @@ -193,6 +193,11 @@ class TopicView @topic.like_count end + def published_time + return nil if desired_post.blank? + desired_post.created_at.strftime('%FT%T%:z') + end + def image_url if @post_number > 1 && @desired_post.present? if @desired_post.image_url.present?