问题
I am developing my blog in Jekyll (3.0.0 beta), currently on localhost,
When i am trying to implement the pretty permalink and i try to visit a post it shows a WEBrick error.
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?
This is the error I get:
/2015/08/03/are-permas-working.html' not found. WEBrick/1.3.1 (Ruby/2.1.6/2015-04-13) at localhost:4000
回答1:
Once you set Jekyll permalinks to pretty
in _config.yml
like so:
permalink : pretty
... 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.
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.
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.
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"
This ensure will hide the .html
extension and also get rid of date values.
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.
来源:https://stackoverflow.com/questions/31791004/jekyll-pretty-permalinks-give-me-webrick-error