Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pagination to blog #296

Merged
merged 1 commit into from
Mar 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@
page '/guides/*'
end

with_layout :blog do
page '/blog/*'
end

###
# Helpers
###
Expand All @@ -46,6 +42,9 @@
activate :blog do |blog|
blog.prefix = 'blog'
blog.permalink = '{year}/{month}/{day}/{title}.html'
blog.layout = :blog
blog.paginate = true
blog.per_page = 5
end

# Automatic image dimensions on image_tag helper
Expand Down
27 changes: 26 additions & 1 deletion source/blog.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Blog
pageable: true
---
<div class="container container-blog">
<div class="block block-inverse text-center">
Expand All @@ -11,7 +12,7 @@ title: Blog
</div>
</div>

<% articles.each do |article| %>
<% page_articles.each do |article| %>
<div class="row">
<div class="col-xs-12 col-md-10 col-md-offset-1">
<h2><%= link_to article_title(article), article %></h2>
Expand All @@ -23,4 +24,28 @@ title: Blog
</div>
</div>
<% end %>

<% if paginate %>
<div class="col-xs-12 col-md-10 col-md-offset-1">
<ul class="pager">
<% prev_title = "&larr; Previous" %>
<% next_title = "Next &rarr;" %>

<li class="<%= prev_page.nil? && 'disabled' %>">
<% if prev_page %>
<a href="<%= prev_page.url %>"><%= prev_title %></a>
<% else %>
<span><%= prev_title %></span>
<% end %>
</li>
<li class="<%= next_page.nil? && 'disabled' %>">
<% if next_page %>
<a href="<%= next_page.url %>"><%= next_title %></a>
<% else %>
<span><%= next_title %></span>
<% end %>
</li>
</ul>
</div>
<% end%>
</div>