jekyll漂亮的固定链接给我WEBrick错误 [英] jekyll pretty permalinks give me WEBrick error
问题描述
我正在使用目前在localhost上的Jekyll(3.0.0 beta)开发博客.
I am developing my blog in Jekyll (3.0.0 beta), currently on localhost,
当我尝试实现漂亮的永久链接并且尝试访问帖子时,它显示WEBrick错误.
When i am trying to implement the pretty permalink and i try to visit a post it shows a WEBrick error.
如果我应用/:year/:month/:day/:title.html效果很好,您是否知道为什么它不能与漂亮的永久链接一起使用?
If i apply the /:year/:month/:day/:title.html it works fine do you have a clue why isn't it working with pretty permalinks?
这是我得到的错误:
/2015/08/03/are-permas-working.html' not found. WEBrick/1.3.1 (Ruby/2.1.6/2015-04-13) at localhost:4000
推荐答案
一旦您将Jekyll永久链接设置为_config.yml
中的pretty
,就像这样:
Once you set Jekyll permalinks to pretty
in _config.yml
like so:
permalink : pretty
... 并重新启动WEBrick服务器(为了使新值生效,需要使用jekyll serve
或bundle exec jekyll serve
[如果遵循GitHub,请重新启动服务器实例,以使新值生效),不再是YYYY/MM/DD/title-slug.html
的格式,因为它们现在是"pretty".您的链接的新格式将是/:categories/:year/:month/:day/:title/
.这符合由此处为文档.
... and restart your WEBrick server (a restart of the server instance using jekyll serve
or bundle exec jekyll serve
[if following GitHub] is needed for the new values to take effect, your permalinks will no longer be in the format of YYYY/MM/DD/title-slug.html
since they are now "pretty". The new format for your links will be /:categories/:year/:month/:day/:title/
. This is in accordance to the format determined by the pretty variable as defined here in the documentation.
这对您意味着,因为您原来的"Aper permas working"帖子的原始链接不再位于localhost:4000/2015/08/03/are-permas-working.html
,而是现在位于localhost:4000/2015/08/03/are-permas-working/
,因为您没有定义为category
.
What this means for you is that your original link for the 'Are permas working' post is no longer at localhost:4000/2015/08/03/are-permas-working.html
, rather they are now at localhost:4000/2015/08/03/are-permas-working/
since you don't have a category
defined.
您遇到此错误,因为在进行更改并重新启动服务器后,您很可能没有从您的主页导航至该帖子(有指向该帖子的新链接),而是您只是在浏览器上刷新了页面,这将抛出404
,因为该页面不再存在.
You're experiencing this error because after you've made the change and restarted your server you most likely did not navigate to the post from your homepage (which will have that new link to point to the post), rather you just refreshed the page on your browser, which will throw a 404
since the page is no longer there.
奖金,Jekyll通过创建文件夹2015-> 08-> 03,然后是该特定帖子的文件夹,并在其中放置index.html
,使帖子变得漂亮.
Bonus, Jekyll makes posts pretty by creating folders 2015 -> 08 -> 03, and then a folder for that specific post, with an index.html
inside it.
此外,如果您想在其中没有日期的精美"链接,则需要使用以下方法手动指定:
Also, if you wanted "pretty-fied" links that don't have the dates there, you'll need to manually specify that using this:
permalink: "/:categories/:title"
这样可以确保隐藏.html
扩展名,并删除日期值.
This ensure will hide the .html
extension and also get rid of date values.
编辑:根据我的评论,我说使用/:title
进行永久链接可能不起作用,因为与非帖子页面存在冲突,我已予以纠正.如果您想使用user.github.io/title-of-blog-post/
之类的简短永久链接,只需设置permalink : /:title
即可. 但是,如果您有诸如about
页面,credits
页面之类的非帖子页面,则应明确地将这些页面上的永久链接设置为/about
和/credits
放在YAML的最前面,以避免出现这样的情况:也有标题为about
的博客帖子,并意外覆盖了非帖子页面.
EDIT: From the comments I stated that using /:title
for permalinks might not work since there are conflicts with non-post pages, I stand corrected. If you wanted short permalinks like user.github.io/title-of-blog-post/
you would just need to set permalink : /:title
and you're good to go. However, if you have non-post pages such as an about
page, a credits
page, you should explicitly set permalinks on those pages to be /about
and /credits
on the YAML frontmatter to avoid the edge case of also having a blog post with the title about
and accidentally overwriting the non-post page.
这篇关于jekyll漂亮的固定链接给我WEBrick错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!