问题
I am creating a website with Jekyll where the main page (jekyllsiteblogpaginated.com/index.html) displays no blog content. In addition, I would like to create a subdirectory for the blog where the main page, jekyllsiteblogpaginated.com/blog/index.html, displays the post in a paginated manner.
I have pushed my example here http://bpatra.github.io/jekyllsiteblogpaginated. The github repository can be found here
You may see in the repository branches that I have tested several organisation: creating a subdirectory blog with an index.html file or to add directly the blog.html file at root level. I also tried to take benefit of the paginate_path option but also without success, the paginator is always empty.
This question is similar to this one, the user says in comment that he finally used a plugin. I would like to avoid plugin because my site will be hosted on github pages.
回答1:
I succeeded !
1 - Add in config.yml
paginate_path: "/blog/page:num"
2 - In you code :
{% for post in paginator.posts %}
and not
{% for post in paginated.posts %}
3 - A last subtle point. As seen at the bottom of the Jekyll variables doc
Paginator variable availability
These are only available in index files, however they can be located in a subdirectory, such as /blog/index.html.
So by renaming blog.html to blog/index.html, you finally get a working pagination for your blog.
Et voilà !
来源:https://stackoverflow.com/questions/24717458/creating-a-website-with-jekyll-that-has-a-subdirectory-for-the-blog-with-paginat