Jekyll paginate blog as a subdirectory

I am using Jekyll for a static site and I am trying to create a blog as a subdirectory / subfolder:

http://example.com/blog

In the directory structure, before running jekyll, this is blog / index.html.

I tried adding pagination by adding "paginate: 5" to _config.yml, but the generated url looked like:

http://example.com/page2/

i.e. no "/ blog". This is fixed:

paginate_path: / blog / page /: num

in _config.yml.

But the resulting generated pages:

http://example.com/blog/page/2/

do not use blog / index.html as your layout. They use the root index.html. What is the point even with the paginate_path parameter, then?

How do I get my blog at example.com/blog paginated using Jekyll?

+2
2

destination _config.yml, , . ,

paginate: 5
destination: _site/blog

, (, http://example.com/ ") " _site "jekyll " index.html " . , jekyll, " ", , .

+4

, , n- , .

_includes/custom/ pagination. ,

<!-- This loops through the paginated posts -->
{% for post in paginator.posts %}
  <h1><a href="{{ post.url }}">{{ post.title }}</a></h1>
  <p class="author">
    <span class="date">{{ post.date }}</span>
  </p>
  <div class="content">
    {{ post.content }}
  </div>
{% endfor %}

<!-- Pagination links -->
<div class="pagination">
  {% if paginator.previous_page %}
    <a href="/page{{ paginator.previous_page }}" class="previous">Previous</a>
  {% else %}
    <span class="previous">Previous</span>
  {% endif %}
  <span class="page_number ">Page: {{ paginator.page }} of {{ paginator.total_pages     }}</span>
  {% if paginator.next_page %}
    <a href="/page{{ paginator.next_page }}" class="next">Next</a>
  {% else %}
    <span class="next ">Next</span>
  {% endif %}
</div>

_layout/index.html

{% if paginator.page != 1 %}
{% include custom/pagination %}
{% else %}
The original content of index
{% endif %}
+2

Source: https://habr.com/ru/post/1548206/


All Articles