Jekyll可以从文件夹URL中省略index.html吗? [英] Can Jekyll omit index.html from folder URLs?

查看:45
本文介绍了Jekyll可以从文件夹URL中省略index.html吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Jekyll 创建页面的文档包括以下包含index.html文件的文件夹示例:

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

要使用Jekyll为页面提供干净的URL,只需为所需的每个顶级页面创建一个文件夹,然后在每个页面的文件夹中放置一个index.html文件.这样,页面URL最终将成为文件夹名称,并且Web服务器将提供相应的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.

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

但是,当我在自己的Jekyll网站中使用此结构时,会得到一个类似这样的模板:

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 %}

…输出这样的HTML:

…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/
---

这为我提供了所需的URL,但要求我为每个页面添加该URL.是否有办法让Jekyll自动从URL中省略index.html?

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?

推荐答案

这似乎是GitHub Pages使用的Jekyll 2.4.0的一个问题,但已在Jekyll 3中解决.

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

这篇关于Jekyll可以从文件夹URL中省略index.html吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