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

Add proper support for sverrirs' Jekyll Paginate V2 plugin (excl. AutoPages) #2636

Merged
merged 9 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,33 @@ sass:

# Outputting
permalink: /:categories/:title/
timezone: # https://en.wikipedia.org/wiki/List_of_tz_database_time_zones


# Pagination with jekyll-paginate
paginate: 5 # amount of posts to show
paginate_path: /page:num/
timezone: # https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

# Pagination with jekyll-paginate-v2
# See https://github.com/sverrirs/jekyll-paginate-v2/blob/master/README-GENERATOR.md#site-configuration
# for configuration details
pagination:
# Set enabled to true to use paginate v2
# enabled: true
debug: false
collection: 'posts'
per_page: 10
permalink: '/page/:num/'
title: ':title - page :num'
limit: 0
sort_field: 'date'
sort_reverse: true
category: 'posts'
tag: ''
locale: ''
trail:
before: 2
after: 2


# Plugins (previously gems:)
Expand Down
70 changes: 70 additions & 0 deletions _includes/paginator-v1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{% if paginator.total_pages > 1 %}
<nav class="pagination">
{% assign paginate_path_last = site.paginate_path | split: '/' | last %}
{% assign first_page_path = paginator.first_page_path | default: site.paginate_path | replace: paginate_path_last, '' | replace: '//', '/' | relative_url %}
<ul>
{% comment %} Link for previous page {% endcomment %}
{% if paginator.previous_page %}
{% if paginator.previous_page == 1 %}
<li><a href="{{ first_page_path }}">{{ site.data.ui-text[site.locale].pagination_previous | default: "Previous" }}</a></li>
{% else %}
<li><a href="{{ site.paginate_path | replace: ':num', paginator.previous_page | replace: '//', '/' | relative_url }}">{{ site.data.ui-text[site.locale].pagination_previous | default: "Previous" }}</a></li>
{% endif %}
{% else %}
<li><a href="#" class="disabled"><span aria-hidden="true">{{ site.data.ui-text[site.locale].pagination_previous | default: "Previous" }}</span></a></li>
{% endif %}

{% comment %} First page {% endcomment %}
{% if paginator.page == 1 %}
<li><a href="#" class="disabled current">1</a></li>
{% else %}
<li><a href="{{ first_page_path }}">1</a></li>
{% endif %}

{% assign page_start = 2 %}
{% if paginator.page > 4 %}
{% assign page_start = paginator.page | minus: 2 %}
{% comment %} Ellipsis for truncated links {% endcomment %}
<li><a href="#" class="disabled">&hellip;</a></li>
{% endif %}

{% assign page_end = paginator.total_pages | minus: 1 %}
{% assign pages_to_end = paginator.total_pages | minus: paginator.page %}
{% if pages_to_end > 4 %}
{% assign page_end = paginator.page | plus: 2 %}
{% endif %}

{% for index in (page_start..page_end) %}
{% if index == paginator.page %}
<li><a href="{{ site.paginate_path | replace: ':num', index | replace: '//', '/' | relative_url }}" class="disabled current">{{ index }}</a></li>
{% else %}
{% comment %} Distance from current page and this link {% endcomment %}
{% assign dist = paginator.page | minus: index %}
{% if dist < 0 %}
{% comment %} Distance must be a positive value {% endcomment %}
{% assign dist = 0 | minus: dist %}
{% endif %}
<li><a href="{{ site.paginate_path | replace: ':num', index | relative_url }}">{{ index }}</a></li>
{% endif %}
{% endfor %}

{% comment %} Ellipsis for truncated links {% endcomment %}
{% if pages_to_end > 3 %}
<li><a href="#" class="disabled">&hellip;</a></li>
{% endif %}

{% if paginator.page == paginator.total_pages %}
<li><a href="#" class="disabled current">{{ paginator.page }}</a></li>
{% else %}
<li><a href="{{ site.paginate_path | replace: ':num', paginator.total_pages | replace: '//', '/' | relative_url }}">{{ paginator.total_pages }}</a></li>
{% endif %}

