如何从 GitHub 页面站点 (Jekyll) 的 URL 中删除文件扩展名,同时将我的 HTML 文件保存在一个文件夹中?

How do I remove file extensions from a URLs of a GitHub Pages site (Jekyll) while keeping my HTML files in one folder?

有没有办法配置我的文件,使我可以将以下文件夹结构映射到以下 URL 结构?

/
    index.html    -> www.site.com
    about.html    -> www.site.com/about
    contact.html  -> www.site.com/contact

这是一个非常简单的网站,只有几页,所以它是我保持文件夹结构非常干净和简单的好方法。

将以下内容添加到您的 _config.yml 文件中:

permalink: /:title/

这将允许您在 posts/pages 的前言中添加标题。后备是文件名,没有文件扩展名。

更多:

https://jekyllrb.com/docs/permalinks/

http://jekyll.tips/jekyll-casts/permalinks/

about.html 中使用以下永久链接

---
title: My about title
permalink: /about/
---

contact.html中:

---
title: My contact title
permalink: /contact/
---

要删除结尾的斜杠,您需要 configure the web server

然后您可以创建硬编码 URL 或使用 link 标签的链接:

[Link to a page]({{ site.baseurl }}{% link about.html %})
#Or
<a href="/about/">About</a>

另一种方法是创建以下文件结构:

├── index.html
├── about
│   └── index.html
└── contact
      └── index.html

然后确保您的永久链接不包含 _configu.yml 中的 .html 扩展名,它会自动生成 URLs.