Jekyll 可以从文件夹 URL 中省略 index.html 吗?
Can Jekyll omit index.html from folder URLs?
Jekyll docs on creating pages 包含包含 index.html
个文件的文件夹示例:
To achieve clean URLs for pages using Jekyll, you simply need to create a folder for each top-level page you want, and then place an index.html
file in each page’s folder. This way the page URL ends up being the folder name, and the web server will serve up the respective index.html
file. Here’s an example of what this structure might look like:
.
├── _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>
有人建议使用这样的 front matter 来修复 URLs:
---
permalink: projects/
---
这为我提供了我想要的 URL,但要求我为每个页面添加它。有没有办法让 Jekyll 自动从 URL 中省略 index.html
?
这似乎是 GitHub Pages 使用的 Jekyll 2.4.0 的问题,但已在 Jekyll 3 中修复。
Jekyll docs on creating pages 包含包含 index.html
个文件的文件夹示例:
To achieve clean URLs for pages using Jekyll, you simply need to create a folder for each top-level page you want, and then place an
index.html
file in each page’s folder. This way the page URL ends up being the folder name, and the web server will serve up the respectiveindex.html
file. Here’s an example of what this structure might look like:. ├── _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>
有人建议使用这样的 front matter 来修复 URLs:
---
permalink: projects/
---
这为我提供了我想要的 URL,但要求我为每个页面添加它。有没有办法让 Jekyll 自动从 URL 中省略 index.html
?
这似乎是 GitHub Pages 使用的 Jekyll 2.4.0 的问题,但已在 Jekyll 3 中修复。