Module: Panda::CMS::PostsHelper

Defined in:
app/helpers/panda/cms/posts_helper.rb

Instance Method Summary collapse

Instance Method Details

#display_post_path(post) ⇒ Object



6
7
8
9
# File 'app/helpers/panda/cms/posts_helper.rb', line 6

def display_post_path(post)
  # Unescape the path for display purposes
  CGI.unescape(post.slug)
end

#posts_months_menuObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/helpers/panda/cms/posts_helper.rb', line 11

def posts_months_menu
  Rails.cache.fetch("panda_cms_posts_months_menu", expires_in: 1.hour) do
    Panda::CMS::Post
      .where(status: :active)
      .select(
        Arel.sql("DATE_TRUNC('month', published_at) as month"),
        Arel.sql("COUNT(*) as post_count")
      )
      .group(Arel.sql("DATE_TRUNC('month', published_at)"))
      .order(Arel.sql("DATE_TRUNC('month', published_at) DESC"))
      .map do |result|
        date = result.month
        {
          year: date.strftime("%Y"),
          month: date.strftime("%m"),
          month_name: "#{date.strftime("%B")} #{date.year}",
          post_count: result.post_count
        }
      end
  end
end