【问题标题】:Can Jekyll omit index.html from folder URLs?Jekyll 可以从文件夹 URL 中省略 index.html 吗?
【发布时间】:2016-01-18 20:44:43
【问题描述】:

Jekyll docs on creating pages 包括这个包含 index.html 文件的文件夹示例:

要使用 Jekyll 为页面实现干净的 URL,您只需为所需的每个顶级页面创建一个文件夹,然后在每个页面的文件夹中放置一个 index.html 文件。这样,页面 URL 最终成为文件夹名称,Web 服务器将提供相应的 index.html 文件。以下是此结构的示例:

.
├── _config.yml
├── _includes/
├── _layouts/
├── _posts/
├── _site/
├── about/
|   └── index.html  # => http://example.com/about/
├── contact/
|   └── index.html  # => http://example.com/contact/
|── other/
|   └── index.md    # => http://example.com/other/
└── index.html      # => http://example.com/

请注意,示例中的 URL 只是文件夹名称——不是 index.html

不过,当我在自己的 Jekyll 网站中使用这种结构时,会出现这样的模板:

{% for page in site.pages %}{% if page.title %}
    <a href="{{ page.url }}">{{ page.title }}</a>
{% endif %}{% endfor %}

...像这样输出 HTML:

<a href="/projects/index.html">Projects</a>
<a href="/blog/index.html">Blog</a>

有人建议使用这样的前端来修复 URL:

---
permalink: projects/
---

这为我提供了我想要的 URL,但要求我为每个页面添加它。有没有办法让 Jekyll 自动从 URL 中省略 index.html

【问题讨论】:

    标签: jekyll


    【解决方案1】:

    这似乎是 GitHub Pages 使用的 Jekyll 2.4.0 的问题,但在 Jekyll 3 中已修复。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-19
      • 2015-07-30
      • 1970-01-01
      • 2013-08-21
      • 1970-01-01
      • 1970-01-01
      • 2020-01-11
      • 1970-01-01
      相关资源
      最近更新 更多