jekyll - 修改现有的Jekyll主题,使其拥有静态主页。
我正在用这个主题做一个网站。Github repo; 主题演示.
该主题是建立在主页上的博客饲料(index.html
). 我想做的是
- 制作一个静态主页(即主页上没有博客源)。和
- 将博客源码放在一个单独的页面上,名为 "Blog",链接为 "blog "或 "blog.html"。
博客源的代码在 _includes/blog.html
并被列入 home
利用 {% include blog.html %}
.
我试过的
- 改变了
index.html
的静态布局,如page
,并在根目录下创建了一个新页面,名为blog.html
与布局home
- 这成功地创建了一个静态主页,但博客页面产生了一个类似于主页的标题,但没有博客源(基本上是一个没有内容的页面)。 - 在根目录下创建了一个新页面,名为
blog.html
与布局default
,并将首页布局的内容(包括{% include blog.html %}
)到该页中--这产生了与上面相同的结果。 - 创建了一个新的布局,名为
blog
的副本,这是当前home
布局。我删除了这一行{% include blog.html %}
来自home
布局。然后我给index.html
的home
布局,并在根目录下创建了一个新的页面,叫做blog.html
与布局blog
. 这产生了和上面一样的结果。
简而言之,似乎博客饲料不能在任何文件中生成,而不是在 index.html
但我一直想不明白为什么。它是我在主题的配置中缺少的东西吗?如果这是一个愚蠢的问题,道歉 - 我是相当新的。谢谢你的任何帮助,你可以给我!
EDIT:原来是分页器的问题,默认情况下,分页器是从首页开始的。
【回答】:
index.html使用的是首页布局。
---
layout: home
---
这是在 _layouts/home.html
并包含一个头,并包含blog.html。它看起来像这样。
---
layout: default
---
<div class="home">
<div id="main" class="call-out"
style="background-image: url('{{ site.header_feature_image | relative_url }}')">
<h1> {{ site.header_text | default: "Change <code>header_text</code> in <code>_config.yml</code>"}} </h1>
</div>
{% include blog.html %}
</div>
blog.html文件循环播放所有(博客)文章。
<div class="posts">
{% for post in paginator.posts %}
...
为了解决你的问题,你需要定义你自己的主页作为一个include,像这样。
- 创建
your-custom-homepage.html
用你选择的html。 - 包括在
home.html
作为{% include your-custom-homepage.html %}
而不是{% include blog.html %}
. 只需将这一行替换为_layouts/home.html
.
然后它将包含头和你的内容。
Jekyll文档,如 https:/jekyllrb.comdocsstep-by-step04-layouts。 和 https:/jekyllrb.comdocsincludes。 将有望解释细节。