{%- endfor -%}
{% if include.paginator and include.paginator.total_pages > 1 %}
{%- if page.pagination.permalink -%}
{% assign page_permalink = page.pagination.permalink %}
{%- else -%}
{% assign page_permalink = site.pagination.permalink %}
{%- endif -%}
{%- comment -%}
#
# HACK: We need the paginator's base directory in order to provide
# page direct links. Unfortunately, there is no particularly easy
# way of working out the directory from the include.paginator. For example,
# `page.dir` could return '/blog/page2/' on the second paginator
# page, which is not the desired directory (we'd actually want
# '/blog/'). So generate here using a bit of a hack.
#
# * On the first page, generation from page.dir is valid.
# * On subsequent pages, work out the page-y portion of the URL and
# replace it.
#
{%- endcomment -%}
{%- if 1 == include.paginator.page -%}
{%- assign page_path_format = page.dir | append: page_permalink | replace: "//", "/" -%}
{%- else -%}
{%- assign current_page_subdirectory = page_permalink | replace: ':num', include.paginator.page -%}
{%- assign page_path_format = page.dir | remove_first: current_page_subdirectory | append: page_permalink -%}
{%- endif -%}