如何在 Jekyll 中添加 RESTful 类型路由

发布于 2024-11-29 12:04:04 字数 395 浏览 4 评论 0原文

网站的根目录 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不必在意 2024-12-06 12:04:04

这个功能实际上在 Jekyll 中就可用。只需将以下行添加到您的 _config.yml 中:

permalink: pretty

这将启用不带 .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:

permalink: pretty

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 of YYYY-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

自此以后,行同陌路 2024-12-06 12:04:04

实际上是服务器需要调整,而不是jekyll。默认情况下,jekyll 将生成扩展名为 .html 的文件。可能有一种解决方法,但您不太可能真的想走那条路。相反,您需要让 Web 服务器知道您希望在使用文件的基本名称(无扩展名)调用 URL 时提供这些文件。

如果您的站点通过 Apache Web 服务器提供服务,您可以启用“MultiViews”选项。在大多数情况下,您可以通过在站点根目录中使用以下行创建 .htaccess 文件来做到这一点:

Options +MultiViews

启用此选项后,当 Apache 收到以下请求时:

http://example.com/foo

它将提供该文件:

/foo.html

请注意,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:

Options +MultiViews

With this option enabled, when Apache receives a request for:

http://example.com/foo

It will serve the file:

/foo.html

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文