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

Paginator does not represent the pages of the index itself #761

Open
proegssilb opened this issue May 10, 2020 · 1 comment
Open

Paginator does not represent the pages of the index itself #761

proegssilb opened this issue May 10, 2020 · 1 comment
Labels
enhancement Improve the expected

Comments

@proegssilb
Copy link

While the paginator in cobalt has support for next/prev and first/last, it doesn't know what the URLs are for other pages in the current index. This means bootstrap's default paginator, which leans heavily on clickable links for specific page numbers, requires manually figuring out the URLs that a specific page number should link to. This is fine while the paginator is restricted to not being used in layouts, but as soon as there's potential for the frontmatter to be separated from the paginator, or for the paginator to be used in layouts, this is going to be a bigger problem.

The minimum solution would be a field on the paginator that listed all the URLs for each page generated by the current index ("index-page"). A more sophisticated solution would make it possible to access the full frontmatter for each index-page

Here's an example of my workaround:

---
layout: page.liquid
permalink: /blog/archive.html
pagination:
  include: All
  per_page: 1
  permalink_suffix: "./{{ num }}/"
  order: Desc
  sort_by: ["published_date"]
  date_index: ["Year", "Month"]
---
    <nav aria-label="Page navigation">
      {% assign startIndex = paginator.index | minus: 2 | at_least: 1 %}
      {% assign currIndex  = paginator.index %}
      {% assign endIndex   = paginator.index | plus: 2 | at_most: paginator.total_indexes %}
      <ul class="pagination pagination-sm">
        {% if paginator.previous_index %}
        <li class="page-item">
          <a class="page-link" href="{{ site.base_url }}/{{ paginator.previous_index_permalink }}" aria-label="Previous">
            <span aria-hidden="true">&laquo;</span>
          </a>
        </li>
        {% endif %}

        {% for pgIndex in (startIndex..endIndex) %}
          <li class="page-item">
            {% if pgIndex == currIndex %}
              <a class="page-link" href="{{ site.base_url }}/{{ paginator.index_permalink }}">{{ paginator.index }}</a>
            {% elsif pgIndex == 1 %}
              <a class="page-link" href="{{site.base_url}}/blog/archive.html">{{ pgIndex }}</a>
            {% else %}
              <a class="page-link" href="{{ site.base_url }}/blog/archive/all/{{ pgIndex }}">{{ pgIndex }}</a>
            {% endif %}
          </li>
        {% endfor %}

        {% if paginator.next_index %}
        <li class="page-item">
          <a class="page-link" href="{{ site.base_url }}/{{ paginator.next_index_permalink }}" aria-label="Next">
            <span aria-hidden="true">&raquo;</span>
          </a>
        </li>
        {% endif %}
      </ul>
    </nav>
@Geobert
Copy link
Contributor

Geobert commented May 10, 2020

This is called pagination trail and is managed like this in jekyll pagination v2 for example:
https://github.com/sverrirs/jekyll-paginate-v2/blob/master/README-GENERATOR.md#creating-pagination-trails

My proposition is to implement this new trail field.

indexes is intended for "meta paginator" in the case of indexing on tags/categories/dates: 
each paginator in indexes is the access to the paginator of each tags

@epage epage added the enhancement Improve the expected label May 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improve the expected
Projects
None yet
Development

No branches or pull requests

3 participants