首页 文章

Jekyll不会在子文件夹中生成页面

提问于
浏览
12

我使用GitHub页面并在子文件夹中创建了一些页面 . 它似乎没有生成我在子文件夹中创建的页面 . 所有其他页面工作正常 . 目录结构如下:

/
/index.html
/_config.yaml
/_includes
/_layouts
/_posts
/tag
/tag/personal.html
/tag/videos.html

/tag 目录中的页面不是由Jekyll生成的 . 此外,如果Jekyll构建失败,通常GitHub会发送一封电子邮件,但在这种情况下则不会 . 此外,如果我做任何其他更改它的工作原理,所以构建显然没有失败 .

/tag/personal.html 在这里:

---
layout: default
title: Tag-personal
permalink: /tag/personal/index.html
tagspec: personal
---
<div id="tagpage">
  <h1>Posts tagged personal</h1>
{% include tags.html %}
</div>

/_includes/tags.html 在这里:

{% for tag in post.tags %}
  {% if tag == page.tagspec %}
    {% assign ispostviable = true %}
  {% endif %}
{% endfor %}

  <ul class="posts">
{% for post in site.posts %}
  {% if ispostviable == true %}
    <li><a href="{{ post.url }}"></li>
  {% endif %}
{% endfor %}
  </ul>

PS:我使用GitHub页面并且无法在我的开发机器(Windows)上访问Jekyll实例 .

2 回答

  • 12

    我找到了罪魁祸首 . 就是在Jekyll v1.0中,引入了子目录中页面的绝对永久链接 . 在v1.1之前,它是选择加入 . 然而,从v1.1开始,绝对永久链接变为选择退出,这意味着Jekyll默认使用绝对永久链接而不是相对永久链接 .

    这些页面是在 /tag/tag/personal.html 生成的,依此类推 .

    有两种解决方案:

    • _config.yaml 中指定 relative_permalinks: false

    • 相对于子目录创建永久链接 .

    我选择了第一个选项 .

  • 8

    Joshua Powell在回复Github上的类似问题时提供了step-by-step directions .

    • 编辑 _config.yml 添加以下行(或展开数组,如果存在)

    include: ['_pages']

    其中 _pages 是您希望保留文件的文件夹的名称 . (如果您明确添加它们,这也适用于嵌套文件夹,例如 ['_pages', '_pages/foo'] . )

    • 将您的页面移动到该文件夹中 . (这些页面可能是HTML,Markdown,或Jekyll放置在根文件夹中时呈现的任何其他内容 . )

    • 给他们带来适当的永久链接,包括一个尾部斜杠,例如 permalink: "/about/" .

相关问题