middleman/middleman-blog — pull request #57 by rumpuslabs (2012-07-11 10:39:18+00:00)
Title: Index Pagination Extension

Expanding on @wagenet's code in #50, I have implemented a pagination extension that works with normal indexes, and calendar and tag indexes.

Setting `blog.paginate = true` will enable the pagination extension. Any template with `pageable: true` in the frontmatter will get pagination support. The `blog.per_page` option can be used to set the number of items per page, and the `blog.page_link` option can be used to customise the URL of the generated page files. These options can also be set in the template frontmatter.

The extension generates new resources for the 2nd and subsequent pages of the index, and makes the following variables available in all pages of the index:

paginate	True if pagination is enabled, allows templates to be used with and without pagination

page_number	The page number of the current index page, starting from 1.

num_pages	The total number of pages in this index. Used with the above for displaying "Page X of Y"

per_page	The number of items per page in this index.

page_start	Index into the article list for the first article on this page.

page_end	Index into the article list for the last article on this page.

next_page	The URL (href) for the next page of the index, or nil if there are no more pages.

prev_page	The URL (href) for the previous page of the index, or nil if this is the first page.

articles	The full list of articles in this index. Use `articles[page_start..page_end]` to get the articles for this page.

Note, this code depends on middleman/middleman#528 (or some other patch to fix the same issue).