Pagination without Blog

Hey there,

i want to make a simple page with a bunch of definitions. As there a some hundred definitions i want to paginate the definition page. Is there a simple solution with the proxy method to achieve this?

I am very interested in this, tooā€¦ The items I would like to paginate are stored in a yaml array.

Could this be done with dynamic pages?

Hi @npostulart, @mkleywegt,

Yes, this can be done. If I can find the time, Iā€™ll try to put together an example for you.

Itā€™s definitely doable. The blog extension does pagination.

Hi @Aupajo,

an example for this would be awesome.

Seconded! This opens up a host of possibilities in my case.

I hear you :slight_smile: This is a popular request. I havenā€™t forgotten about this thread, Iā€™ve just been very busy this week.

Will make some time this weekend to put together a comprehensive example.

I tried to put together an example, but it quickly got out of hand. Thereā€™s enough complexity involved in pagination to warrant its own Middleman extension, so Iā€™m going to take a swing at putting one together. If I can get it done, I promise it will have a nicer API than the blog extension one.

Iā€™ve just released a Pagination extension:

https://github.com/Aupajo/middleman-pagination

Iā€™ve got more changes on the way, but if anyone wants to try it and give me feedback, that would be awesome!

@Aupajo,

Thank you very much for releasing the extension. Installation and initialization both were clearly documented and straightforward.

I cannot get my head around approaching the following scenario:

  • When utilizing the proxy method to dynamically generate pages, would you still be able to match the url or look for frontmatter? Looking at the source code, the extension traverses the sitemap to match (parts of) urls to the query

  • When the index page showing the pageable navigation is itself a dynamic page, would the pagination need to be passed into the template file in a local variable?

Appreciate any pointers you might have!

@mkleywegt, thanks for trying it out! I know thereā€™s some improvements I can make, so the more feedback the better.

When utilizing the proxy method to dynamically generate pages, would you still be able to match the url or look for frontmatter?

You can now! Iā€™ve just added support for this in response to your question. Make sure to run bundle update middleman-pagination to get the latest version (1.0.2) with these changes.

When the index page showing the pageable navigation is itself a dynamic page, would the pagination need to be passed into the template file in a local variable?

The extension will automatically add a pagination local variable to any page (proxied or otherwise) that is a pagination index.

@Aupajo, thatā€™s quick!

I gave it a try. I feel that I am one crucial step removed from getting it to work.

Background:

  • I list resources (patterns) that live in a yaml file. For the purpose of paginating them I gave them a route with the proxy method (ā€˜single patternā€™). The index files are also defined with a proxy route (ā€˜patternsā€™).

  • I have it set up so that the main route ^/patterns (which is the parent of the proxy routes ā€˜patternsā€™) transparently displays all its childrenā€™s listings (using the same template). Navigating from the parent to a child thus narrows down the list of resources.

Here are my findings:

  • Both frontmatter and matching the url result in the right index files being discovered by the extension (ā€˜Creating new resources for indexā€™). However, the frontmatter method fails for me. It doesnā€™t get to displaying a stack trace, simply showing ā€˜Page not foundā€™ instead. Directory indexes are activated, but disabling makes no difference. So working from the url method, the pagination gets displayed.

  • The pagination object is indeed passed on to the index. But in my case, it spits out the entire site map (<middleman::pagination::inpagecontext etc.>). It might not be able to work out the query, so it returns all the data. Subpages were not available as a result.

I have experimented with including a variable to the pageable directive, with no notable difference.

I also tried to activate pagination within the loop that defines the proxy. Middleman then reports it already activated pagination (as it tries to do it a couple of times), also without a notable difference.

@mkleywegt Hmm, thereā€™s quite a lot going on there. Would you be able to create an issue on the repo? I can work through it with you there (thereā€™s quite a few people subscribed to this thread). An example app would also be great too.

@Aupajo It is getting rather specific, I agree.

Here is the issue for anyone following this thread: Paginating with proxy routes.

1 Like

Iā€™m really impressed whatā€™s going on here and the plugin by @Aupajo is really nice but what I wanted to achieve is a pagination of definitions defined in a yaml file, not pages.

The idea is, I have hundreds of definitions in a yaml file in a structure like

- title: "Lorem Ipsum"
  definition: "Foo Bar"
- title: "Lorem Ipsum"
  definition: "Foo Bar"

that I would display. In order not to display all definitions on one page and let the user scroll all the way down I want to paginate the definitions and display only a few on each page. Another feature would be to do the pagination by the first letter of the title. So you get all definitions starting with ā€œAā€, ā€œBā€, ā€œCā€ and so on displayed on a single ā€œpageā€.

At least in the later case, where content rather then number of items, decides what goes on which page, I think youā€™d be better of using dynamic pages. They will also give the opportunity to set a heading and an url that reflects the content.

@npostulart Thanks! Iā€™ve actually been thinking about adding support for more general-purpose pagination, so you can iterate over any arbitrary set of objects. Thereā€™s already some abstractions to support this, I just need to take it a little further. Might take a look at it this week.

@npostulart Iā€™ve just released an update to Middleman Pagination that allows you to paginate data exactly as youā€™ve described. Try it out, let me know what you think.

If youā€™re already using Middleman Pagination, youā€™ll need to update it to version 1.1.0 by running bundle update.

@Aupajo Thatā€™s awesome. I will have a look at your code, maybe I can help you with the pagination.