Add Eli5 tabbing logic (#77)
* Add tabs for chronological filtering * Add Algolia filtering * Fix infinity typo * Fix algolia index on tabbing * Add readable publish date across all posts * Add eli5 logic for tabbing
This commit is contained in:
parent
e1705ef9c0
commit
9354c8fd8b
2 changed files with 19 additions and 7 deletions
|
|
@ -171,6 +171,24 @@ class Article < ApplicationRecord
|
|||
|
||||
stories.pluck(:path, :title, :comments_count, :created_at)
|
||||
end
|
||||
|
||||
def self.active_eli5(time_ago)
|
||||
stories = where(published:true).
|
||||
tagged_with("explainlikeimfive")
|
||||
|
||||
if time_ago == "latest"
|
||||
stories = stories.order("published_at DESC").limit(3)
|
||||
elsif time_ago
|
||||
stories = stories.order("comments_count DESC").
|
||||
where("published_at > ?", time_ago).
|
||||
limit(6)
|
||||
else
|
||||
stories = stories.order("last_comment_at DESC").
|
||||
where("published_at > ?", 5.days.ago).
|
||||
limit(3)
|
||||
end
|
||||
stories.pluck(:path, :title, :comments_count, :created_at)
|
||||
end
|
||||
|
||||
def body_text
|
||||
ActionView::Base.full_sanitizer.sanitize(processed_html)[0..7000]
|
||||
|
|
|
|||
|
|
@ -146,13 +146,7 @@
|
|||
</header>
|
||||
<div class="widget-body">
|
||||
<div class="widget-link-list">
|
||||
<% Article.
|
||||
where(published:true).
|
||||
tagged_with("explainlikeimfive").
|
||||
order("last_comment_at DESC").
|
||||
where("published_at > ?", 5.days.ago).
|
||||
limit(3).
|
||||
pluck(:path,:title,:comments_count, :created_at).
|
||||
<% Article.active_eli5(Timeframer.new(params[:timeframe]).datetime).
|
||||
each do |plucked_article| %>
|
||||
<%= render "articles/widget_list_item", plucked_article: plucked_article, show_comment_count: true %>
|
||||
<% end %>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue