Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a website with Jekyll that has a subdirectory for the blog with paginated content

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.

like image 769
Benoit Patra Avatar asked Dec 01 '22 16:12

Benoit Patra


1 Answers

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à !

like image 82
David Jacquel Avatar answered Dec 09 '22 21:12

David Jacquel