Jekyll post_url -- what am I missing?
Asked Answered
L

3

10

I am using Jekyll and Github pages, testing locally using bundle exec jekyll serve. Everything else works fine so far.

My posts are in a /_posts folder off of the root, and are outputted correctly.

I cannot seem to get {% post_url %} working within posts for other internal posts, no matter what I do.

Example / Question

  • In my _posts folder, I have a post with a file name of 2011-04-14-free-million-dollar-idea-package-carriers-b2b-success.markdown
    • This shows up on my site at [root]/2011/04/free-million-dollar-idea-package-carriers-b2b-success/
  • My config specifies permalink: /:year/:month/:title

I have tried the following references within {% post_url %} from another post, to try to link to the post:

  • 2011-04-14-free-million-dollar-idea-package-carriers-b2b-success
    • Based on the file name of the post, which I thought was what I should be referencing
  • /2011/04/free-million-dollar-idea-package-carriers-b2b-success/
    • Based on the URL that the post actually resides on at my web site
  • 2011/04/free-million-dollar-idea-package-carriers-b2b-success/
    • Without the leading slash
  • /2011/04/free-million-dollar-idea-package-carriers-b2b-success
    • Without the trailing slash
  • 2011/04/free-million-dollar-idea-package-carriers-b2b-success
    • Without either slash

Each one yields the error:

Could not parse name of post [reference] in tag 'post_url'

What am I missing?

Leclaire answered 2/11, 2014 at 18:38 Comment(0)
B
24

If your post file name is 2011-04-14-free-million-dollar-idea-package-carriers-b2b-success.md or .markdown the syntax is :

[Link text]({% post_url 2011-04-14-free-million-dollar-idea-package-carriers-b2b-success %})
Bazar answered 2/11, 2014 at 21:45 Comment(1)
You are indeed correct. The issue I was having ended up being something entirely different. Thanks!Leclaire
B
6

Also check that the front-matter date value matches the date in the post's file name.

(Some versions) of jekyll + safe_yaml can't find the post if the date on the file-name doesn't match the date in the front-matter data.

Boisleduc answered 20/6, 2015 at 15:55 Comment(0)
S
1

Was pulling my hair out until I realized that if a post isn't published, it doesn't "exist" to be linked.

Posts must be published, assuming you're only building Jekyll with published posts. I suspect this might also be a problem if you're linking to a future post.

Stebbins answered 17/3 at 16:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.