middleman / middleman-blog

Blog Engine Extension for Middleman
https://middlemanapp.com
MIT License
325 stars 179 forks source link

Paginating when posts have the same date #233

Closed SachaG closed 9 years ago

SachaG commented 9 years ago

I'm using middleman-blog for the various sections of an app's documentation.

It works well enough as long as I'm using the date to number each article (i.e. date: 0001/01/01, date: 0001/01/02, date: 0002/01/01, etc.).

But I have a section with a lot more articles, and rather than go through each one numbering them, I thought I'd give them all the same date and then let them be sorted alphabetically.

That doesn't seem to be how Middleman works though. Having multiple posts on the same exact date seems to completely break previous post/next post pagination.

Here's an example of the problem. Check out any article in the "Telescope Packages" section and try going back and forth with the pagination links:

https://telestatic-staging.herokuapp.com/docs/

Repo is here by the way: https://github.com/TelescopeJS/Telescope-Homepage/tree/newdoc

I guess my questions are: 1) is this the intended behavior for cases of conflicting dates and 2) are there any workarounds besides manually numbering each post with a different date?

tdreyno commented 9 years ago

Currently, the collections and pagination in middleman-blog are limited to sorting by date or not at all.

However, in v4, we have arbitrary collections and paginations. We're hoping to get a beta out this month, but I wouldn't recommend switching yet. I am going to post what the example code would look like:

articles = resources.select do |r|
  # Some test to make sure a resource is one you want in the collection
  # !r.data.title.empty?
  # r.source_file =~ /some_directory/
  # etc
end

articles.per_page(5) do |items, num, meta|
  paginated_path = "/docs/whatever/#{num}.html"

  proxy paginated_path, "/template_for_paginated_list.html", locals: {
    items: items,
    pagination: meta # These are variables for things like current page, total size, etc.
  }
end
SachaG commented 9 years ago

Sounds really cool! I'll just use dates for now and I'll switch to v4 when it's released. Thanks!

On Sat, Jan 3, 2015 at 2:50 AM, Thomas Reynolds notifications@github.com wrote:

Currently, the collections and pagination in middleman-blog are limited to sorting by date or not at all.

However, in v4, we have arbitrary collections and paginations. We're hoping to get a beta out this month, but I wouldn't recommend switching yet. I am going to post what the example code would look like:

articles = resources.select do |r|

Some test to make sure a resource is one you want in the collection

!r.data.title.empty?

r.source_file =~ /some_directory/

etc

end

articles.per_page(5) do |items, num, meta| paginated_path = "/docs/whatever/#{num}.html"

proxy paginated_path, "/template_for_paginated_list.html", locals: { items: items, pagination: meta # These are variables for things like current page, total size, etc. } end

— Reply to this email directly or view it on GitHub https://github.com/middleman/middleman-blog/issues/233#issuecomment-68546154 .