Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: previous and next archive links #2

Closed
paulrobertlloyd opened this issue Feb 5, 2014 · 9 comments
Closed

Feature request: previous and next archive links #2

paulrobertlloyd opened this issue Feb 5, 2014 · 9 comments
Milestone

Comments

@paulrobertlloyd
Copy link

Hello again,

Not sure if this is the right place to make feature request, but is it possible to extend this plugin so that archive pages can have links to their previous and next day/month/year? Or is there an easy way to do this with Jekyll/Liquid already without adapting this plugin?

(Forgive me, but I am new to Jekyll, and just learning how it all works and understanding what's possible. I also programme in so much as I copy and paste bits of code, cross my fingers and hoping that something works!)

Thanks!

Paul

@itafroma itafroma added this to the 0.2.0 milestone Feb 6, 2014
@itafroma
Copy link
Owner

itafroma commented Feb 6, 2014

This is definitely the right place for feature requests. You might be able to do something with Liquid tags: page.date.value has the archive page's date, which could then be manipulated by Liquid to produce the dates immediately preceding and following the archive page's date.

There are two problems with that, though:

  1. Date manipulation in Liquid is convoluted, to say the least: there is no built-in "add one day" filter. A quick search turned up templates that nightmares are made of.
  2. Even if you do add or subtract one day in your template, whether the previous or subsequent day's archive actually exists is not exposed. So you could very well be creating links that lead to 404s.

So I think there needs to be something exposed through this plugin. I'm thinking two new variables—page.archive.next and page.archive.previous—that contain the dates and urls for the next and previous archive pages in the stack. Then you'd be able to use {{ page.archive.next.url }} in your archive template.

Would that work? If so I'm going to shoot for getting it into the next feature release, 0.2.0.

@paulrobertlloyd
Copy link
Author

That sounds absolutely perfect, thanks again Mark!

itafroma added a commit that referenced this issue Feb 14, 2014
@itafroma
Copy link
Owner

Paging has now been added to the 0.2 branch of JAG.

Instead of the API I described earlier, I decided to use Jekyll's built-in paginator, so it works exactly as described on the Pagination doc page, with the exception that you do not need to do anything in your _config file: the paginator liquid object will automatically be available in any archive layout.

@paulrobertlloyd
Copy link
Author

Thanks for this Mark, JAG works really well! One thing I'm still trying to achieve however is being able to output the name of the next/previous page. Currently paginator.previous_page outputs a page number; how would I output archive names (i.e. ‘2012’, ‘January 2013’) within the paginator?

@itafroma
Copy link
Owner

paginator.posts contains the contents of every page in the archive type: you can use that to get information about the previous or next page:

{% assign previous_index = paginator.previous_page | minus: 1 %}
{{ paginator.posts[previous_index].title }}

N.B. you have to subtract one from paginator.previous_page because paginator.posts is zero-indexed. You'll need to do the same thing to paginator.next_page to get the next page's title:

{% assign next_index = paginator.next_page | minus: 1 %}
{{ paginator.posts[next_index].title }}

@paulrobertlloyd
Copy link
Author

Hmm, that doesn't seem to be working. Here's the code I'm currently using:

<main class="main" role="main">
    <header>
        <h1 class="section__title">{{ page.title }}</h1>

        <nav class="nav nav--pagination">
        {% if paginator.next_page %}
            {% assign next_index = paginator.next_page | minus: 1 %}
            <a rel="prev" href="{{ paginator.next_page_path }}">Next: {{ paginator.posts[next_index].title }}</a>
        {% endif %}
        {% if paginator.previous_page %}
            {% assign previous_index = paginator.previous_page | minus: 1 %}
            <a rel="next" href="{{ paginator.previous_page_path }}">Previous: {{ paginator.posts[previous_index].title }}</a>
        {% endif %}
        </nav>
    </header>

    <ul class="list">
    {% for post in page.archive.posts %}
        <li class="list__item">
            {% indent_include summary.html 12 %}
        </li>
    {% endfor %}
    </ul>
</main><!--/@main-->

Is this correct? I also wish to use URLs minus .html extension, so /2012/12/ instead of /2012/12/index.html. Both these use cases require getting the date of the previous/next archive page. Is that functionality available?

@itafroma
Copy link
Owner

That should be it: I copied and pasted your code into my own archive.html and the titles came through. Do the titles come through on any of the archive types (daily, monthly, yearly)? What happens if instead of {{ paginator.posts[next_index].title }} you use {{ paginator.posts[1].title }}?

For the URL issue, just use the remove filter to remove the index.html part:

{{ paginator.previous_page_path | remove: 'index.html' }}

@paulrobertlloyd
Copy link
Author

Turns out this value was being generated, but only on earlier archives. The information shown however was clearly wrong, leading me to file the latest bug report; the global value for pagination increments should probably not effect the pagination of archives.

@paulrobertlloyd
Copy link
Author

(Oh, and thanks for the .html removal tip!)

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants