docbrown/app/helpers/articles_helper.rb
Julianna Tetreault 849bb846ac
[15-Minute Fix] Sidebar Tags Show Relevant Posts on Homepage (#13326)
* Revert change to options hash within Articles::ActiveThreadsQuery#call
  - Reverts double splat change back to options hash
  - Reverts changes to active_threads_query_spec.rb options

* Adds another check for tags to Articles::ActiveThreadsQuery#call
  - Adds a .tags.present? check to #call
  - Removes redundant and broken relation from #call

* Reverts change to options hash within _sidebar_additional.html.erb

* Removes before block from active_threads_query_spec

* Moves tag filter before conditional in Articles::ActiveThreadsQuery#call
  - Adds before block back to active_threads_query_spec for proper
  testing of filtering of tags within spec

* Adjust options to use new kwargs in Articles::ActiveThreadsQuery
  - Adjust active_threads_query_spec to use new args
  - Remove useless code from Articles::ActiveThreadsQuery

* Adjust published_at in else block
2021-04-09 10:40:09 -06:00

63 lines
1.8 KiB
Ruby

module ArticlesHelper
DASHBOARD_POSTS_SORT_OPTIONS = [
["Recently Created", "creation-desc"],
["Recently Published", "published-desc"],
["Most Views", "views-desc"],
["Most Reactions", "reactions-desc"],
["Most Comments", "comments-desc"],
].freeze
def sort_options
DASHBOARD_POSTS_SORT_OPTIONS
end
def has_vid?(article)
return if article.processed_html.blank?
article.processed_html.include?("youtube.com/embed/") ||
article.processed_html.include?("player.vimeo.com") ||
article.processed_html.include?("clips.twitch.tv/embed") ||
article.comments_blob.include?("youtube")
end
def image_tag_or_inline_svg_tag(service_name, width: nil, height: nil)
name = "#{service_name}-logo.svg"
if internal_navigation?
image_tag(name, class: "icon-img", alt: "#{service_name} logo", width: width, height: height)
else
inline_svg_tag(name, class: "icon-img", aria: true, title: "#{service_name} logo", width: width, height: height)
end
end
def should_show_updated_on?(article)
article.edited_at &&
article.published &&
!article.published_from_feed &&
article.published_at.next_day < article.edited_at
end
def should_show_crossposted_on?(article)
article.canonical_url ||
(article.crossposted_at &&
article.published_from_feed &&
article.published &&
article.published_at &&
article.feed_source_url.present?)
end
def get_host_without_www(url)
url = "http://#{url}" if URI.parse(url).scheme.nil?
host = URI.parse(url).host.downcase
host.gsub!("medium.com", "Medium")
host.delete_prefix("www.")
end
def utc_iso_timestamp(timestamp)
timestamp&.utc&.iso8601
end
def active_threads(...)
Articles::ActiveThreadsQuery.call(...)
end
end