Jekyll blog posts on pages without index.html

I used the code snippet below from the Jekyll website to break up Jekyll plog messages on index.html:

<div class="container"> <ul class="post-list"> <!-- 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 %} {% if paginator.total_pages > 1 %} <div class="pagination"> {% if paginator.previous_page %} <a href="{{ paginator.previous_page_path | prepend: site.baseurl | replace: '//', '/' }}">&laquo; Prev</a> {% else %} <span>&laquo; Prev</span> {% endif %} {% for page in (1..paginator.total_pages) %} {% if page == paginator.page %} <em>{{ page }}</em> {% elsif page == 1 %} <a href="{{ '/index.html' | prepend: site.baseurl | replace: '//', '/' }}">{{ page }}</a> {% else %} <a href="{{ site.paginate_path | prepend: site.baseurl | replace: '//', '/' | replace: ':num', page }}">{{ page }}</a> {% endif %} {% endfor %} {% if paginator.next_page %} <a href="{{ paginator.next_page_path | prepend: site.baseurl | replace: '//', '/' }}">Next &raquo;</a> {% else %} <span>Next &raquo;</span> {% endif %} </div> {% endif %} </ul> </div> 

However, when I try to add this to the /pages/Blog.html page, this will not work. It does not show any messages in my _posts directory and instead creates and empties a container. I guess this is the way to go.

I added the YAML header to the Blog.html file as needed. When the page is displayed, an empty container is created.

+6
source share
1 answer

If you need a URL that looks like /pages/Blog/ for your posts:

  • activate pagination by setting paginate: 5 in _config.yml

  • set paginate_path: pages/Blog/page:num in _config.yml

  • rename / pages / Blog.html to pages/Blog/index.html

+13
source

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


All Articles