Reputation: 18810
I am new to jekyll:
So far I had done what the tutorial has mentioned: This is what I have in _layout: post.html file:
---
layout: default
---
<div class="post">
<h1>{{ page.title }}</h1>
<span class="post-date">{{ page.date | date_to_string }}</span>
{{ content }}
</div>
<div class="related">
<h2>Related Posts</h2>
<ul class="related-posts">
{% for post in site.related_posts limit:3 %}
<li>
<h3>
<a href="{{ post.url }}">
{{ post.title }}
<small>{{ post.date | date_to_string }}</small>
</a>
</h3>
</li>
{% endfor %}
</ul>
</div>
and I use md file with a name 2014-01-01-myNewPost.md
and I get the following error:
Generating... Invalid Date: '' is not a valid datetime.
Liquid Exception: exit in _layouts/post.html
I don't seem to see any issues but unable to really figure it out why its not working.
Upvotes: 9
Views: 3943
Reputation: 382
My problem was that for some reason I kept getting this error in the terminal when I ran "jekyll serve --incremental":
Liquid Exception: Invalid Date: 'nil' is not a valid datetime. in /_layouts/post.html
ERROR: YOUR SITE COULD NOT BE BUILT:
------------------------------------
Invalid Date: 'nil' is not a valid datetime.
and after much digging, it's because jekyll picks up posts of any kind in the root directory, even if they are in a whole different folder. I had my posts in "_posts" and my test posts in "old_posts".
Just having the "old_posts" directory at the root project level made this error occur. Make sure you don't have anything like that.
Upvotes: 3
Reputation: 167
Based on this GitHub issue it looks like Jekyll will complain if you label something as a post and then try to format the date if that thing doesn't have a date in the title or front matter. This doesn't happen if you reference {{ page.date }}
without formatting it, so it must be some kind of nil error in the format function.
I just had this problem and I realized I'd labeled a bunch of static pages with layout: post
in the front matter when the filename was example.md
rather than 2016-01-01-example.md
. I changed those files to layout: page
and that solved the problem.
So at least on my site I have to make sure things without dates are pages and things with dates are posts. (I removed the date from my posts layout when I redesigned the site and just now got around to trying to put it back.)
Upvotes: 0
Reputation: 2260
I had this happen and it turns out I had duplicated a file from my _posts directory by mistake with option-click and it was sitting in the root of my site. Would be nice if the processor would give a detailed description about the cause of the error in addition to the general error message.
Upvotes: 1
Reputation: 4028
Most likely, you have moved the sample posts to another directory, e.g., examples
. Jekyll finds the posts there and tries to process them, which leads to the encountered problem.
Add the examples
folder to the exclude list in _config.yml
, and Jekyll will start as expected.
Upvotes: 2
Reputation: 817
Seems like you've a typo in the date variable in your post YAML matter. Check if your post date complies with this format YYYY-MM-DD HH:MM:SS
I've checked the post layout code posted above, its fine.
If nothing works, uninstall Jekyll and install the last stable release 1.2.1 by running these commands
~ $ gem uninstall jekyll
~ $ gem install jekyll --version(="1.2.1")
Upvotes: 1