* flare tag line height * . * init * widgets * widgets lists * new tabs on home * instantclick * . * rethinking css * . * . * empty space * init * campaign widget * . * merge * . * update layout * fix sidebars on home page * . * fix onboarding x * test * spec * test * toolbar fix * more * test * better handling ads * . * spec * card border * . * . * actions bar * cleanup * animation * test * button width * . * better responsiveness and author boxes * meta info * padding * better animation * optimize videos * fixes * spec * . * codeblocks in comments * whoops * Use .present? correctly as it preloads items * sticky nav * Update app/views/articles/_sticky_nav.html.erb I don't know what I'm doing but @benhalpern says so!e8c0f337a5 (r440248874)Co-authored-by: Ben Halpern <bendhalpern@gmail.com> * Update app/views/articles/show.html.erb I don't know what I'm doing but @benhalpern says so!e8c0f337a5 (r440247802)Co-authored-by: Ben Halpern <bendhalpern@gmail.com> * little fixes * Update app/assets/stylesheets/article-show.scss Co-authored-by: Ben Halpern <bendhalpern@gmail.com> * pawel updating ruby code...... * actually better merge * semantic updates * . Co-authored-by: rhymes <rhymesete@gmail.com> Co-authored-by: Ben Halpern <bendhalpern@gmail.com>
48 lines
1.5 KiB
Ruby
48 lines
1.5 KiB
Ruby
class StickyArticleCollection
|
|
attr_accessor :article, :author, :reaction_count_num, :comment_count_num
|
|
|
|
def initialize(article, author)
|
|
@article = article
|
|
@author = author
|
|
@reaction_count_num = Rails.env.production? ? 15 : -1
|
|
@comment_count_num = Rails.env.production? ? 7 : -2
|
|
end
|
|
|
|
def user_stickies
|
|
author.articles.published.
|
|
limited_column_select.
|
|
tagged_with(article_tags, any: true).
|
|
where.not(id: article.id).order("published_at DESC").
|
|
limit(3)
|
|
end
|
|
|
|
def suggested_stickies
|
|
(tag_articles.load + more_articles).sample(3)
|
|
end
|
|
|
|
def tag_articles
|
|
@tag_articles ||= Article.published.tagged_with(article_tags, any: true).
|
|
includes(:user).
|
|
where("public_reactions_count > ? OR comments_count > ?", reaction_count_num, comment_count_num).
|
|
where.not(id: article.id).where.not(user_id: article.user_id).
|
|
where("featured_number > ?", 5.days.ago.to_i).
|
|
order(Arel.sql("RANDOM()")).
|
|
limit(3)
|
|
end
|
|
|
|
def more_articles
|
|
return [] if tag_articles.size > 6
|
|
|
|
Article.published.tagged_with(%w[career productivity discuss explainlikeimfive], any: true).
|
|
includes(:user).
|
|
where("comments_count > ?", comment_count_num).
|
|
where.not(id: article.id).where.not(user_id: article.user_id).
|
|
where("featured_number > ?", 5.days.ago.to_i).
|
|
order(Arel.sql("RANDOM()")).
|
|
limit(10 - tag_articles.size)
|
|
end
|
|
|
|
def article_tags
|
|
@article_tags ||= article.cached_tag_list_array - ["discuss"]
|
|
end
|
|
end
|