octopress / paginate

A simple paginator for Jekyll sites.
MIT License
105 stars 37 forks source link

Issue with Reversed Pagination {% for page paginator.collection_name reversed %} #11

Closed ericvida closed 8 years ago

ericvida commented 9 years ago

Maybe there's a proper way of doing this with octopress-paginate that's not yet documented, but so far I'm just trying use octopress-paginate as I would use the "reverse" feature of jekyll's pagination.

Pagination reverse is really important, because for most types of blogging or content sharing, the latest products, news, and posts are the most relevant and should display first on a list.

What Should Happen

Reversed pagination generates the latest content to appear as first on a stack list rather than last. When pagination splits content into multiple pages.

Let's say my page is set to paginate 5 items per page, and I have a total of 10 items, it should look like this:

Page1: [Item 1, 2, 3, 4, 5] Page2: [Item 6, 7, 8, 9, 10]

With pagination reversed, it should look like this: Page1: [Item 10, 9, 8, 7, 6] Page2: [Item 5, 4, 3, 2, 1]

But with octopress-paginate, "reverse" happens like this: Page1: [Item 5, 4, 3, 2, 1] Page2: [Item 10, 9, 8, 7, 6]

What Actually Happens

It seems like it brakes them up into pages before reversing the other, so the first 5 posts are still on the first page, but reversed in order, and the latest 5 posts are still in the 2nd page.

Example Code

Here's an example of my reversed paginated collection loop.


---
layout: page
title: "page-title"
permalink: /pagename/
paginate:
  collection: name
  per_page: 5

---

<ul >
    {% for name in paginator.collection_name reversed %}
        <li >
            <div >
                <img src="{% if site.baseurl %}{{ site.baseurl }}{% endif %}/img/name/{{ name.image }}">
            </div>
            <div>
                <a href="{{ name.url | prepend: site.baseurl }}">{{ hoy.title }}</a>
                <p>{{ name.content  | strip_html | truncatewords:10 }}</p>
                <div >
                    <a href="{% if site.baseurl %}{{ site.baseurl }}{% endif %}/img/name/pdf/{{ file.pdf }}">DOWNLOAD</a>
                </div>
            </div>
        </li>
    {% endfor %}
</ul>
I can't wait to learn how to fix these issues myself, make pull requests and help you guys out.
shawnthroop commented 9 years ago

I managed to reverse the posts in a collection by changing line 139 in octopress-paginate.rb to read:

page.site.collections[page['paginate']['collection']].docs.reverse

Maybe add a reverse: false to the DEFAULT yaml front matter dictionary so one could presumably override it on a per page basis. Then on line 142 insert something like this:

if page.data['paginate']['reverse'] == true
    collection = collection.reverse
end

PS. I've never written ruby in my life so I have no idea if that works

ericvida commented 9 years ago

That sounds awesome shawn. So How do I implement this? I'm not too ruby savvy yet.

shawnthroop commented 8 years ago

I forked paginate and added what I mentioned above to octopress-paginate.rb. Specifically line 16 and more lines starting at 143. This was just a little causal hacking, be aware that this might break other things. I have submitted a pull request.

ChrisChinchilla commented 8 years ago

@shawnthroop @iamtirado Has this been merged at all? Any testing needed to get it merged?

ericvida commented 8 years ago

@imathis Have you been able to look into this yet? Shawnthroop's pull request looks like it works.It'd be helpful to me right now. I built a site for work which has been live for almost a year now and this is the only feature I'm waiting to activate.

mlibre commented 8 years ago

Thanks @shawnthroop. I do it. and it works. So file in Linux located somewhere like here: /usr/local/lib/ruby/gems/2.3.0/gems/octopress-paginate-1.1.2/lib/octopress-paginate.rb And here what i do:

And inindex.html's liquid, don't use reversed in for loop. write for loop like this: {% for post in paginator.Posts_en %}

XhmikosR commented 8 years ago

@parkr: this should be fixed by #12.