<% @page_title = @config.name %>

<% content_for :head do %>
  <%= spud_blog_rss_link %>
<% end %>

<% cache(cache_key_for_spud_collection(@posts, :cache_params => [:category_url_name, :archive_date, :page], :for_user => true)) do %>

  <div class="row">
    <div class="col-sm-12">
      <%= form_tag posts_path, :class => 'form-inline blog-filters' do %>
        <div class="form-group">
          <label>Category:</label>
          <%= spud_post_category_select %>
        </div>
        <div class="form-group">
          <label>Month:</label>
          <%= spud_post_archive_select %>
        </div>
        <input type="submit" value="Submit" class="btn btn-default" />
      <% end %>
    </div>
  </div>

  <div class="row">

    <div class="col-sm-8 blog-posts">
      <% if @posts.length > 0 %>
        <% @posts.includes(:categories, :author).each do |post| %>
          <% cache(post) do %>
            <div class="blog-post blog-post-partial">
              <h3 class="blog-post-title"><%= link_to post.title, post_path(post.url_name) %></h3>
              <h4 class="blog-post-author">Posted by <%= post.author_name %> on <%= post.display_date %></h4>
              <% if Spud::Blog.disqus_shortname %>
                <p><%= disqus_comment_count_for_post(post) %></p>
              <% end %>
              <div class="blog-post-content">
                <%= truncate_html post.content_processed.html_safe, :length => 250 %>
              </div>
            </div>
          <% end %>
        <% end %>
      <% else %>
        <p>No posts were found in this category</p>
      <% end %>
      <%= will_paginate @posts %>
    </div>

    <div class="col-sm-4 blog-recent-posts">
      <h3>Recent Posts</h3>
      <ul class="blog-recent-posts-list">
        <% SpudPost.for_blog(params[:blog_key]).recent_posts.each do |post| %>
          <li><%= link_to post.title, post_path(post.url_name) %></li>
        <% end %>
      </ul>
    </div>

  </div>

  <% if Spud::Blog.disqus_shortname %>
    <%= javascript_include_tag "//#{Spud::Blog.disqus_shortname}.disqus.com/count.js", :id => 'dsq-count-scr', :async => true %>
  <% end %>

<% end %>