使用Jekyll创建一个网站,该网站的子目录具有分页内容 [英] Creating a website with Jekyll that has a subdirectory for the blog with paginated content
问题描述
我正在用Jekyll创建一个网站,其主页(jekyllsiteblogpaginated.com/index.html)上没有显示博客内容.另外,我想为博客创建一个子目录,其中主页jekyllsiteblogpaginated.com/blog/index.html以分页方式显示帖子.
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.
我已经在这里推了我的榜样 http://bpatra.github.io/jekyllsiteblogpaginated . 可以在此处
I have pushed my example here http://bpatra.github.io/jekyllsiteblogpaginated. The github repository can be found here
您可能会在存储库分支中看到我已经测试了多个组织:使用index.html文件创建子目录Blog或直接在根级别添加blog.html文件.我还尝试利用了 paginate_path 选项,但是也没有成功,分页器始终为空.
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.
这个问题类似于一个,用户在评论中说他终于使用了插件.我想避免使用插件,因为我的网站将托管在github页面上.
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-添加config.yml
1 - Add in config.yml
paginate_path: "/blog/page:num"
2-在您的代码中:
{% for post in paginator.posts %}
不是
{% for post in paginated.posts %}
3-最后一个微妙的地方.如 Jekyll变量文档
3 - A last subtle point. As seen at the bottom of the Jekyll variables doc
分页器变量的可用性
这些仅在索引文件中可用,但是可以找到它们 在一个子目录中,例如/blog/index.html.
These are only available in index files, however they can be located in a subdirectory, such as /blog/index.html.
因此,通过将 blog.html 重命名为 blog/index.html ,您终于可以对博客进行有效的分页了.
So by renaming blog.html to blog/index.html, you finally get a working pagination for your blog.
等等!
这篇关于使用Jekyll创建一个网站,该网站的子目录具有分页内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!