{% comment %} Link next page {% endcomment %}
{% if paginator.next_page %}
<li><a href="{{ site.paginate_path | replace: ':num', paginator.next_page | replace: '//', '/' | relative_url }}">{{ site.data.ui-text[site.locale].pagination_next | default: "Next" }}</a></li>
{% else %}
<li><a href="#" class="disabled"><span aria-hidden="true">{{ site.data.ui-text[site.locale].pagination_next | default: "Next" }}</span></a></li>
{% endif %}
</ul>
</nav>
{% endif %}
68 changes: 68 additions & 0 deletions _includes/paginator-v2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<nav class="pagination">
<ul>
{% comment %} Link for previous page {% endcomment %}
{% if paginator.previous_page %}
{% if paginator.previous_page == 1 %}
<li><a href="{{ paginator.first_page_path | relative_url }}">{{ site.data.ui-text[site.locale].pagination_previous | default: "Previous" }}</a></li>
{% else %}
<li><a href="{{ paginator.previous_page_path | relative_url }}">{{ site.data.ui-text[site.locale].pagination_previous | default: "Previous" }}</a></li>
{% endif %}
{% else %}
<li><a href="#" class="disabled"><span aria-hidden="true">{{ site.data.ui-text[site.locale].pagination_previous | default: "Previous" }}</span></a></li>
{% endif %}

{% comment %} Determine whether the first page and the last page are already included in trail {% endcomment %}
{% for trail in paginator.page_trail %}
{% if trail.num == paginator.first_page %}
{% assign has_first_page = true %}
{% elsif trail.num == paginator.last_page %}
{% assign has_last_page = true %}
{% endif %}
{% endfor %}

{% comment %} First page {% endcomment %}
{% unless has_first_page %}
{% if paginator.page == 1 %}
<li><a href="#" class="disabled current">1</a></li>
{% else %}
<li><a href="{{ paginator.first_page_path | relative_url }}">1</a></li>
{% endif %}
{% endunless %}

{% comment %} Ellipsis for truncated links {% endcomment %}
{% assign ellipsis_start = paginator.first_page | plus: 1 %}
{% if paginator.page_trail.first.num > ellipsis_start %}
<li><a href="#" class="disabled">&hellip;</a></li>
{% endif %}

{% comment %} Main pagination trail {% endcomment %}
{% for trail in paginator.page_trail %}
{% if paginator.page == trail.num %}
<li><a href="{{ trail.path | remove: 'index.html' | relative_url }}" class="disabled current">{{ trail.num }}</a></li>
{% else %}
<li><a href="{{ trail.path | remove: 'index.html' | relative_url }}">{{ trail.num }}</a></li>
{% endif %}
{% endfor %}

{% comment %} Ellipsis for truncated links {% endcomment %}
{% assign ellipsis_end = paginator.last_page | minus: 1 %}
{% if paginator.page_trail.last.num < ellipsis_end %}
<li><a href="#" class="disabled">&hellip;</a></li>
{% endif %}

{% unless has_last_page %}
{% if paginator.page == paginator.total_pages %}
<li><a href="#" class="disabled current">{{ paginator.page }}</a></li>
{% else %}
<li><a href="{{ paginator.last_page_path | remove: 'index.html' | relative_url }}">{{ paginator.total_pages }}</a></li>
{% endif %}
{% endunless %}

{% comment %} Link next page {% endcomment %}
{% if paginator.next_page %}
<li><a href="{{ paginator.next_page_path | remove: 'index.html' | relative_url }}">{{ site.data.ui-text[site.locale].pagination_next | default: "Next" }}</a></li>
{% else %}
<li><a href="#" class="disabled"><span aria-hidden="true">{{ site.data.ui-text[site.locale].pagination_next | default: "Next" }}</span></a></li>
{% endif %}
</ul>
</nav>
73 changes: 5 additions & 68 deletions _includes/paginator.html
Original file line number Diff line number Diff line change
@@ -1,70 +1,7 @@
{% if paginator.total_pages > 1 %}
<nav class="pagination">
{% assign paginate_path_last = site.paginate_path | split: '/' | last %}
{% assign first_page_path = paginator.first_page_path | default: site.paginate_path | replace: paginate_path_last, '' | replace: '//', '/' | relative_url %}
<ul>
{% comment %} Link for previous page {% endcomment %}
{% if paginator.previous_page %}
{% if paginator.previous_page == 1 %}
<li><a href="{{ first_page_path }}">{{ site.data.ui-text[site.locale].pagination_previous | default: "Previous" }}</a></li>
{% else %}
<li><a href="{{ site.paginate_path | replace: ':num', paginator.previous_page | replace: '//', '/' | relative_url }}">{{ site.data.ui-text[site.locale].pagination_previous | default: "Previous" }}</a></li>
{% endif %}
{% else %}
<li><a href="#" class="disabled"><span aria-hidden="true">{{ site.data.ui-text[site.locale].pagination_previous | default: "Previous" }}</span></a></li>
{% endif %}

{% comment %} First page {% endcomment %}
{% if paginator.page == 1 %}
<li><a href="#" class="disabled current">1</a></li>
{% else %}
<li><a href="{{ first_page_path }}">1</a></li>
{% endif %}

{% assign page_start = 2 %}
{% if paginator.page > 4 %}
{% assign page_start = paginator.page | minus: 2 %}
{% comment %} Ellipsis for truncated links {% endcomment %}
<li><a href="#" class="disabled">&hellip;</a></li>
{% endif %}

{% assign page_end = paginator.total_pages | minus: 1 %}
{% assign pages_to_end = paginator.total_pages | minus: paginator.page %}
{% if pages_to_end > 4 %}
{% assign page_end = paginator.page | plus: 2 %}
{% endif %}

{% for index in (page_start..page_end) %}
{% if index == paginator.page %}
<li><a href="{{ site.paginate_path | replace: ':num', index | replace: '//', '/' | relative_url }}" class="disabled current">{{ index }}</a></li>
{% else %}
{% comment %} Distance from current page and this link {% endcomment %}
{% assign dist = paginator.page | minus: index %}
{% if dist < 0 %}
{% comment %} Distance must be a positive value {% endcomment %}
{% assign dist = 0 | minus: dist %}
{% endif %}
<li><a href="{{ site.paginate_path | replace: ':num', index | relative_url }}">{{ index }}</a></li>
{% endif %}
{% endfor %}

{% comment %} Ellipsis for truncated links {% endcomment %}
{% if pages_to_end > 3 %}
<li><a href="#" class="disabled">&hellip;</a></li>
{% endif %}

{% if paginator.page == paginator.total_pages %}
<li><a href="#" class="disabled current">{{ paginator.page }}</a></li>
{% else %}
<li><a href="{{ site.paginate_path | replace: ':num', paginator.total_pages | replace: '//', '/' | relative_url }}">{{ paginator.total_pages }}</a></li>
{% endif %}

{% comment %} Link next page {% endcomment %}
{% if paginator.next_page %}
<li><a href="{{ site.paginate_path | replace: ':num', paginator.next_page | replace: '//', '/' | relative_url }}">{{ site.data.ui-text[site.locale].pagination_next | default: "Next" }}</a></li>
{% else %}
<li><a href="#" class="disabled"><span aria-hidden="true">{{ site.data.ui-text[site.locale].pagination_next | default: "Next" }}</span></a></li>
{% endif %}
</ul>
</nav>
{% if site.paginate %}
{% include paginator-v1.html %}
{% elsif site.pagination.enabled %}
{% include paginator-v2.html %}
{% endif %}
{% endif %}
65 changes: 46 additions & 19 deletions docs/_docs/05-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1008,45 +1008,72 @@ The paginator only works on files with name `index.html`. To use pagination in a
paginate_path: /recent/page:num/
```

**Please note:** When using Jekyll's default [pagination plugin](https://jekyllrb.com/docs/pagination/) `paginator.posts` can only be called once. If you're looking for something more powerful that can paginate category, tag, and collection pages, [**jekyll-paginate-v2**][jekyll-paginate-v2] is the way to go.
**Please note:** When using Jekyll's default [pagination plugin](https://jekyllrb.com/docs/pagination/) `paginator.posts` can only be called once. If you're looking for something more powerful that can paginate category, tag, and collection pages I suggest **[jekyll-paginate-v2][jekyll-paginate-v2]**.
{: .notice--info}

[jekyll-paginate-v2]: https://github.com/sverrirs/jekyll-paginate-v2

#### Using Jekyll Paginate V2
### Paginate V2

**Note:** Jekyll Paginate V2 is **not** available on GitHub Pages. You must build your site locally or with a CI service like [GitHub Actions][gh-pages-actions].
{: .notice--info}

[gh-pages-actions]: https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site#publishing-with-a-custom-github-actions-workflow

If you opt to use [Jekyll Paginate V2][jekyll-paginate-v2], remove `paginate` from `_config.yml` and add the following configuration to your `_config.yml`:
If you're using [Jekyll Paginate V2][jekyll-paginate-v2], you can enjoy its powerful features by removing `paginate` and `paginate_path` and adding the following configuration to your `_config.yml`:

```yaml
# Pagination with jekyll-paginate-v2
# See https://github.com/sverrirs/jekyll-paginate-v2/blob/master/README-GENERATOR.md#site-configuration
# for configuration details
pagination:
enabled: true
debug: false
collection: 'posts'
per_page: 10
permalink: '/page/:num/'
per_page: 5
permalink: '/page/:num/' # Pages are index.html inside this folder (default)
title: ':title - page :num'
limit: 0
sort_field: 'date'
sort_reverse: true
category: 'posts'
tag: ''
locale: ''
trail:
before: 2
after: 2
```

Minimal Mistakes will automatically pick up Jekyll Paginate V2 mode if it detects the `pagination.enabled` setting in `_config.yml`.
Then, create `/posts/index.html` with the following content:

While the plugin allows you to change the `indexpage` and the `extension` (which default to `index` and `html` respectively), Minimal Mistakes do not support non-default values for these settings, so you should keep them as-is.
```html
---
title: "Posts"
layout: home
permalink: /posts/
pagination:
enabled: true
---
```

Your posts will be paginated at `/posts/`, `/posts/page/2/` and `/posts/page/3/` etc.

Similarly, if you want to paginate a collection or a tag, you can create another `index.html` at an appropriate location, and add configuration to the `pagination` key in the front matter, like this:

```html
---
title: "Lovely pets"
layout: home
permalink: /pets/
pagination:
enabled: true
collection:
- cat
- dog
---
```

**Note:** There are two more configuration options from Jekyll Paginate V2 that this theme doesn't support yet. You should either leave them out or use their default values as shown below. Changing them may lead to unexpected results and you're on your own.

```yaml
pagination:

# Optional, the default file extension for generated pages (e.g html, json, xml).
# Internally this is set to html by default
extension: html

# Optional, the default name of the index file for generated pages (e.g. 'index.html')
# Without file extension
indexpage: 'index'
```

### Timezone

Expand Down
2 changes: 1 addition & 1 deletion docs/_docs/10-layouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ Then adjust the `paginate_path` in **_config.yml** to match.
paginate_path: /blog/page:num
```

**Note:** Jekyll can only paginate a single `index.html` file. If you'd like to paginate more pages (e.g. category indexes) you'll need the help of a custom plugin. For more pagination related settings check the [**Configuration**]({{ "/docs/configuration/#paginate" | relative_url }}) section.
**Note:** The default Jekyll Paginate plugin can only paginate a single `index.html` file. If you'd like to paginate more pages (e.g. category indexes) you'll need the help of a custom plugin. For more pagination-related settings check the [**Configuration**]({{ "/docs/configuration/#paginate" | relative_url }}) section, including settings for [Jekyll Paginate V2](https://github.com/sverrirs/jekyll-paginate-v2).
{: .notice--info}

**Note:** By default, documents are shown in a list view. To change to a grid view add `entries_layout: grid` to the page's front matter. To increase the width of the main container, giving more space to the grid items also add `classes: wide` to the home page's YAML Front Matter.
Expand Down