Skip to content

Commit

Permalink
Pagination now works for index.html files in subfolders. Links to nex…
Browse files Browse the repository at this point in the history
…t page consider baseurl now. (mmistakes#764)
  • Loading branch information
RobinYu committed Mar 7, 2017
1 parent 84cc1a1 commit b069270
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 30 deletions.
12 changes: 5 additions & 7 deletions _includes/page__hero.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
{% include base_path %}

{% if page.header.image contains "://" %}
{% capture img_path %}{{ page.header.image }}{% endcapture %}
{% else %}
{% capture img_path %}{{ page.header.image | prepend: "/images/" | prepend: base_path }}{% endcapture %}
{% capture img_path %}{{ page.header.image | absolute_url }}{% endcapture %}
{% endif %}

{% if page.header.cta_url contains "://" %}
{% capture cta_path %}{{ page.header.cta_url }}{% endcapture %}
{% else %}
{% capture cta_path %}{{ page.header.cta_url | prepend: base_path }}{% endcapture %}
{% capture cta_path %}{{ page.header.cta_url | absolute_url }}{% endcapture %}
{% endif %}

{% if page.header.overlay_image contains "://" %}
{% capture overlay_img_path %}{{ page.header.overlay_image }}{% endcapture %}
{% elsif page.header.overlay_image %}
{% capture overlay_img_path %}{{ page.header.overlay_image | prepend: "/images/" | prepend: base_path }}{% endcapture %}
{% capture overlay_img_path %}{{ page.header.overlay_image | absolute_url }}{% endcapture %}
{% endif %}

{% if page.header.overlay_filter contains "rgba" %}
Expand All @@ -30,7 +28,7 @@
{% if page.header.overlay_color or page.header.overlay_image %}
<div class="wrapper">
<h1 class="page__title" itemprop="headline">
{% if paginator %}
{% if paginator and site.paginate_show_page_num %}
{{ site.title }}{% unless paginator.page == 1 %} {{ site.data.ui-text[site.locale].page | default: "Page" }} {{ paginator.page }}{% endunless %}
{% else %}
{{ page.title | default: site.title | markdownify | remove: "<p>" | remove: "</p>" }}
Expand All @@ -52,4 +50,4 @@ <h1 class="page__title" itemprop="headline">
{% if page.header.caption %}
<span class="page__hero-caption">{{ page.header.caption | markdownify | remove: "<p>" | remove: "</p>" }}</span>
{% endif %}
</div>
</div>
80 changes: 57 additions & 23 deletions _includes/paginator.html
Original file line number Diff line number Diff line change
@@ -1,35 +1,69 @@
{% if paginator.total_pages > 1 %}
<nav class="pagination">
{% assign first_page_path = site.paginate_path | replace: 'page:num', '' | replace: '//', '/' | absolute_url %}
<ul>
{% comment %} Link for previous page {% endcomment %} {% if paginator.previous_page %} {% if paginator.previous_page == 1 %}
<li><a href="{{ '/' | absolute_url }}">{{ site.data.ui-text[site.locale].pagination_previous | default: "Previous" }}</a></li>
{% 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: '//', '/' | absolute_url }}">{{ site.data.ui-text[site.locale].pagination_previous | default: "Previous" }}</a></li>
{% endif %}
{% else %}
<li><a href="{{ '/page' | absolute_url }}{{ paginator.previous_page | append: '/' }}">{{ 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>
{% endif %}

{% comment %} First page {% endcomment %}
{% if paginator.page == 1 %}
<li><a href="#" class="disabled current">1</a></li>
{% else %}
<li><a href="{{ '/' | absolute_url }}">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="{{ '/page' | absolute_url }}{{ index | append: '/' }}" 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="{{ '/page' | absolute_url }}{{ index | append: '/' }}">{{ index }}</a></li>
{% endif %} {% endfor %} {% comment %} Ellipsis for truncated links {% endcomment %} {% if pages_to_end > 3 %}
<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 %} {% if paginator.page == paginator.total_pages %}
<li><a href="#" class="disabled current">{{ paginator.page }}</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: '//', '/' | absolute_url }}" class="disabled current">{{ index }}</a></li>
{% else %}
<li><a href="{{ '/page' | absolute_url }}{{ paginator.total_pages }}/">{{ paginator.total_pages }}</a></li>
{% endif %} {% comment %} Link next page {% endcomment %} {% if paginator.next_page %}
<li><a href="{{ '/page' | absolute_url }}{{ paginator.next_page }}/">{{ 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>
{% 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 | absolute_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: '//', '/' | absolute_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: '//', '/' | absolute_url }}">{{ site.data.ui-text[site.locale].pagination_next | default: "Next" }}</a></li></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 %}

0 comments on commit b069270

Please sign in to comment.