Add publication date to medium liquid tag (#4961) (#5002) [deploy]

* Add publication date to medium liquid tag

* Add time tag to publication date and fix timezone issue
This commit is contained in:
John Curcio 2019-12-05 13:19:10 -03:00 committed by Ben Halpern
parent 193bbd7349
commit 02c2a0808f
4 changed files with 17 additions and 2 deletions

View file

@ -17,13 +17,24 @@ class MediumArticleRetrievalService
reading_time = page.at("meta[name='twitter:data1']")["value"]
author = page.at("meta[name='author']")["content"]
author_image = page.at("img[alt='#{author}']")["src"]
published_time = page.at("meta[property='article:published_time']")["content"]
{
title: title,
author: author,
author_image: author_image,
reading_time: reading_time,
published_time: published_time,
publication_date: publication_date(published_time),
url: url
}
end
private
def publication_date(published_time)
Time.zone.parse(published_time).strftime("%b %-d, %Y")
rescue ArgumentError, NoMethodError => e
Rails.logger.error("#{published_time} is not a valid date: #{e}")
end
end

View file

@ -1,13 +1,13 @@
<div class='ltag__link'>
<a href='<%= response[:url] %>' class='ltag__link__link'>
<div class='ltag__link__pic'>
<img src='<%= response[:author_image] %>' alt='<%= response[:author] %>'/>
<img src='<%= response[:author_image] %>' alt='<%= response[:author] %>' />
</div>
</a>
<a href='<%= response[:url] %>' class='ltag__link__link'>
<div class='ltag__link__content'>
<h2><%= response[:title] %></h2>
<h3><%= response[:author] %> ・ <%= response[:reading_time] %></h3>
<h3><%= response[:author] %> ・ <time datetime='<%= response[:published_time] %>'><%= response[:publication_date] %></time> ・ <%= response[:reading_time] %></h4>
<div class="ltag__link__servicename">
<img src="<%= asset_path("medium_icon.svg") %>" alt="Medium Logo" aria-label="Medium Logo" />
<%= ApplicationController.helpers.get_host_without_www response[:url] %>

View file

@ -13,6 +13,8 @@ RSpec.describe MediumTag, type: :liquid_tag do
author: "Edison",
author_image: "https://cdn-images-1.medium.com/fit/c/120/120/1*qFzi921ix0_kkrFMKYgELw.jpeg",
reading_time: "4 min read",
published_time: "2018-11-03T09:44:32.733Z",
publication_date: "Nov 3, 2018",
url: "https://medium.com/@edisonywh"
}
end

View file

@ -7,6 +7,8 @@ RSpec.describe MediumArticleRetrievalService, type: :service, vcr: {} do
author: "Edison Yap",
author_image: "https://miro.medium.com/fit/c/96/96/1*qFzi921ix0_kkrFMKYgELw.jpeg",
reading_time: "4 min read",
published_time: "2018-11-03T09:44:32.733Z",
publication_date: "Nov 3, 2018",
url: "https://medium.com/@edisonywh/my-ruby-journey-hooking-things-up-91d757e1c59c"
}
end