[英]How do I remove file extensions from a URLs of a GitHub Pages site (Jekyll) while keeping my HTML files in one folder?
Is there a way to configure my files such that I can have the following folder structure map to the following URL structure? 有没有办法配置我的文件,以便我可以将以下文件夹结构映射到以下URL结构?
/
index.html -> www.site.com
about.html -> www.site.com/about
contact.html -> www.site.com/contact
This is a very simple site with just a few pages so it'd be a nice way for me to keep the folder structure very clean and simple. 这是一个非常简单的网站,只有几页,所以这对我来说是一个很好的方式来保持文件夹结构非常简洁。
Add the following to your _config.yml
file: 将以下内容添加到_config.yml
文件中:
permalink: /:title/
This will allow you to add a title to the frontmatter of posts/pages. 这将允许您向帖子/页面的前端添加标题。 The fallback for this is the filename, sans file extension. 对此的回退是文件名,sans文件扩展名。
For more: 更多:
https://jekyllrb.com/docs/permalinks/ https://jekyllrb.com/docs/permalinks/
http://jekyll.tips/jekyll-casts/permalinks/ http://jekyll.tips/jekyll-casts/permalinks/
In about.html
use the following permalink 在about.html
使用以下永久链接
---
title: My about title
permalink: /about/
---
And in contact.html
: 在contact.html
:
---
title: My contact title
permalink: /contact/
---
To remove trailing slashes you need to configure the web server 要删除尾部斜杠,您需要配置Web服务器
Then you can create links hardcoding the URL or using the link
tag: 然后,您可以创建硬编码URL或使用link
标记的link
:
[Link to a page]({{ site.baseurl }}{% link about.html %})
#Or
<a href="/about/">About</a>
Another way is to create the following file structure: 另一种方法是创建以下文件结构:
├── index.html
├── about
│ └── index.html
└── contact
└── index.html
Then be sure your permalinks do not include the .html extension in _configu.yml and it will automatically generate the URLs. 然后确保您的固定链接不包含_configu.yml中的.html扩展名,它将自动生成URL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.