Jekyll分页博客作为子目录

时间:2013-03-15 02:22:24

标签: pagination blogs jekyll subdirectory

我正在使用Jekyll作为静态网站,我正在尝试将博客生成为子目录/子文件夹:

http://example.com/blog

在运行jekyll之前的目录结构中,这是blog / index.html。

我尝试通过在_config.yml中添加“paginate:5”来添加分页,但生成的url的格式如下:

http://example.com/page2/

即。没有“/博客”。这可以通过以下方式解决:

paginate_path:/ blog / page /:num

_config.yml中的

但生成的页面位于:

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

不要使用blog / index.html作为其布局。他们使用root index.html。那么即使拥有paginate_path选项有什么意义呢?

如何使用Jekyll以分页形式在example.com/blog上获取我的博客?

2 个答案:

答案 0 :(得分:5)

使用_config.yml文件中的destination键设置要将输出发布到的基本路径。例如,

paginate: 5
destination: _site/blog

请注意,假设您的网站设置为服务器,其根目录(例如“http://example.com/”)来自“_site”jekyll将不会在该位置生成“index.html”页面。 jekyll构建的所有内容都将位于“博客”目录下,但这听起来就像您所追求的那样。

答案 1 :(得分:2)

我通过这个page找到了一个修复程序。基本上它涉及一些黑客,以确定你是否在博客的第n页,然后包含一个文件,拉入你的博客部分。

在名为_includes/custom/的{​​{1}}中创建一个文件。有你的分页代码

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