jekyll: Invalid Date: '' is not a valid datetime

jekyll, ruby

Solution

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.

Problem

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.

Original source