Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ruby

jekyll

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.

like image 306
add-semi-colons Avatar asked Jan 13 '14 18:01

add-semi-colons


4 Answers

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.

like image 81
Teedub Avatar answered Sep 20 '22 07:09

Teedub


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.

like image 40
nibra Avatar answered Sep 21 '22 07:09

nibra


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")
like image 26
Hossain Mohd Faysal Avatar answered Sep 20 '22 07:09

Hossain Mohd Faysal


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.

like image 31
Eric Cloninger Avatar answered Sep 17 '22 07:09

Eric Cloninger