【问题标题】:jekyll pretty permalinks give me WEBrick errorjekyll 漂亮的永久链接给了我 WEBrick 错误
【发布时间】:2015-08-04 23:43:43
【问题描述】:

我正在使用 Jekyll(3.0.0 测试版)开发我的博客,目前在本地主机上,

当我尝试实现漂亮的永久链接并尝试访问帖子时,它显示 WEBrick 错误。

如果我应用 /:year/:month/:day/:title.html 它工作正常你知道为什么它不能与漂亮的永久链接一起工作吗?

这是我得到的错误:

/2015/08/03/are-permas-working.html' not found. WEBrick/1.3.1 (Ruby/2.1.6/2015-04-13) at localhost:4000

【问题讨论】:

  • 请提供更多信息,当您在_config.yml 中执行permalinks: pretty 时,确切的错误是什么?更改_config.yml中的值时不需要重新启动服务器
  • @matrixanomaly 这是我得到的错误。未找到 `/2015/08/03/are-permas-working.html' 未找到。 WEBrick/1.3.1 (Ruby/2.1.6/2015-04-13) 在 localhost:4000

标签: jekyll permalinks


【解决方案1】:

一旦你在_config.yml 中将 Jekyll 永久链接设置为 pretty,如下所示:

permalink : pretty

... 并重新启动您的 WEBrick 服务器(使用 jekyll servebundle exec jekyll serve [如果关注 GitHub] 重新启动服务器实例需要新值生效,您的永久链接将不再采用YYYY/MM/DD/title-slug.html 的格式,因为它们现在是“漂亮的”。您的链接的新格式将是/:categories/:year/:month/:day/:title/。这与定义的漂亮变量here in the documentation 确定的格式一致。

这对您意味着什么是您的“永久有效”帖子的原始链接不再位于 localhost:4000/2015/08/03/are-permas-working.html,而是现在位于 localhost:4000/2015/08/03/are-permas-working/,因为您没有category 已定义。

您遇到此错误,因为在您进行更改并重新启动服务器后,您很可能没有从您的主页导航到帖子(这将拥有指向帖子的新链接),而不是您只是刷新浏览器上的页面,这将引发404,因为该页面不再存在。

奖励,Jekyll 通过创建文件夹 2015 -> 08 -> 03,然后为该特定帖子创建一个文件夹,其中包含 index.html,从而使帖子变得漂亮。

另外,如果您想要没有日期的“漂亮”链接,您需要手动指定:

permalink: "/:categories/:title"

此确保将隐藏 .html 扩展名并删除日期值。

编辑:在 cmets 中,我表示使用 /:title 进行永久链接可能不起作用,因为与非帖子页面存在冲突,我已得到纠正。如果你想要像user.github.io/title-of-blog-post/ 这样的短永久链接,你只需要设置permalink : /:title 就可以了。 但是,如果您有非帖子页面,例如 about 页面、credits 页面,您应该明确将这些页面上的永久链接设置为 /about/credits 在 YAML frontmatter 上,以避免出现标题为 about 的博客帖子并意外覆盖非帖子页面的极端情况。

【讨论】:

  • 好的,如你所说。我添加了一个类别:在每个帖子和永久链接的前面发帖:/:categories/:title 现在我的网址看起来像这样 localhost:4000/post/are-my-permas-working/ 如果不想要怎么办/post 在那里,我希望我的 url 看起来像 localhost:4000/are-my-permas-working/ 我试图在 _config.yml 中添加 permalinks: /:title 但它不起作用。对不起,我是 Stack Overflow 的新手。
  • @ThanosBousis 没关系,无需抱歉。欢迎来到 SO! :) 你可以试试permalink : /:title(不是你提到的permalinkS),但我查了谷歌,它似乎不起作用。您最好的选择是删除类别的使用,或者在每个帖子中手动设置永久链接。 (只是为了每篇博文,在短划线之间的顶部添加permalink: are-my-permas-working,但这可能很烦人,因为您必须为每篇博文都这样做
  • @ThanosBousis 对错误信息感到抱歉,结果permalink: /:title 工作得很好。我只是有机会测试一下。但是,当我尝试它时,它并没有回来。更新了我的答案。
  • 是的,它现在是我的网站 [link](bousis.github.io/myblog) 我在 'gh-pages' 分支中有这个,但我不知道把它移到 master 所以我可以默认获得“bousis.github.io”。有什么想法吗?
  • @ThanosBousis 当然,将你的 repo 从 'myblog' 重命名为 bousis.github.io,然后你需要(在拉下新重命名的 repo 后),使用 git branch -m gh-pages master,然后是 git push -m origin master。参考:stackoverflow.com/questions/2862590/…
猜你喜欢
  • 1970-01-01
  • 2013-03-26
  • 1970-01-01
  • 1970-01-01
  • 2011-03-12
  • 2011-03-22
  • 2015-01-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多