diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 9a12e5dbb..a75c1c25a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -146,6 +146,16 @@ module ApplicationHelper end end + if opts[:read_time] + result << tag(:meta, name: 'twitter:label1', value: I18n.t("reading_time")) + result << tag(:meta, name: 'twitter:data1', value: "#{opts[:read_time]} mins 🕑") + end + + if opts[:like_count] + result << tag(:meta, name: 'twitter:label2', value: I18n.t("likes")) + result << tag(:meta, name: 'twitter:data2', value: "#{opts[:like_count]} 💚") + end + result.join("\n") end diff --git a/app/views/topics/plain.html.erb b/app/views/topics/plain.html.erb index 61895ddd5..82da8dd74 100644 --- a/app/views/topics/plain.html.erb +++ b/app/views/topics/plain.html.erb @@ -3,7 +3,7 @@ <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title><%= @topic_view.topic.title %></title> - <%= raw crawlable_meta_data(title: @topic_view.title, description: @topic_view.summary, image: @topic_view.image_url) %> + <%= raw crawlable_meta_data(title: @topic_view.title, description: @topic_view.summary, image: @topic_view.image_url, read_time: @topic_view.read_time, like_count: @topic_view.like_count) %> </head> <body> <% @topic_view.posts.each do |post| %> diff --git a/app/views/topics/show.html.erb b/app/views/topics/show.html.erb index d08fca398..583a0d640 100644 --- a/app/views/topics/show.html.erb +++ b/app/views/topics/show.html.erb @@ -60,7 +60,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, image: @topic_view.image_url) %> + <%= raw crawlable_meta_data(title: @topic_view.title, description: @topic_view.summary, image: @topic_view.image_url, read_time: @topic_view.read_time, like_count: @topic_view.like_count) %> <% end %> <% content_for(:title) { "#{@topic_view.page_title}" } %> diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index c8f258de5..8bc6fded7 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -118,6 +118,9 @@ en: invalid_access: "You are not permitted to view the requested resource." read_only_mode_enabled: "The site is in read only mode. Interactions are disabled." + reading_time: "Reading time" + likes: "Likes" + too_many_replies: one: "We're sorry, but new users are temporarily limited to 1 reply in the same topic." other: "We're sorry, but new users are temporarily limited to %{count} replies in the same topic." diff --git a/lib/topic_view.rb b/lib/topic_view.rb index 5ff057dcc..9f9cfb41f 100644 --- a/lib/topic_view.rb +++ b/lib/topic_view.rb @@ -159,6 +159,16 @@ class TopicView (excerpt || "").gsub(/\n/, ' ').strip end + def read_time + return nil if @post_number.present? && @post_number.to_i != 1 # only show for topic URLs + (@topic.word_count/500).floor if @topic.word_count + end + + def like_count + return nil if @post_number.present? && @post_number.to_i != 1 # only show for topic URLs + @topic.like_count + end + def image_url @topic.image_url || SiteSetting.default_opengraph_image_url end