Jekyll在非index.html页面发表博文 [英] Jekyll blog posts on non index.html pages
问题描述
我使用了Jekyll网站下面的代码片段来对我的index.html页面上的Jekyll plog帖子进行分页:
< div class =container>
< ul class =post-list>
<! - 这个循环遍历分页文章 - >
{%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:'//','/'}}>& amp ; LAQUO;上一页< / A>
{%else%}
< span>& laquo;上一页< /跨度>
{%endif%}
{%(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:'//','/'}}>下一页& raquo;< / a>
{%else%}
< span>下一页& raquo;< / span>
{%endif%}
< / div>
{%endif%}
< / ul>
< / div>
但是,当我尝试将其添加到/pages/Blog.html页面时,它不起作用。它不显示我的_posts目录中的任何帖子,而是生成并清空容器。我认为这是一个路径问题。
我已经根据需要将YAML标题添加到了Blog.html文件中。如果你想要一个看起来像 / pages / Blog /
为您的帖子列表:
-
通过设置<$ c $激活分页c> paginate:5 in
_config.yml
-
set
paginate_path:pages / Blog / page:num
in_config.yml
li>
将/pages/Blog.html重命名为 pages / Blog / index.html
I have used the below code snippet from the Jekyll website to paginate Jekyll plog posts on my index.html page:
<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: '//', '/' }}">« Prev</a>
{% else %}
<span>« 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 »</a>
{% else %}
<span>Next »</span>
{% endif %}
</div>
{% endif %}
</ul>
</div>
However when I try to add this to a /pages/Blog.html page it does not work. It does not show any of the posts in my _posts directory and instead produces and empty container. I am assuming it is a path issue.
I have added the YAML header to the Blog.html file as required. When page is rendered it produces an empty container.
If you want an url that looks like /pages/Blog/
for your posts listings :
activate pagination by setting a
paginate: 5
in_config.yml
set
paginate_path: pages/Blog/page:num
in_config.yml
rename /pages/Blog.html to
pages/Blog/index.html
这篇关于Jekyll在非index.html页面发表博文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!