杰奇分页博客作为子目录(Jekyll paginate blog as subdirectory)

2019-07-21 16:33发布

我使用杰基尔一个静态的网站,我试图生成博客作为一个子目录/子文件夹:

http://example.com/blog

在运行之前杰基尔的目录结构,这是博客/ index.html的。

我试图通过添加“分页:5”添加分页到_config.yml,但生成的URL的是下面的形式:

http://example.com/page2/

即没有“/博客”。 这是由固定的:

paginate_path:/博客/页/:NUM

在_config.yml。

但由此产生的页面在:

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

不要使用博客/ index.html作为它们的布局。 他们利用根的index.html。 是什么在即使具有paginate_path选项,然后点?

如何让我的在example.com/blog博客,分页功能,采用化身?

Answer 1:

使用destination在_config.yml文件密钥设置您所要的输出发布到基本路径。 例如,

paginate: 5
destination: _site/blog

请注意,假设您的网站是设置到服务器根(如“ http://example.com/从‘_site’杰奇不会产生与‘index.html的’页”),在该位置。 该杰基尔构建一切都将是“博客”目录下,但听起来像你所追求的。



Answer 2:

我发现通过这个修复页面基本上它涉及到一个黑客位弄清楚,如果你是博客的第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 %}


文章来源: Jekyll paginate blog as subdirectory