【发布时间】: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