Can Jekyll omit index.html from folder URLs?

百般思念 提交于 2019-12-23 03:23:19

问题


The Jekyll docs on creating pages include this example of folders containing index.html files:

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/

Note that the URLs in the example are just the folder names — no index.html.

When I use this structure in my own Jekyll site, though, a template like this:

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

…outputs HTML like this:

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

Someone suggested using front matter like this to fix the URLs:

---
permalink: projects/
---

This gives me the URLs I want but requires that I add that for each page. Is there a way to get Jekyll to omit index.html from the URL automatically?


回答1:


This appears to be an issue with Jekyll 2.4.0, which GitHub Pages uses, but is fixed in Jekyll 3.



来源:https://stackoverflow.com/questions/34863745/can-jekyll-omit-index-html-from-folder-urls

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!