I encountered this problem myself and overcame it by using dynamic pages. I’ve so far come up with the following code to help solve the problem. I’m sure there is room for improvement in it, but it will give you an idea.
# In config.rb
def get_locals(category, total_pages, i, articles)
prev_page = false
# Is the a previous page and if so what does it look like
if (i - 1) == 1
prev_page = "/categories/#{category}"
elsif (i - 1) > 1
prev_page = "/categories/#{category}/p/#{i-1}"
end
# Return the local variables
{
:page_articles => articles,
:paginate => total_pages > 1,
:category => category,
:page_number => i,
:num_pages => total_pages,
:next_page => if (i + 1) <= total_pages then "/categories/#{category}/p/#{i+1}" else false end,
:prev_page => prev_page
}
end
ready do
per_page = 5 #Set the number of posts per page here
# Loop through all articles and group them by category and then loop through each group
blog.articles.group_by {|a| a.data.category }.each do |category, articles|
total_pages = articles.size.fdiv(per_page).ceil # Calculate the numer of pages
page_articles = articles.slice(0, per_page) # Get the articles for the page
# Create a proxy for the main/first category page
proxy "/categories/#{category}", "/category.html", :locals => get_locals(category, total_pages, 1, page_articles)
# Create pages for each of the pagination
(1..total_pages).each do |i|
page_articles = articles.slice((i - 1) * per_page, per_page)
proxy "/categories/#{category}/p/#{i}", "/category.html", :locals => get_locals(category, total_pages, i, page_articles)
end
end
end
You may want to customise the links, something to note is the style I’ve used is sensitive to the presence of trailing slashes.