如何在 Jekyll 中添加 RESTful 类型路由
网站的根目录 http://example.com 正确识别 index.html 并呈现它。以类似的方式,我想要,http://example.com/foo 获取目录根目录中的foo.html。使用此功能的网站是 www.zachholman.com。我在Github上看过他的代码。但我仍然无法找到它是如何完成的。请帮忙。
The root of the site http://example.com correctly identifies index.html and renders it. In a similar manner, I want, http://example.com/foo to fetch foo.html present in the root of the directory. The site that uses this functionality is www.zachholman.com. I've seen his code in Github. But still I'm not able to find how it is done. Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个功能实际上在 Jekyll 中就可用。只需将以下行添加到您的 _config.yml 中:
这将启用不带 .html 扩展名的帖子和页面的链接,例如
/about/
而不是/about.html
/YYYY/MM/DD/my-first-post/
而不是YYYY-MM-DD-my-first-post.html
但是,您将失去自定义永久链接的能力。 ..结尾的斜线很漂亮 丑陋的。
编辑:尾部斜杠似乎是由 设计
This feature is actually available in Jekyll. Just add the following line to your _config.yml:
This will enable links to posts and pages without .html extension, e.g.
/about/
instead of/about.html
/YYYY/MM/DD/my-first-post/
instead ofYYYY-MM-DD-my-first-post.html
However, you lose the ability to customize permalinks... and the trailing slash is pretty ugly.
Edit: The trailing slash seems to be there by design
实际上是服务器需要调整,而不是jekyll。默认情况下,jekyll 将生成扩展名为 .html 的文件。可能有一种解决方法,但您不太可能真的想走那条路。相反,您需要让 Web 服务器知道您希望在使用文件的基本名称(无扩展名)调用 URL 时提供这些文件。
如果您的站点通过 Apache Web 服务器提供服务,您可以启用“MultiViews”选项。在大多数情况下,您可以通过在站点根目录中使用以下行创建 .htaccess 文件来做到这一点:
启用此选项后,当 Apache 收到以下请求时:
它将提供该文件:
请注意,Apache 服务器必须进行设置以允许在 htaccess 文件中设置该选项。如果没有,您需要在 Apache 配置文件本身中执行此操作。如果您的网站托管在其他网络服务器上,您需要寻找等效的设置。
It's actually the server that needs adjusting, not jekyll. Be default, jekyll is going to produces files with .html extensions. There may be a way around that, but it's unlikely that you really want to do go that route. Instead, you need to let your web server know that you want those files served when a URL is called with the file's basename (and no extension).
If your site is served via an Apache web server you can enable the "MultiViews" option. In most cases, you can do that be creating an .htaccess file at your site root with the following line:
With this option enabled, when Apache receives a request for:
It will serve the file:
Note that the Apache server must be setup to allow the option to be set in the htaccess file. If not, you would need to do it in the Apache config file itself. If your site is hosted on another web server, you'll need to look for an equivalent setting.