2

我正在使用这个主题制作一个网站:Github repo主题演示

主题是使用主页上的博客提要 ( index.html) 构建的。我想做的是:

  1. 制作一个静态主页(即主页上没有博客提要),以及
  2. 将博客提要放在名为“Blog”的单独页面上,并带有链接“/blog”或“/blog.html”。

博客提要的代码位于_includes/blog.html并包含在home布局中,使用{% include blog.html %}.

我试过的

  • 将布局更改index.html为静态布局page,并在根目录中创建了一个名为blog.html该布局的新页面home- 这成功创建了一个静态主页,但博客页面产生了一个类似主页的标题但没有博客提要(本质上是一个带有无内容)。
  • blog.html在名为layout的根目录中创建了一个新页面,default并将主布局的内容(包括{% include blog.html %})粘贴到该页面中 - 这产生了与上述相同的结果。
  • 创建了一个名为 的新布局blog,它是当前home布局的副本。{% include blog.html %}我从home布局中删除了该行。然后我给出index.htmlhome布局并在根目录中创建了一个名为blog.htmllayout的新页面blog。这产生了与上述相同的结果。

简而言之,似乎博客提要无法在除 之外的任何文件中生成index.html,我也无法弄清楚原因。这是我在主题配置中缺少的东西吗?如果这是一个愚蠢的问题,我深表歉意——我对此很陌生。谢谢你能给我的任何帮助!

编辑:原来这是分页器的问题,默认情况下从家里分页。

4

1 回答 1

1

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 %}
...

要解决您的问题,您需要将自己的主页定义为这样的包含:

  1. 使用您选择的 html创建your-custom-homepage.html
  2. 将其包含在home.htmlas{% include your-custom-homepage.html %}而不是{% include blog.html %}. 只需替换_layouts/home.html.

然后它将包含标题和您的内容。

Jekyll 文档,例如https://jekyllrb.com/docs/step-by-step/04-layouts/https://jekyllrb.com/docs/includes/有望解释细节。

于 2020-05-18T22:43:53.667 回答